update
This commit is contained in:
@@ -71,8 +71,8 @@ export class ProductService {
|
||||
return product;
|
||||
}
|
||||
|
||||
findAll(restId: string, dto: FindProductsDto) {
|
||||
return this.productRepository.findAllPaginated(restId, dto);
|
||||
findAll(shopId: string, dto: FindProductsDto) {
|
||||
return this.productRepository.findAllPaginated(shopId, dto);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,14 +113,15 @@ export class ProductService {
|
||||
});
|
||||
}
|
||||
|
||||
async update(restId: string, productId: string, dto: Partial<CreateProductDto>): Promise<Product> {
|
||||
|
||||
async update(shopId: string, productId: string, dto: Partial<CreateProductDto>): Promise<Product> {
|
||||
const { categoryId, variants, ...rest } = dto;
|
||||
|
||||
const product = await this.findOrFail(productId)
|
||||
|
||||
// attach new categories if provided (adds, does not attempt to preserve/remove existing ones)
|
||||
if (categoryId) {
|
||||
const category = await this.categoryRepository.findOne({ id: categoryId, shop: { id: restId } });
|
||||
const category = await this.categoryRepository.findOne({ id: categoryId, shop: { id: shopId } });
|
||||
|
||||
if (!category) {
|
||||
throw new NotFoundException(CategoryMessage.NOT_FOUND);
|
||||
@@ -178,6 +179,7 @@ export class ProductService {
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
|
||||
async remove(shopId: string, id: string): Promise<void> {
|
||||
const product = await this.findOrFail(id)
|
||||
@@ -207,8 +209,8 @@ export class ProductService {
|
||||
}
|
||||
|
||||
|
||||
async getMyFavorites(userId: string, restId: string) {
|
||||
return this.em.find(Favorite, { user: userId, product: { shop: { id: restId } } }, { populate: ['product'] });
|
||||
async getMyFavorites(userId: string, shopId: string) {
|
||||
return this.em.find(Favorite, { user: userId, product: { shop: { id: shopId } } }, { populate: ['product'] });
|
||||
}
|
||||
/**
|
||||
* Helper
|
||||
|
||||
Reference in New Issue
Block a user