Skip to content

Commit

Permalink
add api app endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Jan 9, 2024
1 parent 7218c87 commit f5bcd83
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apps/api/src/endpoints/apps/apps.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiResponse } from '@nestjs/swagger'
import { AppValue } from './entities/app.value'
import { AppService, DelegationService } from '@mvx-monorepo/common'
import { Controller, Get, NotFoundException, Param } from '@nestjs/common'

Expand All @@ -9,6 +10,30 @@ export class AppsController {
private readonly delegationService: DelegationService
) {}

// TODO: @UseGuards(NativeAuthGuard)
@Get('/apps')
@ApiResponse({ status: 200 })
async index() {
const apps = await this.appService.getApps()
const values = apps.map((app) => AppValue.fromAppInfo(app))

return values
}

// TODO: @UseGuards(NativeAuthGuard)
@Get('/apps/:appid')
@ApiResponse({ status: 200 })
@ApiResponse({ status: 404 })
async show(@Param('appid') appId: string) {
const app = await this.appService.getAppById(+appId)

if (!app) {
throw new NotFoundException('App not found')
}

return AppValue.fromAppInfo(app)
}

// TODO: @UseGuards(NativeAuthGuard)
@Get('/apps/sync')
@ApiResponse({ status: 200 })
Expand Down
21 changes: 21 additions & 0 deletions apps/api/src/endpoints/apps/entities/app.value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AppInfo } from '@mvx-monorepo/common'

export class AppValue {
id: number
name: string
manager: string
createdAt: number
dataCollections: string[]

constructor(id: number, name: string, manager: string, createdAt: number, dataCollections: string[]) {
this.id = id
this.name = name
this.manager = manager
this.createdAt = createdAt
this.dataCollections = dataCollections
}

static fromAppInfo(info: AppInfo): AppValue {
return new AppValue(info.id, info.name, info.manager, info.createdAt, info.dataCollections)
}
}

0 comments on commit f5bcd83

Please sign in to comment.