feat(products): include ownerId in product creation and enforce its requirement
This commit is contained in:
@@ -128,8 +128,8 @@ export class ProductsController {
|
||||
|
||||
@Roles('admin')
|
||||
@Post()
|
||||
create(@Body() body: CreateProductDto) {
|
||||
return this.productsService.create(body);
|
||||
create(@Body() body: CreateProductDto, @Request() req: { user: { id: number } }) {
|
||||
return this.productsService.create(body, req.user.id);
|
||||
}
|
||||
|
||||
// Tillgänglig för alla inloggade användare — req.user.id injiceras av JWT-guard
|
||||
|
||||
@@ -116,7 +116,7 @@ export class ProductsService {
|
||||
return product;
|
||||
}
|
||||
|
||||
async create(data: CreateProductDto) {
|
||||
async create(data: CreateProductDto, ownerId?: number) {
|
||||
const name = data.name.trim();
|
||||
const normalizedName = normalizeName(name);
|
||||
|
||||
@@ -140,8 +140,13 @@ export class ProductsService {
|
||||
return existing;
|
||||
}
|
||||
|
||||
if (!ownerId) {
|
||||
throw new Error('ownerId är obligatorisk för att skapa en produkt');
|
||||
}
|
||||
|
||||
return this.prisma.product.create({
|
||||
data: {
|
||||
ownerId,
|
||||
name,
|
||||
normalizedName,
|
||||
canonicalName: name,
|
||||
|
||||
Reference in New Issue
Block a user