Spaces:
Runtime error
Runtime error
| import { UnprocessableEntityException } from '@nestjs/common'; | |
| import { ApiProperty } from '@nestjs/swagger'; | |
| import { ChatIdProperty } from '@waha/structures/properties.dto'; | |
| import { IsHexColor, IsNumber, IsOptional, IsString } from 'class-validator'; | |
| const Colors = [ | |
| '#ff9485', | |
| '#64c4ff', | |
| '#ffd429', | |
| '#dfaef0', | |
| '#99b6c1', | |
| '#55ccb3', | |
| '#ff9dff', | |
| '#d3a91d', | |
| '#6d7cce', | |
| '#d7e752', | |
| '#00d0e2', | |
| '#ffc5c7', | |
| '#93ceac', | |
| '#f74848', | |
| '#00a0f2', | |
| '#83e422', | |
| '#ffaf04', | |
| '#b5ebff', | |
| '#9ba6ff', | |
| '#9368cf', | |
| ]; | |
| export class LabelBody { | |
| ({ | |
| example: 'Lead', | |
| description: 'Label name', | |
| }) | |
| () | |
| name: string; | |
| ({ | |
| example: '#ff9485', | |
| description: 'Color in hex', | |
| }) | |
| () | |
| () | |
| colorHex?: string; | |
| ({ | |
| example: null, | |
| description: 'Color number, not hex', | |
| }) | |
| () | |
| () | |
| color?: number; | |
| toDTO(): LabelDTO { | |
| if (this.color != null && this.colorHex != null) { | |
| throw new UnprocessableEntityException( | |
| "Use either 'color' or 'colorHex'", | |
| ); | |
| } | |
| if (this.color == null && this.colorHex == null) { | |
| throw new UnprocessableEntityException( | |
| "'color' or 'colorHex' is required", | |
| ); | |
| } | |
| if (this.colorHex) { | |
| const color = Colors.indexOf(this.colorHex); | |
| if (color == -1) { | |
| throw new UnprocessableEntityException( | |
| "Invalid 'colorHex'. Possible values: " + Colors.join(', '), | |
| ); | |
| } | |
| this.color = color; | |
| } | |
| return { | |
| name: this.name, | |
| color: this.color, | |
| }; | |
| } | |
| } | |
| export class LabelDTO { | |
| name: string; | |
| color: number; | |
| } | |
| export class Label { | |
| ({ | |
| example: '1', | |
| description: 'Label ID', | |
| }) | |
| id: string; | |
| ({ | |
| example: 'Lead', | |
| description: 'Label name', | |
| }) | |
| name: string; | |
| ({ | |
| example: 0, | |
| description: 'Color number, not hex', | |
| }) | |
| color: number; | |
| ({ | |
| example: '#ff9485', | |
| description: 'Color in hex', | |
| }) | |
| colorHex: string; | |
| static toHex(color: number) { | |
| if (color >= Colors.length) { | |
| return '#000000'; | |
| } | |
| return Colors[color]; | |
| } | |
| } | |
| export class LabelID { | |
| ({ | |
| example: '1', | |
| description: 'Label ID', | |
| }) | |
| id: string; | |
| } | |
| export class SetLabelsRequest { | |
| labels: LabelID[]; | |
| } | |
| export class LabelChatAssociation { | |
| ({ | |
| example: '1', | |
| description: 'Label ID', | |
| }) | |
| labelId: string; | |
| label: Label | null; | |
| ({ | |
| description: 'Chat ID', | |
| }) | |
| chatId: string; | |
| } | |