| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { Transform, Type |
| 3 | import { |
| 4 | ArrayMaxSize, |
| 5 | IsArray, |
| 6 | IsISO8601, |
| 7 | IsOptional, |
| 8 | IsString, |
| 9 | Matches, |
| 10 | MaxLength, |
| 11 | MinLength, |
| 12 | ValidateNested, |
| 13 | } from 'class-validator'; |
| 14 | |
| 15 | export class LabelDTO |
| 16 | @ApiProperty() |
| 17 | @IsString() |
| 18 | id: string; |
| 19 | |
| 20 | @ApiProperty({ example |
| 21 | @IsString() |
| 22 | name: string; |
| 23 | |
| 24 | @ApiProperty({ type |
| 25 | @IsString() |
| 26 | @IsOptional() |
| 27 | description: string |
| 28 | |
| 29 | @ApiProperty({ |
| 30 | description: '6 hex chars, no `#`. The client adds `#` when rendering.', |
| 31 | example: 'd73a4a', |
| 32 | }) |
| 33 | @IsString() |
| 34 | color: string; |
| 35 | |
| 36 | @ApiProperty() |
| 37 | @IsISO8601() |
| 38 | createdAt: string; |
| 39 | |
| 40 | @ApiProperty() |
| 41 | @IsISO8601() |
| 42 | updatedAt: string; |
| 43 | } |
| 44 | |
| 45 | export class CreateLabelRequestDTO |
| 46 | @ApiProperty({ example |
| 47 | @IsString() |
| 48 | @Transform(({ |
| 49 | @MinLength(1) |
| 50 | @MaxLength(50) |
| 51 | name: string; |
| 52 | |
| 53 | @ApiPropertyOptional({ example |
| 54 | @IsString() |
| 55 | @IsOptional() |
| 56 | @MaxLength(100) |
| 57 | description?: string |
| 58 | |
| 59 | @ApiProperty({ example |
| 60 | @IsString() |
| 61 | @Matches(/^[ |
| 62 | message: 'Color must be 6 hex characters, e.g. d73a4a.', |
| 63 | }) |
| 64 | color: string; |
| 65 | } |
| 66 | |
| 67 | export class UpdateLabelRequestDTO |
| 68 | @ApiPropertyOptional({ example |
| 69 | @IsString() |
| 70 | @IsOptional() |
| 71 | @Transform(({ |
| 72 | @MinLength(1) |
| 73 | @MaxLength(50) |
| 74 | name?: string |
| 75 | |
| 76 | @ApiPropertyOptional({ |
| 77 | type: String, |
| 78 | nullable: true, |
| 79 | description: '`null` clears the description.', |
| 80 | }) |
| 81 | @IsString() |
| 82 | @IsOptional() |
| 83 | @MaxLength(100) |
| 84 | description?: string |
| 85 | |
| 86 | @ApiPropertyOptional({ example |
| 87 | @IsString() |
| 88 | @IsOptional() |
| 89 | @Matches(/^[ |
| 90 | message: 'Color must be 6 hex characters, e.g. d73a4a.', |
| 91 | }) |
| 92 | color?: string |
| 93 | } |
| 94 | |
| 95 | export class GetLabelsResponseDTO |
| 96 | @ApiProperty({ type |
| 97 | @ValidateNested({ each |
| 98 | @Type(() => |
| 99 | labels: LabelDTO |
| 100 | } |
| 101 | |
| 102 | export class SetIssueLabelsRequestDTO |
| 103 | @ApiProperty({ |
| 104 | description: 'Full replacement set. Label names in this repository.', |
| 105 | example: ['bug', |
| 106 | }) |
| 107 | @IsArray() |
| 108 | @IsString({ each |
| 109 | @MaxLength(50, |
| 110 | @ArrayMaxSize(20) |
| 111 | names: string[] |
| 112 | } |
| 113 | |
| 114 | export class SetIssueAssigneesRequestDTO |
| 115 | @ApiProperty({ |
| 116 | description: 'Full replacement set. Usernames to assign.', |
| 117 | example: ['octocat'], |
| 118 | }) |
| 119 | @IsArray() |
| 120 | @IsString({ each |
| 121 | @MaxLength(100, |
| 122 | @ArrayMaxSize(10) |
| 123 | usernames: string[] |
| 124 | } |