feat(categories): implement category management with hierarchical structure and update product association
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user