From 2ce164784f38fea3a6ccddcb9d7794383eab3e3f Mon Sep 17 00:00:00 2001 From: Matthieu Date: Thu, 25 Sep 2025 11:26:22 +0200 Subject: [PATCH] FIx: delete champs par default --- .../migration.sql | 3 + prisma/schema.prisma | 39 ++- src/machines/machines.service.ts | 297 +++++++++++------- src/shared/dto/composant.dto.ts | 8 - src/shared/dto/machine.dto.ts | 8 - src/shared/dto/piece.dto.ts | 8 - src/shared/dto/type.dto.ts | 8 - src/types/types.service.ts | 38 +-- test/app.e2e-spec.ts | 17 +- 9 files changed, 226 insertions(+), 200 deletions(-) create mode 100644 prisma/migrations/20250803120000_remove_emplacement/migration.sql diff --git a/prisma/migrations/20250803120000_remove_emplacement/migration.sql b/prisma/migrations/20250803120000_remove_emplacement/migration.sql new file mode 100644 index 0000000..9938976 --- /dev/null +++ b/prisma/migrations/20250803120000_remove_emplacement/migration.sql @@ -0,0 +1,3 @@ +ALTER TABLE "machines" DROP COLUMN IF EXISTS "emplacement"; +ALTER TABLE "composants" DROP COLUMN IF EXISTS "emplacement"; +ALTER TABLE "pieces" DROP COLUMN IF EXISTS "emplacement"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1ba6a74..17abd92 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -52,13 +52,12 @@ model TypeMachine { } model Machine { - id String @id @default(cuid()) - name String - reference String? - prix Decimal? @db.Decimal(10, 2) - emplacement String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @default(cuid()) + name String + reference String? + prix Decimal? @db.Decimal(10, 2) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt // Relations siteId String @@ -79,13 +78,12 @@ model Machine { } model Composant { - id String @id @default(cuid()) - name String - reference String? - prix Decimal? @db.Decimal(10, 2) - emplacement String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @default(cuid()) + name String + reference String? + prix Decimal? @db.Decimal(10, 2) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt // Relations hiérarchiques machineId String? @@ -115,13 +113,12 @@ model Composant { } model Piece { - id String @id @default(cuid()) - name String - reference String? - prix Decimal? @db.Decimal(10, 2) - emplacement String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @default(cuid()) + name String + reference String? + prix Decimal? @db.Decimal(10, 2) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt // Relations machineId String? diff --git a/src/machines/machines.service.ts b/src/machines/machines.service.ts index 8cdaf86..69a847a 100644 --- a/src/machines/machines.service.ts +++ b/src/machines/machines.service.ts @@ -9,8 +9,16 @@ import { MachinePieceSelectionDto, } from '../shared/dto/machine.dto'; +const CUSTOM_FIELD_SELECT = { + id: true, + name: true, + type: true, + required: true, + options: true, +} as const; + const TYPE_MACHINE_CONFIGURATION_INCLUDE = { - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, componentRequirements: { include: { typeComposant: true, @@ -41,7 +49,7 @@ const MACHINE_DEFAULT_INCLUDE = { sousComposants: true, customFieldValues: { include: { - customField: true, + customField: { select: CUSTOM_FIELD_SELECT }, }, }, constructeur: true, @@ -49,7 +57,7 @@ const MACHINE_DEFAULT_INCLUDE = { include: { customFieldValues: { include: { - customField: true, + customField: { select: CUSTOM_FIELD_SELECT }, }, }, constructeur: true, @@ -67,7 +75,7 @@ const MACHINE_DEFAULT_INCLUDE = { include: { customFieldValues: { include: { - customField: true, + customField: { select: CUSTOM_FIELD_SELECT }, }, }, constructeur: true, @@ -81,7 +89,7 @@ const MACHINE_DEFAULT_INCLUDE = { }, customFieldValues: { include: { - customField: true, + customField: { select: CUSTOM_FIELD_SELECT }, }, }, documents: true, @@ -472,6 +480,19 @@ export class MachinesService { } } + private extractCustomFieldValue(field: any): string | undefined { + if ( + field && + Object.prototype.hasOwnProperty.call(field, 'value') + ) { + const rawValue = field.value; + return rawValue === undefined || rawValue === null + ? '' + : String(rawValue); + } + return undefined; + } + private normalizeComponentSelection( selection: MachineComponentSelectionDto, requirement: any, @@ -491,8 +512,6 @@ export class MachinesService { 'Composant'; prepared.reference = prepared.reference ?? model?.structure?.reference ?? ''; - prepared.emplacement = - prepared.emplacement ?? model?.structure?.emplacement ?? ''; prepared.prix = prepared.prix ?? model?.structure?.prix ?? null; prepared.customFields = Array.isArray(prepared.customFields) @@ -565,6 +584,14 @@ export class MachinesService { const customFields = Array.isArray(component.customFields) ? component.customFields : []; + const componentFieldMap = new Map( + customFields + .filter((field) => field && typeof field.name === 'string') + .map((field) => [field.name, field]), + ); + const resolveComponentValue = (fieldName: string) => + this.extractCustomFieldValue(componentFieldMap.get(fieldName)); + const componentPieces = Array.isArray(component.pieces) ? component.pieces : []; @@ -582,7 +609,7 @@ export class MachinesService { let typeComposantId: string | null = providedTypeComposantId ?? null; - if (!typeComposantId && customFields.length > 0) { + if (!typeComposantId && componentFieldMap.size > 0) { let typeComposant = await prisma.modelType.findFirst({ where: { name: component.name, @@ -604,12 +631,12 @@ export class MachinesService { }); for (const customField of customFields) { + if (!customField?.name) continue; await prisma.customField.create({ data: { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typeComposantId: typeComposant.id, }, @@ -628,7 +655,6 @@ export class MachinesService { prisma, component.constructeur, ), - emplacement: component.emplacement || '', prix: component.prix ?? null, machineId, parentComposantId, @@ -644,16 +670,16 @@ export class MachinesService { }); for (const customField of typeCustomFields) { - const defaultValue = - customFields.find((cf) => cf.name === customField.name) - ?.defaultValue || ''; - await prisma.customFieldValue.create({ - data: { - value: defaultValue, - customFieldId: customField.id, - composantId: createdComposant.id, - }, - }); + const providedValue = resolveComponentValue(customField.name); + if (providedValue !== undefined) { + await prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: customField.id, + composantId: createdComposant.id, + }, + }); + } } } @@ -663,6 +689,13 @@ export class MachinesService { const pieceCustomFields = Array.isArray(piece.customFields) ? piece.customFields : []; + const pieceFieldMap = new Map( + pieceCustomFields + .filter((field) => field && typeof field.name === 'string') + .map((field) => [field.name, field]), + ); + const resolvePieceValue = (fieldName: string) => + this.extractCustomFieldValue(pieceFieldMap.get(fieldName)); const pieceModelId = piece.__pieceModelId ?? null; const pieceRequirementId = piece.__requirementId ?? null; const providedTypePieceId = @@ -671,7 +704,7 @@ export class MachinesService { let typePieceId: string | null = providedTypePieceId ?? null; - if (!typePieceId && pieceCustomFields.length > 0) { + if (!typePieceId && pieceFieldMap.size > 0) { let typePiece = await prisma.typePiece.findFirst({ where: { name: piece.name }, }); @@ -685,12 +718,12 @@ export class MachinesService { }); for (const customField of pieceCustomFields) { + if (!customField?.name) continue; await prisma.customField.create({ data: { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typePieceId: typePiece.id, }, @@ -709,7 +742,6 @@ export class MachinesService { prisma, piece.constructeur, ), - emplacement: piece.emplacement || '', prix: piece.prix ?? null, composantId: createdComposant.id, typePieceId, @@ -724,16 +756,16 @@ export class MachinesService { }); for (const customField of typePieceCustomFields) { - const defaultValue = - pieceCustomFields.find((cf) => cf.name === customField.name) - ?.defaultValue || ''; - await prisma.customFieldValue.create({ - data: { - value: defaultValue, - customFieldId: customField.id, - pieceId: createdPiece.id, - }, - }); + const providedValue = resolvePieceValue(customField.name); + if (providedValue !== undefined) { + await prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: customField.id, + pieceId: createdPiece.id, + }, + }); + } } } } @@ -760,6 +792,13 @@ export class MachinesService { const customFields = Array.isArray(piece.customFields) ? piece.customFields : []; + const fieldMap = new Map( + customFields + .filter((field) => field && typeof field.name === 'string') + .map((field) => [field.name, field]), + ); + const resolveProvidedValue = (fieldName: string) => + this.extractCustomFieldValue(fieldMap.get(fieldName)); const pieceModelId = piece.__pieceModelId ?? null; const requirementId = piece.__requirementId ?? null; const providedTypePieceId = @@ -768,7 +807,7 @@ export class MachinesService { let typePieceId: string | null = providedTypePieceId ?? null; - if (!typePieceId && customFields.length > 0) { + if (!typePieceId && fieldMap.size > 0) { let typePiece = await prisma.typePiece.findFirst({ where: { name: piece.name }, }); @@ -782,12 +821,12 @@ export class MachinesService { }); for (const customField of customFields) { + if (!customField?.name) continue; await prisma.customField.create({ data: { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typePieceId: typePiece.id, }, @@ -806,7 +845,6 @@ export class MachinesService { prisma, piece.constructeur, ), - emplacement: piece.emplacement || '', prix: piece.prix ?? null, machineId, typePieceId, @@ -821,37 +859,40 @@ export class MachinesService { }); for (const customField of typePieceCustomFields) { - const defaultValue = - customFields.find((cf) => cf.name === customField.name) - ?.defaultValue || ''; - await prisma.customFieldValue.create({ - data: { - value: defaultValue, - customFieldId: customField.id, - pieceId: createdPiece.id, - }, - }); + const providedValue = resolveProvidedValue(customField.name); + if (providedValue !== undefined) { + await prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: customField.id, + pieceId: createdPiece.id, + }, + }); + } } - } else if (customFields.length > 0) { + } else if (fieldMap.size > 0) { for (const customField of customFields) { + if (!customField?.name) continue; const createdCustomField = await prisma.customField.create({ data: { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typePieceId: null, }, }); - await prisma.customFieldValue.create({ - data: { - value: customField.defaultValue || '', - customFieldId: createdCustomField.id, - pieceId: createdPiece.id, - }, - }); + const providedValue = this.extractCustomFieldValue(customField); + if (providedValue !== undefined) { + await prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: createdCustomField.id, + pieceId: createdPiece.id, + }, + }); + } } } } @@ -865,26 +906,26 @@ export class MachinesService { for (const customField of machineCustomFields) { if (!customField || !customField.name) continue; - // Créer le champ personnalisé pour la machine const createdCustomField = await prisma.customField.create({ data: { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typeMachineId: null, // Ce champ sera lié à la machine individuelle }, }); - // Créer la valeur par défaut pour la machine - await prisma.customFieldValue.create({ - data: { - value: customField.defaultValue || '', - customFieldId: createdCustomField.id, - machineId: machineId, - }, - }); + const providedValue = this.extractCustomFieldValue(customField); + if (providedValue !== undefined) { + await prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: createdCustomField.id, + machineId, + }, + }); + } } } @@ -1160,7 +1201,7 @@ export class MachinesService { }, }, include: { - customField: true, + customField: { select: CUSTOM_FIELD_SELECT }, }, }); @@ -1171,20 +1212,21 @@ export class MachinesService { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typeMachineId: null, // Ce champ sera lié à la machine individuelle }, }); - // Créer la valeur par défaut pour la machine - await this.prisma.customFieldValue.create({ - data: { - value: customField.defaultValue || '', - customFieldId: createdCustomField.id, - machineId: machineId, - }, - }); + const providedValue = this.extractCustomFieldValue(customField); + if (providedValue !== undefined) { + await this.prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: createdCustomField.id, + machineId, + }, + }); + } } } } @@ -1199,6 +1241,15 @@ export class MachinesService { typeComponent.customFields && typeComponent.customFields.length > 0 ) { + const typeComponentFields = Array.isArray(typeComponent.customFields) + ? typeComponent.customFields + : []; + const typeComponentFieldMap = new Map( + typeComponentFields + .filter((field: any) => field && typeof field.name === 'string') + .map((field: any) => [field.name, field]), + ); + // Créer le type de composant s'il n'existe pas let typeComposant = await this.prisma.modelType.findFirst({ where: { @@ -1222,7 +1273,7 @@ export class MachinesService { } // Créer les champs personnalisés pour le type de composant - for (const customField of typeComponent.customFields) { + for (const customField of typeComponentFields) { const existingField = await this.prisma.customField.findFirst({ where: { name: customField.name, @@ -1236,7 +1287,6 @@ export class MachinesService { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typeComposantId: typeComposant.id, }, @@ -1264,17 +1314,18 @@ export class MachinesService { }); if (!existingValue) { - const defaultValue = - typeComponent.customFields.find( - (cf: any) => cf.name === customField.name, - )?.defaultValue || ''; - await this.prisma.customFieldValue.create({ - data: { - value: defaultValue, - customFieldId: customField.id, - composantId: component.id, - }, - }); + const providedValue = this.extractCustomFieldValue( + typeComponentFieldMap.get(customField.name), + ); + if (providedValue !== undefined) { + await this.prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: customField.id, + composantId: component.id, + }, + }); + } } } @@ -1288,6 +1339,15 @@ export class MachinesService { typePiece.customFields && typePiece.customFields.length > 0 ) { + const typePieceFields = Array.isArray(typePiece.customFields) + ? typePiece.customFields + : []; + const typePieceFieldMap = new Map( + typePieceFields + .filter((field: any) => field && typeof field.name === 'string') + .map((field: any) => [field.name, field]), + ); + // Créer le type de pièce s'il n'existe pas let typePieceEntity = await this.prisma.modelType.findFirst({ where: { @@ -1312,7 +1372,7 @@ export class MachinesService { } // Créer les champs personnalisés pour le type de pièce - for (const customField of typePiece.customFields) { + for (const customField of typePieceFields) { const existingField = await this.prisma.customField.findFirst({ where: { name: customField.name, @@ -1326,7 +1386,6 @@ export class MachinesService { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typePieceId: typePieceEntity.id, }, @@ -1355,17 +1414,18 @@ export class MachinesService { }); if (!existingValue) { - const defaultValue = - typePiece.customFields.find( - (cf: any) => cf.name === customField.name, - )?.defaultValue || ''; - await this.prisma.customFieldValue.create({ - data: { - value: defaultValue, - customFieldId: customField.id, - pieceId: piece.id, - }, - }); + const providedValue = this.extractCustomFieldValue( + typePieceFieldMap.get(customField.name), + ); + if (providedValue !== undefined) { + await this.prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: customField.id, + pieceId: piece.id, + }, + }); + } } } } @@ -1381,6 +1441,15 @@ export class MachinesService { typePiece.customFields && typePiece.customFields.length > 0 ) { + const typePieceFields = Array.isArray(typePiece.customFields) + ? typePiece.customFields + : []; + const typePieceFieldMap = new Map( + typePieceFields + .filter((field: any) => field && typeof field.name === 'string') + .map((field: any) => [field.name, field]), + ); + // Créer le type de pièce s'il n'existe pas let typePieceEntity = await this.prisma.modelType.findFirst({ where: { @@ -1405,7 +1474,7 @@ export class MachinesService { } // Créer les champs personnalisés pour le type de pièce - for (const customField of typePiece.customFields) { + for (const customField of typePieceFields) { const existingField = await this.prisma.customField.findFirst({ where: { name: customField.name, @@ -1419,7 +1488,6 @@ export class MachinesService { name: customField.name, type: customField.type, required: customField.required || false, - defaultValue: customField.defaultValue, options: customField.options || [], typePieceId: typePieceEntity.id, }, @@ -1447,17 +1515,18 @@ export class MachinesService { }); if (!existingValue) { - const defaultValue = - typePiece.customFields.find( - (cf: any) => cf.name === customField.name, - )?.defaultValue || ''; - await this.prisma.customFieldValue.create({ - data: { - value: defaultValue, - customFieldId: customField.id, - pieceId: piece.id, - }, - }); + const providedValue = this.extractCustomFieldValue( + typePieceFieldMap.get(customField.name), + ); + if (providedValue !== undefined) { + await this.prisma.customFieldValue.create({ + data: { + value: providedValue, + customFieldId: customField.id, + pieceId: piece.id, + }, + }); + } } } } diff --git a/src/shared/dto/composant.dto.ts b/src/shared/dto/composant.dto.ts index 87442b6..6601615 100644 --- a/src/shared/dto/composant.dto.ts +++ b/src/shared/dto/composant.dto.ts @@ -26,10 +26,6 @@ export class CreateComposantDto { @IsNumber({}, { message: 'prix must be a valid number' }) prix?: number | null; - @IsOptional() - @IsString() - emplacement?: string; - @IsOptional() @IsString() typeComposantId?: string; @@ -60,10 +56,6 @@ export class UpdateComposantDto { @IsNumber({}, { message: 'prix must be a valid number' }) prix?: number | null; - @IsOptional() - @IsString() - emplacement?: string; - @IsOptional() @IsString() typeComposantId?: string; diff --git a/src/shared/dto/machine.dto.ts b/src/shared/dto/machine.dto.ts index 8a73694..60f2264 100644 --- a/src/shared/dto/machine.dto.ts +++ b/src/shared/dto/machine.dto.ts @@ -41,10 +41,6 @@ export class CreateMachineDto { @IsDecimal() prix?: string; - @IsOptional() - @IsString() - emplacement?: string; - @IsOptional() @IsString() typeMachineId?: string; @@ -79,10 +75,6 @@ export class UpdateMachineDto { @IsDecimal() prix?: string; - @IsOptional() - @IsString() - emplacement?: string; - @IsOptional() @IsString() typeMachineId?: string; diff --git a/src/shared/dto/piece.dto.ts b/src/shared/dto/piece.dto.ts index eb49600..8a9b372 100644 --- a/src/shared/dto/piece.dto.ts +++ b/src/shared/dto/piece.dto.ts @@ -26,10 +26,6 @@ export class CreatePieceDto { @IsNumber({}, { message: 'prix must be a valid number' }) prix?: number | null; - @IsOptional() - @IsString() - emplacement?: string; - @IsOptional() @IsString() typePieceId?: string; @@ -60,10 +56,6 @@ export class UpdatePieceDto { @IsNumber({}, { message: 'prix must be a valid number' }) prix?: number | null; - @IsOptional() - @IsString() - emplacement?: string; - @IsOptional() @IsString() typePieceId?: string; diff --git a/src/shared/dto/type.dto.ts b/src/shared/dto/type.dto.ts index ebbe017..994e82d 100644 --- a/src/shared/dto/type.dto.ts +++ b/src/shared/dto/type.dto.ts @@ -29,10 +29,6 @@ export class CreateCustomFieldDto { @IsBoolean() required?: boolean; - @IsOptional() - @IsString() - defaultValue?: string; - @IsOptional() @IsArray() options?: string[]; // Pour les champs de type SELECT @@ -51,10 +47,6 @@ export class UpdateCustomFieldDto { @IsBoolean() required?: boolean; - @IsOptional() - @IsString() - defaultValue?: string; - @IsOptional() @IsArray() options?: string[]; diff --git a/src/types/types.service.ts b/src/types/types.service.ts index 9315d95..95a6be1 100644 --- a/src/types/types.service.ts +++ b/src/types/types.service.ts @@ -14,6 +14,14 @@ import { UpdatePieceModelDto, } from '../shared/dto/type.dto'; +const CUSTOM_FIELD_SELECT = { + id: true, + name: true, + type: true, + required: true, + options: true, +} as const; + @Injectable() export class TypesService { constructor(private prisma: PrismaService) {} @@ -63,7 +71,6 @@ export class TypesService { name: field.name, type: field.type, required: field.required || false, - defaultValue: field.defaultValue, options: field.options, })), } @@ -100,7 +107,7 @@ export class TypesService { : undefined, }, include: { - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, componentRequirements: { include: { typeComposant: true, @@ -119,7 +126,7 @@ export class TypesService { return this.prisma.typeMachine.findMany({ include: { machines: true, - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, componentRequirements: { include: { typeComposant: true, @@ -139,7 +146,7 @@ export class TypesService { where: { id }, include: { machines: true, - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, componentRequirements: { include: { typeComposant: true, @@ -179,7 +186,6 @@ export class TypesService { name: field.name, type: field.type, required: field.required || false, - defaultValue: field.defaultValue, options: field.options, typeMachineId: id, })), @@ -233,7 +239,7 @@ export class TypesService { where: { id }, data: typeData, include: { - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, componentRequirements: { include: { typeComposant: true, @@ -292,14 +298,13 @@ export class TypesService { name: field.name, type: field.type, required: field.required || false, - defaultValue: field.defaultValue, options: field.options, })), } : undefined, }, include: { - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, }, }); } @@ -309,7 +314,7 @@ export class TypesService { where: { category: ModelCategory.COMPONENT }, include: { composants: true, - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, models: true, }, }); @@ -323,7 +328,7 @@ export class TypesService { }, include: { composants: true, - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, models: true, }, }); @@ -346,7 +351,6 @@ export class TypesService { name: field.name, type: field.type, required: field.required || false, - defaultValue: field.defaultValue, options: field.options, typeComposantId: id, })), @@ -367,7 +371,7 @@ export class TypesService { where: { id }, data, include: { - customFields: true, + customFields: { select: CUSTOM_FIELD_SELECT }, }, }); } @@ -419,14 +423,13 @@ export class TypesService { name: field.name, type: field.type, required: field.required || false, - defaultValue: field.defaultValue, options: field.options, })), } : undefined, }, include: { - pieceCustomFields: true, + pieceCustomFields: { select: CUSTOM_FIELD_SELECT }, pieceModels: true, pieceRequirements: true, pieces: true, @@ -440,7 +443,7 @@ export class TypesService { const items = await this.prisma.modelType.findMany({ where: { category: ModelCategory.PIECE }, include: { - pieceCustomFields: true, + pieceCustomFields: { select: CUSTOM_FIELD_SELECT }, pieceModels: true, pieceRequirements: true, pieces: true, @@ -455,7 +458,7 @@ export class TypesService { const item = await this.prisma.modelType.findFirst({ where: { id, category: ModelCategory.PIECE }, include: { - pieceCustomFields: true, + pieceCustomFields: { select: CUSTOM_FIELD_SELECT }, pieceModels: true, pieceRequirements: true, pieces: true, @@ -479,7 +482,6 @@ export class TypesService { name: field.name, type: field.type, required: field.required || false, - defaultValue: field.defaultValue, options: field.options, typePieceId: id, })), @@ -500,7 +502,7 @@ export class TypesService { where: { id }, data: updatePayload, include: { - pieceCustomFields: true, + pieceCustomFields: { select: CUSTOM_FIELD_SELECT }, pieceModels: true, pieceRequirements: true, pieces: true, diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index 6085c30..4e9ad17 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.ts @@ -75,7 +75,6 @@ type MachineRecord = { reference: Nullable; constructeurId: Nullable; prix: Nullable; - emplacement: Nullable; siteId: string; typeMachineId: Nullable; createdAt: Date; @@ -87,7 +86,6 @@ type ComposantRecord = { name: string; reference: Nullable; prix: Nullable; - emplacement: Nullable; machineId: Nullable; parentComposantId: Nullable; typeComposantId: Nullable; @@ -103,7 +101,6 @@ type PieceRecord = { name: string; reference: Nullable; prix: Nullable; - emplacement: Nullable; machineId: Nullable; composantId: Nullable; typePieceId: Nullable; @@ -119,7 +116,6 @@ type CustomFieldRecord = { name: string; type: string; required: boolean; - defaultValue: Nullable; options: string[]; typeMachineId: Nullable; typeComposantId: Nullable; @@ -258,7 +254,6 @@ class InMemoryPrismaService { name: field.name, type: field.type, required: field.required ?? false, - defaultValue: field.defaultValue ?? null, options: field.options ?? [], typeMachineId: null, typeComposantId: record.id, @@ -319,7 +314,6 @@ class InMemoryPrismaService { name: field.name, type: field.type, required: field.required ?? false, - defaultValue: field.defaultValue ?? null, options: field.options ?? [], typeMachineId: null, typeComposantId: null, @@ -380,7 +374,6 @@ class InMemoryPrismaService { name: field.name, type: field.type, required: field.required ?? false, - defaultValue: field.defaultValue ?? null, options: field.options ?? [], typeMachineId: record.id, typeComposantId: null, @@ -485,7 +478,6 @@ class InMemoryPrismaService { reference: data.reference ?? null, constructeurId: data.constructeurId ?? null, prix: data.prix ?? null, - emplacement: data.emplacement ?? null, siteId: data.siteId, typeMachineId: data.typeMachineId ?? null, createdAt: now, @@ -530,7 +522,6 @@ class InMemoryPrismaService { name: data.name, reference: data.reference ?? null, prix: data.prix ?? null, - emplacement: data.emplacement ?? null, machineId: data.machineId ?? null, parentComposantId: data.parentComposantId ?? null, typeComposantId: data.typeComposantId ?? null, @@ -568,7 +559,6 @@ class InMemoryPrismaService { name: data.name, reference: data.reference ?? null, prix: data.prix ?? null, - emplacement: data.emplacement ?? null, machineId: data.machineId ?? null, composantId: data.composantId ?? null, typePieceId: data.typePieceId ?? null, @@ -604,7 +594,6 @@ class InMemoryPrismaService { name: data.name, type: data.type, required: data.required ?? false, - defaultValue: data.defaultValue ?? null, options: data.options ?? [], typeMachineId: data.typeMachineId ?? null, typeComposantId: data.typeComposantId ?? null, @@ -1100,7 +1089,6 @@ describe('Inventory flow (e2e)', () => { name: 'Puissance nominale', type: 'text', required: true, - defaultValue: '5 kW', }, ], }); @@ -1118,7 +1106,6 @@ describe('Inventory flow (e2e)', () => { { name: 'Référence fournisseur', type: 'text', - defaultValue: 'STD-001', }, ], }); @@ -1174,7 +1161,7 @@ describe('Inventory flow (e2e)', () => { name: 'Puissance nominale', type: 'text', required: true, - defaultValue: '7 kW', + value: '7 kW', }, ], }, @@ -1190,7 +1177,7 @@ describe('Inventory flow (e2e)', () => { { name: 'Référence fournisseur', type: 'text', - defaultValue: 'STD-002', + value: 'STD-002', }, ], },