feat(inventory): add origin field to InventoryItem and update related DTOs and services

This commit is contained in:
Nils-Johan Gynther
2026-04-19 15:11:35 +02:00
parent 3b0208b5b4
commit 976a72612e
14 changed files with 210 additions and 23 deletions
@@ -125,11 +125,20 @@ export class ProductsController {
return this.aiService.suggestCategory(product.canonicalName ?? product.name, categories);
}
@Roles('admin')
@Post()
create(@Body() body: CreateProductDto) {
return this.productsService.create(body);
}
@Post('pending')
createPending(
@Body() body: CreateProductDto,
@Request() req: { user: { id: number } },
) {
return this.productsService.createPending(body, req.user.id);
}
@Roles('admin')
@Post('merge')
merge(@Body() body: MergeProductsDto) {
+31
View File
@@ -427,6 +427,37 @@ export class ProductsService {
});
}
async createPending(data: CreateProductDto, userId: number) {
const name = data.name.trim();
const normalizedName = normalizeName(name);
const existing = await this.prisma.product.findUnique({
where: { normalizedName },
});
if (existing) {
// Om produkten redan finns (aktiv), returnera den direkt
if (existing.isActive && existing.status === 'active') {
return existing;
}
// Om det redan finns ett pending-förslag, returnera det
if (existing.status === 'pending') {
return existing;
}
}
return this.prisma.product.create({
data: {
name,
normalizedName,
canonicalName: name,
isActive: false,
status: 'pending',
ownerId: userId,
},
});
}
setStatus(id: number, status: string) {
return this.prisma.product.update({ where: { id }, data: { status } });
}