-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2129cbc
commit cbcc989
Showing
11 changed files
with
249 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Controller, Get, Logger, Query } from '@nestjs/common'; | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
|
||
import { ClientService } from './client.service'; | ||
import { APIException } from 'src/common/dto/APIException.dto'; | ||
|
||
@ApiTags('Common - Client Information') | ||
@Controller('client') | ||
export class ClientController { | ||
private readonly logger = new Logger(ClientController.name); | ||
|
||
constructor(private readonly clientService: ClientService) {} | ||
|
||
@Get('maintenance') | ||
@ApiOperation({ | ||
summary: '현재 점검여부 확인', | ||
description: '왁타플레이 서비스가 현재 점검 중인지 확인합니다.', | ||
}) | ||
async maintenance() { | ||
return await this.clientService.getMaintenance(); | ||
// return {}; | ||
} | ||
|
||
@Get('update') | ||
@ApiOperation({ | ||
summary: '클라이언트 업데이트 확인', | ||
description: '사용자의 클라이언트에 업데이트가 존재하는지 확인합니다.', | ||
}) | ||
async update(@Query('os') os: string, @Query('version') version: string) { | ||
if (!os || !version) { | ||
throw new APIException(400, "'os'와 'version' 파라미터는 필수입니다."); | ||
} | ||
|
||
if (!['ios', 'android', 'pc'].includes(os)) { | ||
throw new APIException( | ||
400, | ||
"'os' 파라미터는 'ios' 또는 'android', 'pc' 만 허용됩니다.", | ||
); | ||
} | ||
|
||
return await this.clientService.update(os, version); | ||
// return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ClientController } from './client.controller'; | ||
import { ClientService } from './client.service'; | ||
|
||
import { RepositoryModule } from 'src/common/repository/repository.module'; | ||
import { maintenanceProviders } from 'src/common/repository/models/maintenance.providers'; | ||
import { versionProviders } from 'src/common/repository/models/version.providers'; | ||
|
||
@Module({ | ||
imports: [RepositoryModule], | ||
controllers: [ClientController], | ||
providers: [ClientService, ...maintenanceProviders, ...versionProviders], | ||
}) | ||
export class ClientModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Inject, Injectable, Logger } from '@nestjs/common'; | ||
import { Model } from 'mongoose'; | ||
|
||
import { IMaintenance } from 'src/common/repository/schemas/maintenance.schema'; | ||
import { IVersion } from 'src/common/repository/schemas/version.schema'; | ||
|
||
import { UpdateResponseDto } from './dto/updateResponse.dto'; | ||
import { APIException } from 'src/common/dto/APIException.dto'; | ||
|
||
@Injectable() | ||
export class ClientService { | ||
private readonly logger = new Logger(ClientService.name); | ||
|
||
constructor( | ||
@Inject('MAINTENANCE_MODEL') | ||
private readonly maintenanceModel: Model<IMaintenance>, | ||
@Inject('CLIENTVERSION_MODEL') | ||
private readonly clientVersionModel: Model<IVersion>, | ||
) {} | ||
|
||
async getMaintenance(): Promise<IMaintenance> { | ||
const maintenanceData = await this.maintenanceModel | ||
.find() | ||
.select({ _id: 0, __v: 0 }) | ||
.sort({ date: -1 }); | ||
|
||
return ( | ||
maintenanceData.find( | ||
(maintenance) => maintenance.date.end >= new Date(), | ||
) || null | ||
); | ||
} | ||
|
||
async update(os: string, version: string): Promise<UpdateResponseDto> { | ||
const versions = await this.clientVersionModel.find({ os }); | ||
const updateUrl = { | ||
ios: 'https://apps.apple.com/kr/app/id', | ||
android: | ||
'https://play.google.com/store/apps/details?id=com.waktaplay.mobile', | ||
pc: null, | ||
}[os]; | ||
|
||
if (!versions.length) { | ||
throw new APIException(404, '업데이트 정보를 찾을 수 없습니다.'); | ||
} | ||
|
||
const latestVersion = versions.reduce((prev, curr) => | ||
prev.version > curr.version ? prev : curr, | ||
); | ||
|
||
return { | ||
// 업데이트가 필요한지 여부 | ||
// 현재 버전이 최신 버전보다 낮은 경우 true | ||
needUpdate: version < latestVersion.version, | ||
|
||
os: latestVersion.os, | ||
updateUrl, | ||
|
||
version: latestVersion.version, | ||
specialLogo: latestVersion.specialLogo, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export class UpdateResponseDto { | ||
/** | ||
* 업데이트 필요 여부 | ||
* @example true | ||
*/ | ||
needUpdate: boolean; | ||
|
||
/** | ||
* 업데이트 OS 정보 | ||
* @example ios | ||
*/ | ||
os: string; | ||
|
||
/** | ||
* 업데이트 URL | ||
* @example https://play.google.com/store/apps/details?id=com.waktaplay.mobile | ||
*/ | ||
updateUrl?: string; | ||
|
||
/** | ||
* 업데이트 버전 | ||
* @example "1.0.0" | ||
*/ | ||
version: string; | ||
|
||
/** | ||
* 이벤트 특별 로고 URL | ||
* @example https://cdn.waktaplay.com/lottie/2024/christmas.json | ||
*/ | ||
specialLogo?: string; | ||
} | ||
|
||
export default UpdateResponseDto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Connection } from 'mongoose'; | ||
import { MaintenanceSchema } from '../schemas/maintenance.schema'; | ||
|
||
export const maintenanceProviders = [ | ||
{ | ||
provide: 'MAINTENANCE_MODEL', | ||
useFactory: (connection: Connection) => | ||
connection.model('Maintenance', MaintenanceSchema), | ||
inject: ['DATABASE_CONNECTION'], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Connection } from 'mongoose'; | ||
import { VersionSchema } from '../schemas/version.schema'; | ||
|
||
export const versionProviders = [ | ||
{ | ||
provide: 'CLIENTVERSION_MODEL', | ||
useFactory: (connection: Connection) => | ||
connection.model('ClientVersion', VersionSchema), | ||
inject: ['DATABASE_CONNECTION'], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
export interface IMaintenance { | ||
type: 'SCHEDULED' | 'NONSTOP' | 'EMERGENCY' | 'END_OF_LIFE'; | ||
title: string; | ||
description?: string; | ||
date: { | ||
start: Date; | ||
end: Date; | ||
}; | ||
} | ||
|
||
export const MaintenanceSchema = new mongoose.Schema<IMaintenance>({ | ||
type: { | ||
type: String, | ||
required: true, | ||
}, | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
description: String, | ||
date: { | ||
start: { | ||
type: Date, | ||
required: true, | ||
}, | ||
end: { | ||
type: Date, | ||
required: true, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
export interface IVersion { | ||
os: string; | ||
version: string; | ||
specialLogo?: string; | ||
} | ||
|
||
export const VersionSchema = new mongoose.Schema<IVersion>({ | ||
os: { | ||
type: String, | ||
required: true, | ||
}, | ||
version: { | ||
type: String, | ||
required: true, | ||
}, | ||
specialLogo: String, | ||
}); |