feat: DTOs partagés pour la validation des données - Ajout des classes de transfert de données pour toutes les entités
This commit is contained in:
63
src/shared/dto/composant.dto.ts
Normal file
63
src/shared/dto/composant.dto.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { IsString, IsOptional, IsNumber } from 'class-validator';
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export class CreateComposantDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
machineId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
parentComposantId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
reference?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
prestataire?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => value === '' ? null : value)
|
||||
@IsNumber({}, { message: 'prix must be a valid number' })
|
||||
prix?: number | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
emplacement?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
typeComposantId?: string;
|
||||
}
|
||||
|
||||
export class UpdateComposantDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
reference?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
prestataire?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => value === '' ? null : value)
|
||||
@IsNumber({}, { message: 'prix must be a valid number' })
|
||||
prix?: number | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
emplacement?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
typeComposantId?: string;
|
||||
}
|
||||
29
src/shared/dto/custom-field.dto.ts
Normal file
29
src/shared/dto/custom-field.dto.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { IsString, IsOptional, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class CreateCustomFieldValueDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
customFieldId: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
value: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
machineId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
composantId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
pieceId?: string;
|
||||
}
|
||||
|
||||
export class UpdateCustomFieldValueDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
value?: string;
|
||||
}
|
||||
52
src/shared/dto/document.dto.ts
Normal file
52
src/shared/dto/document.dto.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { IsString, IsOptional, IsNumber } from 'class-validator';
|
||||
|
||||
export class CreateDocumentDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
filename: string;
|
||||
|
||||
@IsString()
|
||||
path: string;
|
||||
|
||||
@IsString()
|
||||
mimeType: string;
|
||||
|
||||
@IsNumber()
|
||||
size: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
machineId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
composantId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
pieceId?: string;
|
||||
}
|
||||
|
||||
export class UpdateDocumentDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
filename?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
path?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
mimeType?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
size?: number;
|
||||
}
|
||||
55
src/shared/dto/machine.dto.ts
Normal file
55
src/shared/dto/machine.dto.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { IsString, IsOptional, IsNumber, IsDecimal } from 'class-validator';
|
||||
|
||||
export class CreateMachineDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
siteId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
reference?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
prestataire?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDecimal()
|
||||
prix?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
emplacement?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
typeMachineId?: string;
|
||||
}
|
||||
|
||||
export class UpdateMachineDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
reference?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
prestataire?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDecimal()
|
||||
prix?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
emplacement?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
typeMachineId?: string;
|
||||
}
|
||||
63
src/shared/dto/piece.dto.ts
Normal file
63
src/shared/dto/piece.dto.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { IsString, IsOptional, IsNumber } from 'class-validator';
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export class CreatePieceDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
machineId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
composantId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
reference?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
prestataire?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => value === '' ? null : value)
|
||||
@IsNumber({}, { message: 'prix must be a valid number' })
|
||||
prix?: number | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
emplacement?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
typePieceId?: string;
|
||||
}
|
||||
|
||||
export class UpdatePieceDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
reference?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
prestataire?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => value === '' ? null : value)
|
||||
@IsNumber({}, { message: 'prix must be a valid number' })
|
||||
prix?: number | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
emplacement?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
typePieceId?: string;
|
||||
}
|
||||
20
src/shared/dto/site.dto.ts
Normal file
20
src/shared/dto/site.dto.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { IsString, IsOptional } from 'class-validator';
|
||||
|
||||
export class CreateSiteDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export class UpdateSiteDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
}
|
||||
164
src/shared/dto/type.dto.ts
Normal file
164
src/shared/dto/type.dto.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { IsString, IsOptional, IsArray, IsObject, IsBoolean, IsEnum } from 'class-validator';
|
||||
|
||||
export enum CustomFieldType {
|
||||
TEXT = 'text',
|
||||
NUMBER = 'number',
|
||||
SELECT = 'select',
|
||||
BOOLEAN = 'boolean',
|
||||
DATE = 'date'
|
||||
}
|
||||
|
||||
export class CreateCustomFieldDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsEnum(CustomFieldType)
|
||||
type: CustomFieldType;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
required?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
defaultValue?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
options?: string[]; // Pour les champs de type SELECT
|
||||
}
|
||||
|
||||
export class UpdateCustomFieldDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(CustomFieldType)
|
||||
type?: CustomFieldType;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
required?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
defaultValue?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
options?: string[];
|
||||
}
|
||||
|
||||
export class CreateTypeMachineDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
category?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
maintenanceFrequency?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
components?: any[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
machinePieces?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
customFields?: CreateCustomFieldDto[];
|
||||
}
|
||||
|
||||
export class UpdateTypeMachineDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
category?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
maintenanceFrequency?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
components?: any[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
machinePieces?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
customFields?: CreateCustomFieldDto[];
|
||||
}
|
||||
|
||||
export class CreateTypeComposantDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
customFields?: CreateCustomFieldDto[];
|
||||
}
|
||||
|
||||
export class UpdateTypeComposantDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
customFields?: CreateCustomFieldDto[];
|
||||
}
|
||||
|
||||
export class CreateTypePieceDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
customFields?: CreateCustomFieldDto[];
|
||||
}
|
||||
|
||||
export class UpdateTypePieceDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
customFields?: CreateCustomFieldDto[];
|
||||
}
|
||||
Reference in New Issue
Block a user