Browse Source

Merge pull request 'app-version' (#2) from app-version into stage

Reviewed-on: #2
pull/3/head
Vitalik Yatsenko 1 year ago
parent
commit
41cd011c19
  1. 3
      .env.example
  2. 3
      .env.save
  3. 13
      src/config/index.ts
  4. 2
      src/rest/app/index.ts
  5. 24
      src/rest/app/system/app-system.controller.ts
  6. 16
      src/rest/app/system/app-system.module.ts
  7. 13
      src/rest/app/system/app-system.service.ts
  8. 12
      src/rest/app/system/dto/app-version.dto.ts
  9. 1
      src/rest/app/system/dto/index.ts

3
.env.example

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
APP_VERSION_IOS=2.2
APP_VERSION_ANDROID=2.2
TEST_ENV=test
AUTO_SEED_ENABLED=true

3
.env.save

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
APP_VERSION_IOS=2.2
APP_VERSION_ANDROID=2.2
AUTO_SEED_ENABLED=true
DATABASE_DB=taskme

13
src/config/index.ts

@ -10,7 +10,7 @@ import { getEnv, stringToBoolean } from 'src/shared' @@ -10,7 +10,7 @@ import { getEnv, stringToBoolean } from 'src/shared'
import { ConnectionOptions } from 'typeorm'
import { ENTITIES } from './entities.config'
const getDatabaseConfig = (): Parameters<typeof DatabaseModule['forRoot']> => {
const getDatabaseConfig = (): Parameters<(typeof DatabaseModule)['forRoot']> => {
return [
{
type: 'postgres',
@ -117,6 +117,16 @@ const getFilesLimitsConfig = () => { @@ -117,6 +117,16 @@ const getFilesLimitsConfig = () => {
return config
}
const getAppVersion = (platform: string) => {
if (!platform) return null
const paramName = `APP_VERSION_${platform.toUpperCase()}`
try {
return getEnv(paramName)
} catch (e) {
console.log('Error on get env var:', e.message)
}
}
export const $config = {
getDatabaseConfig,
getJwtConfig,
@ -128,4 +138,5 @@ export const $config = { @@ -128,4 +138,5 @@ export const $config = {
getOldDatabaseConfig,
getEmail,
getFilesLimitsConfig,
getAppVersion,
}

2
src/rest/app/index.ts

@ -10,6 +10,7 @@ import { AppTaxonomiesModule } from './taxonomies/app-taxonomies.module' @@ -10,6 +10,7 @@ import { AppTaxonomiesModule } from './taxonomies/app-taxonomies.module'
import { AppNotificationsModule } from './notifications/app-notifications.module'
import { AppChatsModule } from './chats/chats.module'
import { AppVersionsModule } from './versions/app-versions.module'
import { AppSystemModule } from './system/app-system.module'
export const getRestAppModules = () => [
AppAuthModule.forRoot(),
@ -24,4 +25,5 @@ export const getRestAppModules = () => [ @@ -24,4 +25,5 @@ export const getRestAppModules = () => [
AppNotificationsModule.forRoot(),
AppChatsModule.forRoot(),
AppVersionsModule.forRoot(),
AppSystemModule.forRoot(),
]

24
src/rest/app/system/app-system.controller.ts

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
import { Controller, Get, Query } from '@nestjs/common'
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'
import { AppSystemService } from './app-system.service'
import { AppVersionDto, GetAppVersionParamsDto } from './dto'
import { AuthGuard } from 'src/domain/sessions/decorators'
@ApiTags('App | System')
@Controller('app/system')
export class AppSystemController {
constructor(private readonly systemService: AppSystemService) {}
@ApiOperation({
summary: 'Отримання актуальної версії мобільного додатку',
})
@ApiOkResponse({
description: 'Повертає актуальну версію мобільного додатку',
type: AppVersionDto,
})
@AuthGuard()
@Get('app-version')
public async getAppVersion(@Query() dto: GetAppVersionParamsDto) {
return this.systemService.getAppVersion(dto)
}
}

16
src/rest/app/system/app-system.module.ts

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
import { DynamicModule, Module } from '@nestjs/common'
import { JwtModule } from 'src/libs'
import { AppSystemService } from './app-system.service'
import { AppSystemController } from './app-system.controller'
@Module({})
export class AppSystemModule {
static forRoot(): DynamicModule {
return {
module: AppSystemModule,
imports: [JwtModule.forFeature()],
providers: [AppSystemService],
controllers: [AppSystemController],
}
}
}

13
src/rest/app/system/app-system.service.ts

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
import { Injectable } from '@nestjs/common'
import { $config } from 'src/config'
import { GetAppVersionParamsDto } from './dto'
@Injectable()
export class AppSystemService {
public getAppVersion(dto: GetAppVersionParamsDto) {
const version = $config.getAppVersion(dto.platform)
if (version) return { version }
return null
}
}

12
src/rest/app/system/dto/app-version.dto.ts

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
import { IsString } from 'class-validator'
import { DtoProperty } from 'src/shared'
export class GetAppVersionParamsDto {
@DtoProperty()
@IsString()
platform: string
}
export class AppVersionDto {
@DtoProperty()
version: string
}

1
src/rest/app/system/dto/index.ts

@ -0,0 +1 @@ @@ -0,0 +1 @@
export * from './app-version.dto'
Loading…
Cancel
Save