|
1 | | -import { ApiProperty, PartialType } from '@nestjs/swagger'; |
2 | | -import { IsString, IsNotEmpty, ValidateNested, IsEmail, IsBoolean, IsMongoId, IsOptional } from 'class-validator'; |
3 | | -import { Type } from 'class-transformer'; |
4 | | -import { StatePartDTO } from './parts/state.part.dto'; |
5 | | -import { SecurityPartDTO } from './parts/security.part.dto'; |
6 | | -import { CustomFieldsDto } from '~/_common/abstracts/dto/custom-fields.dto'; |
| 1 | +import { ApiProperty, PartialType } from '@nestjs/swagger' |
| 2 | +import { IsString, IsNotEmpty, ValidateNested, IsEmail, IsBoolean, IsMongoId, IsOptional } from 'class-validator' |
| 3 | +import { Type } from 'class-transformer' |
| 4 | +import { StatePartDTO } from './parts/state.part.dto' |
| 5 | +import { SecurityPartDTO } from './parts/security.part.dto' |
| 6 | +import { CustomFieldsDto } from '~/_common/abstracts/dto/custom-fields.dto' |
7 | 7 |
|
| 8 | +/** |
| 9 | + * DTO pour la création d'un agent. |
| 10 | + * |
| 11 | + * Ce DTO définit les données requises et optionnelles pour créer un nouvel agent |
| 12 | + * dans le système. Il inclut les validations nécessaires pour garantir l'intégrité |
| 13 | + * des données et hérite des fonctionnalités de champs personnalisés. |
| 14 | + * |
| 15 | + * @class AgentsCreateDto |
| 16 | + * @extends {CustomFieldsDto} |
| 17 | + * |
| 18 | + * @description |
| 19 | + * Données requises : |
| 20 | + * - username : Nom d'utilisateur unique |
| 21 | + * - email : Adresse email unique et valide |
| 22 | + * - password : Mot de passe (sera haché automatiquement avec Argon2) |
| 23 | + * - state : État de lifecycle de l'agent |
| 24 | + * |
| 25 | + * Données optionnelles : |
| 26 | + * - displayName : Nom d'affichage convivial |
| 27 | + * - thirdPartyAuth : Méthode d'authentification tierce |
| 28 | + * - baseURL : URL de base pour l'agent |
| 29 | + * - security : Configuration de sécurité (clés, restrictions, etc.) |
| 30 | + * - hidden : Indicateur de visibilité de l'agent |
| 31 | + * - customFields : Champs personnalisés additionnels (hérité) |
| 32 | + * |
| 33 | + * Note : Le mot de passe sera automatiquement haché et une clé secrète |
| 34 | + * sera générée lors de la création par le service AgentsService. |
| 35 | + * |
| 36 | + * @example |
| 37 | + * ```typescript |
| 38 | + * const createDto: AgentsCreateDto = { |
| 39 | + * username: "john.doe", |
| 40 | + * email: "john.doe@example.com", |
| 41 | + * password: "SecurePassword123!", |
| 42 | + * displayName: "John Doe", |
| 43 | + * state: { current: AgentState.PENDING }, |
| 44 | + * baseURL: "/", |
| 45 | + * hidden: false |
| 46 | + * }; |
| 47 | + * ``` |
| 48 | + */ |
8 | 49 | export class AgentsCreateDto extends CustomFieldsDto { |
9 | | - // @IsMongoId() |
10 | | - // @IsNotEmpty() |
11 | | - // @ApiProperty({ type: String }) |
12 | | - // public entityId: string |
13 | | - |
| 50 | + /** |
| 51 | + * Nom d'utilisateur unique de l'agent. |
| 52 | + * |
| 53 | + * @type {string} |
| 54 | + * @required |
| 55 | + */ |
14 | 56 | @IsString() |
15 | 57 | @IsNotEmpty() |
16 | 58 | @ApiProperty() |
17 | | - public username: string; |
| 59 | + public username: string |
18 | 60 |
|
| 61 | + /** |
| 62 | + * Nom d'affichage de l'agent. |
| 63 | + * |
| 64 | + * @type {string} |
| 65 | + * @optional |
| 66 | + */ |
19 | 67 | @IsString() |
20 | 68 | @IsOptional() |
21 | 69 | @ApiProperty() |
22 | | - public displayName?: string; |
| 70 | + public displayName?: string |
23 | 71 |
|
| 72 | + /** |
| 73 | + * Adresse email unique de l'agent. |
| 74 | + * Doit être une adresse email valide. |
| 75 | + * |
| 76 | + * @type {string} |
| 77 | + * @required |
| 78 | + */ |
24 | 79 | @IsEmail() |
25 | 80 | @IsNotEmpty() |
26 | 81 | @ApiProperty() |
27 | | - public email: string; |
| 82 | + public email: string |
28 | 83 |
|
| 84 | + /** |
| 85 | + * Mot de passe de l'agent. |
| 86 | + * Sera automatiquement haché avec Argon2 avant stockage. |
| 87 | + * |
| 88 | + * @type {string} |
| 89 | + * @required |
| 90 | + */ |
29 | 91 | @IsString() |
30 | 92 | @IsNotEmpty() |
31 | 93 | @ApiProperty() |
32 | | - public password: string; |
| 94 | + public password: string |
33 | 95 |
|
| 96 | + /** |
| 97 | + * Méthode d'authentification tierce. |
| 98 | + * |
| 99 | + * @type {string} |
| 100 | + * @optional |
| 101 | + * @default "local" |
| 102 | + * @example "local", "oauth2", "saml" |
| 103 | + */ |
34 | 104 | @IsString() |
35 | 105 | @IsOptional() |
36 | 106 | @ApiProperty() |
37 | | - public thirdPartyAuth?: string; |
| 107 | + public thirdPartyAuth?: string |
38 | 108 |
|
| 109 | + /** |
| 110 | + * État de lifecycle de l'agent. |
| 111 | + * |
| 112 | + * @type {StatePartDTO} |
| 113 | + * @required |
| 114 | + */ |
39 | 115 | @ValidateNested() |
40 | 116 | @Type(() => StatePartDTO) |
41 | 117 | @IsNotEmpty() |
42 | 118 | @ApiProperty({ type: StatePartDTO }) |
43 | | - public state: StatePartDTO; |
| 119 | + public state: StatePartDTO |
44 | 120 |
|
| 121 | + /** |
| 122 | + * URL de base pour l'agent. |
| 123 | + * |
| 124 | + * @type {string} |
| 125 | + * @optional |
| 126 | + * @default "/" |
| 127 | + */ |
45 | 128 | @IsString() |
46 | 129 | @IsOptional() |
47 | 130 | @ApiProperty() |
48 | | - public baseURL?: string; |
49 | | - |
50 | | - // @IsArray() |
51 | | - // @IsString({ each: true }) |
52 | | - // @ApiProperty({ type: [String] }) |
53 | | - // public roles: string[]; |
| 131 | + public baseURL?: string |
54 | 132 |
|
| 133 | + /** |
| 134 | + * Configuration de sécurité de l'agent. |
| 135 | + * Contient les clés, restrictions et paramètres de sécurité. |
| 136 | + * |
| 137 | + * @type {SecurityPartDTO} |
| 138 | + */ |
55 | 139 | @ValidateNested() |
56 | 140 | @Type(() => SecurityPartDTO) |
57 | 141 | @ApiProperty({ type: SecurityPartDTO }) |
58 | | - public security: SecurityPartDTO; |
| 142 | + public security: SecurityPartDTO |
59 | 143 |
|
| 144 | + /** |
| 145 | + * Indicateur de visibilité de l'agent. |
| 146 | + * Si true, l'agent est masqué dans les listes publiques. |
| 147 | + * |
| 148 | + * @type {boolean} |
| 149 | + * @optional |
| 150 | + */ |
60 | 151 | @IsBoolean() |
61 | 152 | @IsOptional() |
62 | 153 | @ApiProperty() |
63 | | - public hidden: boolean; |
| 154 | + public hidden: boolean |
64 | 155 | } |
65 | 156 |
|
| 157 | +/** |
| 158 | + * DTO représentant un agent complet avec son identifiant. |
| 159 | + * |
| 160 | + * Utilisé pour les réponses API qui retournent un agent existant. |
| 161 | + * Inclut toutes les propriétés de création plus l'identifiant MongoDB. |
| 162 | + * |
| 163 | + * @class AgentsDto |
| 164 | + * @extends {AgentsCreateDto} |
| 165 | + * |
| 166 | + * @example |
| 167 | + * ```typescript |
| 168 | + * const agent: AgentsDto = { |
| 169 | + * _id: "507f1f77bcf86cd799439011", |
| 170 | + * username: "john.doe", |
| 171 | + * email: "john.doe@example.com", |
| 172 | + * // ... autres propriétés |
| 173 | + * }; |
| 174 | + * ``` |
| 175 | + */ |
66 | 176 | export class AgentsDto extends AgentsCreateDto { |
| 177 | + /** |
| 178 | + * Identifiant unique MongoDB de l'agent. |
| 179 | + * |
| 180 | + * @type {string} |
| 181 | + * @required |
| 182 | + */ |
67 | 183 | @IsMongoId() |
68 | 184 | @ApiProperty({ type: String }) |
69 | | - public _id: string; |
| 185 | + public _id: string |
70 | 186 | } |
71 | 187 |
|
72 | | -export class AgentsUpdateDto extends PartialType(AgentsCreateDto) {} |
| 188 | +/** |
| 189 | + * DTO pour la mise à jour d'un agent. |
| 190 | + * |
| 191 | + * Toutes les propriétés d'AgentsCreateDto sont optionnelles pour permettre |
| 192 | + * des mises à jour partielles. Utilise PartialType de NestJS pour générer |
| 193 | + * automatiquement la version partielle du DTO de création. |
| 194 | + * |
| 195 | + * @class AgentsUpdateDto |
| 196 | + * @extends {PartialType(AgentsCreateDto)} |
| 197 | + * |
| 198 | + * @description |
| 199 | + * Note : Si le mot de passe est fourni dans les données de mise à jour, |
| 200 | + * il sera automatiquement re-haché par le service AgentsService. |
| 201 | + * |
| 202 | + * @example |
| 203 | + * ```typescript |
| 204 | + * // Mise à jour du nom d'affichage uniquement |
| 205 | + * const updateDto: AgentsUpdateDto = { |
| 206 | + * displayName: "John F. Doe" |
| 207 | + * }; |
| 208 | + * |
| 209 | + * // Mise à jour de plusieurs champs |
| 210 | + * const updateDto: AgentsUpdateDto = { |
| 211 | + * displayName: "John F. Doe", |
| 212 | + * state: { current: AgentState.ACTIVE } |
| 213 | + * }; |
| 214 | + * ``` |
| 215 | + */ |
| 216 | +export class AgentsUpdateDto extends PartialType(AgentsCreateDto) { } |
0 commit comments