Browse Source

FEATURE | Get app version rest

pull/2/head
Oksana Stepanenko 1 year ago
parent
commit
6acf119d3a
  1. 2
      .env.example
  2. 2
      .env.save
  3. 11
      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. 12
      src/rest/app/system/app-system.service.ts
  8. 6
      src/rest/app/system/dto/app-version.dto.ts
  9. 1
      src/rest/app/system/dto/index.ts

2
.env.example

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
APP_VERSION=2.1
TEST_ENV=test
AUTO_SEED_ENABLED=true

2
.env.save

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
APP_VERSION=2.1
AUTO_SEED_ENABLED=true
DATABASE_DB=taskme

11
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,14 @@ const getFilesLimitsConfig = () => { @@ -117,6 +117,14 @@ const getFilesLimitsConfig = () => {
return config
}
const getAppVersion = () => {
try {
return getEnv('APP_VERSION')
} catch (e) {
console.log('Error on get env var:', e.message)
}
}
export const $config = {
getDatabaseConfig,
getJwtConfig,
@ -128,4 +136,5 @@ export const $config = { @@ -128,4 +136,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 } from '@nestjs/common'
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'
import { AppSystemService } from './app-system.service'
import { AppVersionDto } 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() {
return this.systemService.getAppVersion()
}
}

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],
}
}
}

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

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

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

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
import { DtoProperty } from 'src/shared'
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