feat: enhance product model with subcategory, brand, tags, and nutrition; update related DTOs and services

This commit is contained in:
Nils-Johan Gynther
2026-04-17 18:11:06 +02:00
parent a05d907608
commit a4ea9be7a1
10 changed files with 517 additions and 33 deletions
+37 -10
View File
@@ -7,6 +7,7 @@ import {
ParseIntPipe,
Patch,
Post,
Put,
Query,
} from '@nestjs/common';
import { CreateProductDto } from './dto/create-product.dto';
@@ -14,25 +15,35 @@ import { UpdateProductDto } from './dto/update-product.dto';
import { ProductsService } from './products.service';
import { MergeProductsDto } from './dto/merge-products.dto';
import { UpdateCanonicalNameDto } from './dto/update-canonical-name.dto';
import { SetTagsDto } from './dto/set-tags.dto';
import { UpsertNutritionDto } from './dto/upsert-nutrition.dto';
@Controller('products')
export class ProductsController {
constructor(private readonly productsService: ProductsService) {}
@Get()
findAll() {
return this.productsService.findAll();
findAll(
@Query('tag') tag?: string,
@Query('subcategory') subcategory?: string,
) {
return this.productsService.findAll({ tag, subcategory });
}
@Get('tags')
findAllTags() {
return this.productsService.findAllTags();
}
@Get('duplicates')
findDuplicates() {
return this.productsService.findDuplicateCandidates();
}
@Get('merge-preview')
@Get('merge-preview')
previewMerge(
@Query('sourceProductId', ParseIntPipe) sourceProductId: number,
@Query('targetProductId', ParseIntPipe) targetProductId: number,
@Query('sourceProductId', ParseIntPipe) sourceProductId: number,
@Query('targetProductId', ParseIntPipe) targetProductId: number,
) {
return this.productsService.previewMerge(sourceProductId, targetProductId);
}
@@ -59,10 +70,26 @@ export class ProductsController {
@Patch(':id/canonical-name')
updateCanonicalName(
@Param('id', ParseIntPipe) id: number,
@Body() body: UpdateCanonicalNameDto,
@Param('id', ParseIntPipe) id: number,
@Body() body: UpdateCanonicalNameDto,
) {
return this.productsService.updateCanonicalName(id, body.canonicalName);
return this.productsService.updateCanonicalName(id, body.canonicalName);
}
@Put(':id/tags')
setTags(
@Param('id', ParseIntPipe) id: number,
@Body() body: SetTagsDto,
) {
return this.productsService.setTags(id, body.tags);
}
@Put(':id/nutrition')
upsertNutrition(
@Param('id', ParseIntPipe) id: number,
@Body() body: UpsertNutritionDto,
) {
return this.productsService.upsertNutrition(id, body);
}
@Patch(':id')