fix
This commit is contained in:
@@ -16,7 +16,7 @@ export class ProductService {
|
||||
constructor(
|
||||
private readonly productRepository: ProductRepository,
|
||||
private readonly categoryRepository: CategoryRepository,
|
||||
private readonly shopService: ShopService,
|
||||
private readonly shopService: ShopService,
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
|
||||
@@ -42,8 +42,7 @@ export class ProductService {
|
||||
// map single-title/content DTO to localized fields
|
||||
title: rest.title,
|
||||
attribute: rest.attribute,
|
||||
// numeric/array fields
|
||||
price: rest.price ?? 0,
|
||||
|
||||
images: rest.images ?? undefined,
|
||||
shop: shop,
|
||||
category: category,
|
||||
@@ -57,7 +56,6 @@ export class ProductService {
|
||||
const variantRecord = em.create(Variant, {
|
||||
product,
|
||||
value: variant.value,
|
||||
stock: variant.stock,
|
||||
price: variant.price,
|
||||
})
|
||||
|
||||
@@ -102,7 +100,7 @@ export class ProductService {
|
||||
|
||||
|
||||
async findByShop(slug: string): Promise<Product[]> {
|
||||
const shop = await this.shopService.findOrFailBySlug( slug );
|
||||
const shop = await this.shopService.findOrFailBySlug(slug);
|
||||
|
||||
const queryFilter: FilterQuery<Product> = {
|
||||
shop: { slug },
|
||||
@@ -142,7 +140,7 @@ export class ProductService {
|
||||
const updatedVariantIds = new Set<string>();
|
||||
|
||||
for (const variant of variants) {
|
||||
const { id, value, stock, price } = variant;
|
||||
const { id, value, price } = variant;
|
||||
|
||||
if (id) {
|
||||
// Update existing variant
|
||||
@@ -152,14 +150,13 @@ export class ProductService {
|
||||
}
|
||||
|
||||
// Update the variant fields
|
||||
this.em.assign(existingVariant, { value, stock, price });
|
||||
this.em.assign(existingVariant, { value, price });
|
||||
updatedVariantIds.add(id);
|
||||
} else {
|
||||
// Create new variant
|
||||
const variantRecord = this.em.create(Variant, {
|
||||
product,
|
||||
value,
|
||||
stock,
|
||||
price,
|
||||
});
|
||||
this.em.persist(variantRecord);
|
||||
@@ -182,10 +179,10 @@ export class ProductService {
|
||||
return product;
|
||||
}
|
||||
|
||||
async remove(restId: string, id: string): Promise<void> {
|
||||
async remove(shopId: string, id: string): Promise<void> {
|
||||
const product = await this.findOrFail(id)
|
||||
|
||||
if (product.shop.id !== restId) {
|
||||
if (product.shop.id !== shopId) {
|
||||
throw new BadRequestException("Product doesnt belongs to you")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user