product
This commit is contained in:
@@ -13,6 +13,7 @@ import { AuthModule } from '../auth/auth.module';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { UtilsModule } from '../utils/utils.module';
|
||||
import { Favorite } from './entities/favorite.entity';
|
||||
import { FavoriteRepository } from './repositories/favorite.repository';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -24,7 +25,7 @@ import { Favorite } from './entities/favorite.entity';
|
||||
ShopsModule
|
||||
],
|
||||
controllers: [FoodController, CategoryController],
|
||||
providers: [ProductService, CategoryService, ProductRepository, CategoryRepository],
|
||||
exports: [ProductRepository, CategoryRepository, ProductService],
|
||||
providers: [ProductService, CategoryService, ProductRepository, CategoryRepository,FavoriteRepository],
|
||||
exports: [ProductRepository, CategoryRepository, FavoriteRepository, ProductService],
|
||||
})
|
||||
export class ProductModule {}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Variant } from '../entities/variant.entity';
|
||||
import { ShopService } from 'src/modules/shops/providers/shops.service';
|
||||
import { CategoryService } from './category.service';
|
||||
import { User } from 'src/modules/users/entities/user.entity';
|
||||
import { FavoriteRepository } from '../repositories/favorite.repository';
|
||||
|
||||
@Injectable()
|
||||
export class ProductService {
|
||||
@@ -20,6 +21,7 @@ export class ProductService {
|
||||
private readonly categoryRepository: CategoryRepository,
|
||||
private readonly categoryService: CategoryService,
|
||||
private readonly shopService: ShopService,
|
||||
private readonly favoriteRepository: FavoriteRepository,
|
||||
private readonly em: EntityManager,
|
||||
) { }
|
||||
// TODO : Messages must be in persian
|
||||
@@ -223,7 +225,11 @@ export class ProductService {
|
||||
|
||||
|
||||
async getMyFavorites(userId: string, shopId: string) {
|
||||
return this.em.find(Favorite, { user: { id: userId }, product: { shop: { id: shopId } } }, { populate: ['product'] });
|
||||
return this.favoriteRepository.find({
|
||||
user: { id: userId },
|
||||
product: { shop: { id: shopId } }
|
||||
},
|
||||
{ populate: ['product'] });
|
||||
}
|
||||
/**
|
||||
* Helper
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { Favorite } from '../entities/favorite.entity';
|
||||
|
||||
@Injectable()
|
||||
export class FavoriteRepository extends EntityRepository<Favorite> {
|
||||
constructor(readonly em: EntityManager) {
|
||||
super(em, Favorite);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user