feat: autoriser la suppression quand seuls les champs personnalisés restent
This commit is contained in:
@@ -138,18 +138,31 @@ export class ComposantsService {
|
||||
`${documentsCount} document${documentsCount > 1 ? 's' : ''}`,
|
||||
);
|
||||
}
|
||||
if (customFieldValuesCount > 0) {
|
||||
blockingReasons.push(
|
||||
`${customFieldValuesCount} valeur${customFieldValuesCount > 1 ? 's' : ''} de champ personnalisé`,
|
||||
|
||||
if (blockingReasons.length > 0) {
|
||||
const messageParts = [
|
||||
`Impossible de supprimer ce composant car il possède encore: ${blockingReasons.join(
|
||||
', ',
|
||||
)}.`,
|
||||
];
|
||||
|
||||
if (customFieldValuesCount > 0) {
|
||||
messageParts.push(
|
||||
`Les ${customFieldValuesCount} valeur${
|
||||
customFieldValuesCount > 1 ? 's' : ''
|
||||
} de champ personnalisé seront supprimées automatiquement une fois ces éléments détachés.`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new ConflictException(
|
||||
`${messageParts.join(' ')} Supprimez ou détachez les éléments indiqués avant de réessayer.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (blockingReasons.length > 0) {
|
||||
throw new ConflictException(
|
||||
`Impossible de supprimer ce composant car il possède encore: ${blockingReasons.join(
|
||||
', ',
|
||||
)}. Supprimez ou détachez ces éléments avant de réessayer.`,
|
||||
);
|
||||
if (customFieldValuesCount > 0) {
|
||||
await this.prisma.customFieldValue.deleteMany({
|
||||
where: { composantId: id },
|
||||
});
|
||||
}
|
||||
|
||||
return this.prisma.composant.delete({
|
||||
|
||||
@@ -162,18 +162,31 @@ export class PiecesService {
|
||||
`${documentsCount} document${documentsCount > 1 ? 's' : ''}`,
|
||||
);
|
||||
}
|
||||
if (customFieldValuesCount > 0) {
|
||||
blockingReasons.push(
|
||||
`${customFieldValuesCount} valeur${customFieldValuesCount > 1 ? 's' : ''} de champ personnalisé`,
|
||||
|
||||
if (blockingReasons.length > 0) {
|
||||
const messageParts = [
|
||||
`Impossible de supprimer cette pièce car elle possède encore: ${blockingReasons.join(
|
||||
', ',
|
||||
)}.`,
|
||||
];
|
||||
|
||||
if (customFieldValuesCount > 0) {
|
||||
messageParts.push(
|
||||
`Les ${customFieldValuesCount} valeur${
|
||||
customFieldValuesCount > 1 ? 's' : ''
|
||||
} de champ personnalisé seront supprimées automatiquement une fois ces éléments détachés.`,
|
||||
);
|
||||
}
|
||||
|
||||
throw new ConflictException(
|
||||
`${messageParts.join(' ')} Supprimez ou détachez les éléments indiqués avant de réessayer.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (blockingReasons.length > 0) {
|
||||
throw new ConflictException(
|
||||
`Impossible de supprimer cette pièce car elle possède encore: ${blockingReasons.join(
|
||||
', ',
|
||||
)}. Supprimez ou détachez ces éléments avant de réessayer.`,
|
||||
);
|
||||
if (customFieldValuesCount > 0) {
|
||||
await this.prisma.customFieldValue.deleteMany({
|
||||
where: { pieceId: id },
|
||||
});
|
||||
}
|
||||
|
||||
return this.prisma.piece.delete({
|
||||
|
||||
Reference in New Issue
Block a user