Spaces:
Runtime error
Runtime error
| import { | |
| Body, | |
| Controller, | |
| Delete, | |
| Get, | |
| Inject, | |
| NotFoundException, | |
| Param, | |
| Post, | |
| Put, | |
| Query, | |
| UsePipes, | |
| } from '@nestjs/common'; | |
| import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger'; | |
| import { | |
| AppsService, | |
| IAppsService, | |
| } from '@waha/apps/app_sdk/services/IAppsService'; | |
| import { SessionManager } from '@waha/core/abc/manager.abc'; | |
| import { WAHAValidationPipe } from '@waha/nestjs/pipes/WAHAValidationPipe'; | |
| import { App } from '../dto/app.dto'; | |
| import { ListAppsQuery } from '../dto/query.dto'; | |
| ('api_key') | |
| ('api/apps') | |
| ('🧩 Apps') | |
| export class AppsController { | |
| constructor( | |
| (AppsService) | |
| private appsService: IAppsService, | |
| private manager: SessionManager, | |
| ) {} | |
| ('/') | |
| ({ summary: 'List all apps for a session' }) | |
| (new WAHAValidationPipe()) | |
| async list( | |
| (new WAHAValidationPipe()) query: ListAppsQuery, | |
| ): Promise<App[]> { | |
| return this.appsService.list(this.manager, query.session); | |
| } | |
| ('/') | |
| ({ summary: 'Create a new app' }) | |
| (new WAHAValidationPipe()) | |
| async create(() app: App): Promise<App> { | |
| return await this.appsService.create(this.manager, app); | |
| } | |
| ('/:id') | |
| ({ summary: 'Update an existing app' }) | |
| (new WAHAValidationPipe()) | |
| async update(('id') id: string, () app: App): Promise<void> { | |
| if (!app.id) { | |
| app.id = id; | |
| } else if (app.id !== id) { | |
| throw new NotFoundException( | |
| `App ID in path (${id}) does not match ID in body (${app.id})`, | |
| ); | |
| } | |
| await this.appsService.update(this.manager, app); | |
| } | |
| ('/:id') | |
| ({ summary: 'Delete an app' }) | |
| (new WAHAValidationPipe()) | |
| async delete(('id') id: string): Promise<void> { | |
| await this.appsService.delete(this.manager, id); | |
| } | |
| } | |