Spaces:
Runtime error
Runtime error
File size: 2,593 Bytes
4327358 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
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 {
@ApiProperty({
example: 'Lead',
description: 'Label name',
})
@IsString()
name: string;
@ApiProperty({
example: '#ff9485',
description: 'Color in hex',
})
@IsHexColor()
@IsOptional()
colorHex?: string;
@ApiProperty({
example: null,
description: 'Color number, not hex',
})
@IsNumber()
@IsOptional()
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 {
@ApiProperty({
example: '1',
description: 'Label ID',
})
id: string;
@ApiProperty({
example: 'Lead',
description: 'Label name',
})
name: string;
@ApiProperty({
example: 0,
description: 'Color number, not hex',
})
color: number;
@ApiProperty({
example: '#ff9485',
description: 'Color in hex',
})
colorHex: string;
static toHex(color: number) {
if (color >= Colors.length) {
return '#000000';
}
return Colors[color];
}
}
export class LabelID {
@ApiProperty({
example: '1',
description: 'Label ID',
})
id: string;
}
export class SetLabelsRequest {
labels: LabelID[];
}
export class LabelChatAssociation {
@ApiProperty({
example: '1',
description: 'Label ID',
})
labelId: string;
label: Label | null;
@ChatIdProperty({
description: 'Chat ID',
})
chatId: string;
}
|