feat(inventory): add origin field to InventoryItem and update related DTOs and services
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 } });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user