Spaces:
Runtime error
Runtime error
| import { Controller, Get, Post, Delete, Param, Body, HttpCode, HttpStatus } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger'; | |
| import { LabelService } from './label.service'; | |
| import { AddLabelDto } from './dto/add-label.dto'; | |
| import { RequireRole } from '../auth/decorators/auth.decorators'; | |
| import { ApiKeyRole } from '../auth/entities/api-key.entity'; | |
| ('labels') | |
| ('sessions/:sessionId/labels') | |
| export class LabelController { | |
| constructor(private readonly labelService: LabelService) {} | |
| () | |
| ({ summary: 'Get all labels (WhatsApp Business only)' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of labels', | |
| }) | |
| ({ status: 400, description: 'Session not ready or not a business account' }) | |
| ({ status: 404, description: 'Session not found' }) | |
| async findAll(('sessionId') sessionId: string) { | |
| return this.labelService.getLabels(sessionId); | |
| } | |
| (':labelId') | |
| ({ summary: 'Get a specific label by ID' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'labelId', description: 'Label ID' }) | |
| ({ | |
| status: 200, | |
| description: 'Label details', | |
| }) | |
| ({ status: 404, description: 'Label not found' }) | |
| async findOne(('sessionId') sessionId: string, ('labelId') labelId: string) { | |
| return this.labelService.getLabelById(sessionId, labelId); | |
| } | |
| ('chat/:chatId') | |
| ({ summary: 'Get labels for a specific chat' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'chatId', description: 'Chat ID' }) | |
| ({ | |
| status: 200, | |
| description: 'List of labels for the chat', | |
| }) | |
| async getChatLabels(('sessionId') sessionId: string, ('chatId') chatId: string) { | |
| return this.labelService.getChatLabels(sessionId, chatId); | |
| } | |
| ('chat/:chatId') | |
| (ApiKeyRole.OPERATOR) | |
| (HttpStatus.OK) | |
| ({ summary: 'Add a label to a chat' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'chatId', description: 'Chat ID' }) | |
| ({ | |
| schema: { | |
| type: 'object', | |
| properties: { | |
| labelId: { type: 'string', description: 'Label ID to add' }, | |
| }, | |
| required: ['labelId'], | |
| }, | |
| }) | |
| ({ | |
| status: 200, | |
| description: 'Label added to chat', | |
| }) | |
| ({ | |
| status: 422, | |
| description: 'Labels require a WhatsApp Business account, or the chat type has no labels', | |
| }) | |
| async addLabelToChat( | |
| ('sessionId') sessionId: string, | |
| ('chatId') chatId: string, | |
| () body: AddLabelDto, | |
| ) { | |
| await this.labelService.addLabelToChat(sessionId, chatId, body.labelId); | |
| return { success: true }; | |
| } | |
| ('chat/:chatId/:labelId') | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'Remove a label from a chat' }) | |
| ({ name: 'sessionId', description: 'Session ID' }) | |
| ({ name: 'chatId', description: 'Chat ID' }) | |
| ({ name: 'labelId', description: 'Label ID to remove' }) | |
| ({ | |
| status: 200, | |
| description: 'Label removed from chat', | |
| }) | |
| ({ | |
| status: 422, | |
| description: 'Labels require a WhatsApp Business account, or the chat type has no labels', | |
| }) | |
| async removeLabelFromChat( | |
| ('sessionId') sessionId: string, | |
| ('chatId') chatId: string, | |
| ('labelId') labelId: string, | |
| ) { | |
| await this.labelService.removeLabelFromChat(sessionId, chatId, labelId); | |
| return { success: true }; | |
| } | |
| } | |