linter
This commit is contained in:
@@ -5,7 +5,9 @@ describe('ModelTypeMapper', () => {
|
||||
const dto = {
|
||||
name: 'Comp',
|
||||
description: 'Desc',
|
||||
customFields: [{ name: 'Field', type: 'string', required: false, options: [] }],
|
||||
customFields: [
|
||||
{ name: 'Field', type: 'string', required: false, options: [] },
|
||||
],
|
||||
} as any;
|
||||
|
||||
const input = ModelTypeMapper.toComponentCreateInput(dto, 'code');
|
||||
|
||||
@@ -96,7 +96,9 @@ export class ModelTypeMapper {
|
||||
};
|
||||
}
|
||||
|
||||
static toPieceUpdateInput(dto: UpdateTypePieceDto): Prisma.ModelTypeUpdateInput {
|
||||
static toPieceUpdateInput(
|
||||
dto: UpdateTypePieceDto,
|
||||
): Prisma.ModelTypeUpdateInput {
|
||||
const { customFields, description, name } = dto;
|
||||
const data: Prisma.ModelTypeUpdateInput = {};
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ describe('TypeMachineMapper', () => {
|
||||
});
|
||||
|
||||
it('should map custom field inputs for create many', () => {
|
||||
const result = TypeMachineMapper.mapCustomFieldInputs(baseDto.customFields as any);
|
||||
const result = TypeMachineMapper.mapCustomFieldInputs(
|
||||
baseDto.customFields as any,
|
||||
);
|
||||
expect(result).toEqual([
|
||||
{
|
||||
name: 'Field',
|
||||
|
||||
@@ -40,12 +40,16 @@ export class TypeMachineMapper {
|
||||
return {
|
||||
...data,
|
||||
customFields: this.mapCustomFields(customFields),
|
||||
componentRequirements: this.mapComponentRequirements(componentRequirements),
|
||||
componentRequirements: this.mapComponentRequirements(
|
||||
componentRequirements,
|
||||
),
|
||||
pieceRequirements: this.mapPieceRequirements(pieceRequirements),
|
||||
};
|
||||
}
|
||||
|
||||
static toUpdateData(dto: UpdateTypeMachineDto): Prisma.TypeMachineUpdateInput {
|
||||
static toUpdateData(
|
||||
dto: UpdateTypeMachineDto,
|
||||
): Prisma.TypeMachineUpdateInput {
|
||||
const { customFields, componentRequirements, pieceRequirements, ...data } =
|
||||
dto;
|
||||
|
||||
@@ -83,9 +87,7 @@ export class TypeMachineMapper {
|
||||
};
|
||||
}
|
||||
|
||||
static mapCustomFieldInputs(
|
||||
fields?: CreateTypeMachineDto['customFields'],
|
||||
) {
|
||||
static mapCustomFieldInputs(fields?: CreateTypeMachineDto['customFields']) {
|
||||
if (!fields || fields.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@@ -100,7 +102,9 @@ export class TypeMachineMapper {
|
||||
|
||||
static mapComponentRequirements(
|
||||
requirements?: RequirementDto[] | null,
|
||||
): Prisma.TypeMachineComponentRequirementCreateNestedManyWithoutTypeMachineInput | undefined {
|
||||
):
|
||||
| Prisma.TypeMachineComponentRequirementCreateNestedManyWithoutTypeMachineInput
|
||||
| undefined {
|
||||
if (!requirements || requirements.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -125,9 +129,7 @@ export class TypeMachineMapper {
|
||||
};
|
||||
}
|
||||
|
||||
static mapComponentRequirementInputs(
|
||||
requirements?: RequirementDto[] | null,
|
||||
) {
|
||||
static mapComponentRequirementInputs(requirements?: RequirementDto[] | null) {
|
||||
if (!requirements || requirements.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@@ -144,7 +146,9 @@ export class TypeMachineMapper {
|
||||
|
||||
static mapPieceRequirements(
|
||||
requirements?: RequirementDto[] | null,
|
||||
): Prisma.TypeMachinePieceRequirementCreateNestedManyWithoutTypeMachineInput | undefined {
|
||||
):
|
||||
| Prisma.TypeMachinePieceRequirementCreateNestedManyWithoutTypeMachineInput
|
||||
| undefined {
|
||||
if (!requirements || requirements.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -169,9 +173,7 @@ export class TypeMachineMapper {
|
||||
};
|
||||
}
|
||||
|
||||
static mapPieceRequirementInputs(
|
||||
requirements?: RequirementDto[] | null,
|
||||
) {
|
||||
static mapPieceRequirementInputs(requirements?: RequirementDto[] | null) {
|
||||
if (!requirements || requirements.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ export class ModelTypesRepository {
|
||||
let candidate = base;
|
||||
let suffix = 1;
|
||||
|
||||
while (await this.client.modelType.findUnique({ where: { code: candidate } })) {
|
||||
while (
|
||||
await this.client.modelType.findUnique({ where: { code: candidate } })
|
||||
) {
|
||||
candidate = `${base}-${suffix++}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,9 @@ describe('TypeMachinesRepository', () => {
|
||||
},
|
||||
]);
|
||||
|
||||
expect(prismaMock.typeMachinePieceRequirement.createMany).toHaveBeenCalledWith({
|
||||
expect(
|
||||
prismaMock.typeMachinePieceRequirement.createMany,
|
||||
).toHaveBeenCalledWith({
|
||||
data: [
|
||||
{
|
||||
label: 'Piece',
|
||||
|
||||
@@ -231,7 +231,7 @@ export class MachinesService {
|
||||
.map((selection) => selection.pieceModelId)
|
||||
.filter(Boolean),
|
||||
),
|
||||
) as string[];
|
||||
);
|
||||
const pieceModels = pieceModelIds.length
|
||||
? await this.prisma.pieceModel.findMany({
|
||||
where: { id: { in: pieceModelIds } },
|
||||
@@ -286,7 +286,6 @@ export class MachinesService {
|
||||
`Le groupe de pièces "${requirement.label || requirement.typePiece?.name || requirement.id}" ne peut pas dépasser ${max} sélection(s).`,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (const selection of componentSelections) {
|
||||
@@ -481,10 +480,7 @@ export class MachinesService {
|
||||
}
|
||||
|
||||
private extractCustomFieldValue(field: any): string | undefined {
|
||||
if (
|
||||
field &&
|
||||
Object.prototype.hasOwnProperty.call(field, 'value')
|
||||
) {
|
||||
if (field && Object.prototype.hasOwnProperty.call(field, 'value')) {
|
||||
const rawValue = field.value;
|
||||
return rawValue === undefined || rawValue === null
|
||||
? ''
|
||||
@@ -545,9 +541,7 @@ export class MachinesService {
|
||||
model?: any,
|
||||
): any {
|
||||
if (!model) {
|
||||
throw new Error(
|
||||
`Modèle de pièce introuvable: ${selection.pieceModelId}`,
|
||||
);
|
||||
throw new Error(`Modèle de pièce introuvable: ${selection.pieceModelId}`);
|
||||
}
|
||||
|
||||
const baseDefinition = model.structure ?? {};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateModelTypeDto } from './create-model-type.dto';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
export class UpdateModelTypeDto extends PartialType(CreateModelTypeDto) {}
|
||||
|
||||
@@ -108,7 +108,9 @@ export class ModelTypeService {
|
||||
data: {
|
||||
...dto,
|
||||
description:
|
||||
dto.description === undefined ? undefined : dto.description ?? null,
|
||||
dto.description === undefined
|
||||
? undefined
|
||||
: (dto.description ?? null),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PieceModelsRepository } from '../../common/repositories/piece-models.repository';
|
||||
import { CreatePieceModelDto, UpdatePieceModelDto } from '../../shared/dto/type.dto';
|
||||
import {
|
||||
CreatePieceModelDto,
|
||||
UpdatePieceModelDto,
|
||||
} from '../../shared/dto/type.dto';
|
||||
|
||||
const PIECE_MODEL_INCLUDE = {
|
||||
typePiece: true,
|
||||
|
||||
@@ -38,7 +38,11 @@ export class TypeComponentService {
|
||||
}
|
||||
|
||||
const data = ModelTypeMapper.toComponentUpdateInput(dto);
|
||||
return this.repository.updateComponentType(id, data, COMPONENT_TYPE_INCLUDE);
|
||||
return this.repository.updateComponentType(
|
||||
id,
|
||||
data,
|
||||
COMPONENT_TYPE_INCLUDE,
|
||||
);
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
|
||||
@@ -17,7 +17,10 @@ export class TypePieceService {
|
||||
const code = await this.repository.generateUniqueCode(dto.name);
|
||||
const data = ModelTypeMapper.toPieceCreateInput(dto, code);
|
||||
|
||||
const created = await this.repository.createPieceType(data, PIECE_TYPE_INCLUDE);
|
||||
const created = await this.repository.createPieceType(
|
||||
data,
|
||||
PIECE_TYPE_INCLUDE,
|
||||
);
|
||||
return ModelTypeMapper.mapPieceModelType(created);
|
||||
}
|
||||
|
||||
@@ -34,7 +37,9 @@ export class TypePieceService {
|
||||
async update(id: string, dto: UpdateTypePieceDto) {
|
||||
if (dto.customFields !== undefined) {
|
||||
await this.repository.deletePieceTypeCustomFields(id);
|
||||
const fields = ModelTypeMapper.mapPieceCustomFieldInputs(dto.customFields);
|
||||
const fields = ModelTypeMapper.mapPieceCustomFieldInputs(
|
||||
dto.customFields,
|
||||
);
|
||||
await this.repository.createPieceTypeCustomFields(id, fields);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user