Skip to content

Commit

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

@Controller()
export class AppsController {
constructor(
private readonly appService: AppService,
private readonly delegationService: DelegationService
) {}

// TODO: @UseGuards(NativeAuthGuard)
@Get('/apps/sync')
@ApiResponse({ status: 200 })
async syncAll() {
await this.appService.syncApps()
}

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

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

await this.delegationService.syncDelegations(app)
}
}
3 changes: 2 additions & 1 deletion apps/api/src/endpoints/endpoints.controllers.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Module } from '@nestjs/common'
import { config } from 'apps/api/config'
import { AuthController } from './auth/auth.controller'
import { AppsController } from './apps/apps.controller'
import { EndpointsServicesModule } from './endpoints.services.module'
import { CollectionsController } from './collections/collections.controller'
import { AppService, ContractService, DelegationService, DynamicModuleUtils, HealthCheckController } from '@mvx-monorepo/common'

@Module({
imports: [EndpointsServicesModule, DynamicModuleUtils.getCachingModule(config)],
providers: [DynamicModuleUtils.getNestJsApiConfigService(), AppService, DelegationService, ContractService],
controllers: [AuthController, HealthCheckController, CollectionsController],
controllers: [AuthController, HealthCheckController, AppsController, CollectionsController],
})
export class EndpointsControllersModule {}

0 comments on commit 621ac9d

Please sign in to comment.