feat: Add Model gestion for piece and component
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import {
|
||||
CreateCustomFieldValueDto,
|
||||
@@ -11,7 +15,9 @@ export class CustomFieldsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
// Créer une valeur de champ personnalisé
|
||||
async createCustomFieldValue(createCustomFieldValueDto: CreateCustomFieldValueDto) {
|
||||
async createCustomFieldValue(
|
||||
createCustomFieldValueDto: CreateCustomFieldValueDto,
|
||||
) {
|
||||
return this.prisma.customFieldValue.create({
|
||||
data: createCustomFieldValueDto,
|
||||
include: {
|
||||
@@ -30,11 +36,16 @@ export class CustomFieldsService {
|
||||
case CustomFieldEntityType.PIECE:
|
||||
return 'pieceId' as const;
|
||||
default:
|
||||
throw new BadRequestException('Type d\'entité de champ personnalisé invalide.');
|
||||
throw new BadRequestException(
|
||||
"Type d'entité de champ personnalisé invalide.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private async resolveEntityContext(entityType: CustomFieldEntityType, entityId: string) {
|
||||
private async resolveEntityContext(
|
||||
entityType: CustomFieldEntityType,
|
||||
entityId: string,
|
||||
) {
|
||||
switch (entityType) {
|
||||
case CustomFieldEntityType.MACHINE: {
|
||||
const machine = await this.prisma.machine.findUnique({
|
||||
@@ -103,7 +114,9 @@ export class CustomFieldsService {
|
||||
};
|
||||
}
|
||||
default:
|
||||
throw new BadRequestException('Type d\'entité de champ personnalisé invalide.');
|
||||
throw new BadRequestException(
|
||||
"Type d'entité de champ personnalisé invalide.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +148,10 @@ export class CustomFieldsService {
|
||||
}
|
||||
|
||||
// Mettre à jour une valeur de champ personnalisé
|
||||
async updateCustomFieldValue(id: string, updateCustomFieldValueDto: UpdateCustomFieldValueDto) {
|
||||
async updateCustomFieldValue(
|
||||
id: string,
|
||||
updateCustomFieldValueDto: UpdateCustomFieldValueDto,
|
||||
) {
|
||||
return this.prisma.customFieldValue.update({
|
||||
where: { id },
|
||||
data: updateCustomFieldValueDto,
|
||||
@@ -159,10 +175,8 @@ export class CustomFieldsService {
|
||||
entityId: string,
|
||||
value: string,
|
||||
) {
|
||||
const { typeId, customFieldTypeField, valueKey } = await this.resolveEntityContext(
|
||||
entityType,
|
||||
entityId,
|
||||
);
|
||||
const { typeId, customFieldTypeField, valueKey } =
|
||||
await this.resolveEntityContext(entityType, entityId);
|
||||
|
||||
const allowedCustomField = await this.prisma.customField.findFirst({
|
||||
where: {
|
||||
@@ -173,7 +187,7 @@ export class CustomFieldsService {
|
||||
|
||||
if (!allowedCustomField) {
|
||||
throw new BadRequestException(
|
||||
'Le champ personnalisé n\'est pas autorisé pour cette entité.',
|
||||
"Le champ personnalisé n'est pas autorisé pour cette entité.",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user