feat(categories): implement category management with hierarchical structure and update product association

This commit is contained in:
Nils-Johan Gynther
2026-04-17 21:16:58 +02:00
parent a9e83544c5
commit cc8be88462
11 changed files with 286 additions and 42 deletions
@@ -1,4 +1,4 @@
import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
import { IsNotEmpty, IsNumber, IsOptional, IsString, MaxLength } from 'class-validator';
export class UpdateProductDto {
@IsOptional()
@@ -26,4 +26,8 @@ export class UpdateProductDto {
@IsString()
@MaxLength(191)
brand?: string;
@IsOptional()
@IsNumber()
categoryId?: number | null;
}
+6
View File
@@ -21,6 +21,7 @@ export class ProductsService {
include: {
tags: { include: { tag: true } },
nutrition: true,
categoryRef: { include: { parent: { include: { parent: true } } } },
},
orderBy: { name: 'asc' },
});
@@ -114,6 +115,7 @@ export class ProductsService {
category?: string | null;
subcategory?: string | null;
brand?: string | null;
categoryId?: number | null;
} = {};
if (typeof data.name === 'string') {
@@ -160,6 +162,10 @@ export class ProductsService {
updateData.brand = data.brand.trim() || null;
}
if ('categoryId' in data) {
updateData.categoryId = data.categoryId ?? null;
}
return this.prisma.product.update({
where: { id },
data: updateData,