product
This commit is contained in:
@@ -13,6 +13,7 @@ import { AuthModule } from '../auth/auth.module';
|
|||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { UtilsModule } from '../utils/utils.module';
|
import { UtilsModule } from '../utils/utils.module';
|
||||||
import { Favorite } from './entities/favorite.entity';
|
import { Favorite } from './entities/favorite.entity';
|
||||||
|
import { FavoriteRepository } from './repositories/favorite.repository';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -24,7 +25,7 @@ import { Favorite } from './entities/favorite.entity';
|
|||||||
ShopsModule
|
ShopsModule
|
||||||
],
|
],
|
||||||
controllers: [FoodController, CategoryController],
|
controllers: [FoodController, CategoryController],
|
||||||
providers: [ProductService, CategoryService, ProductRepository, CategoryRepository],
|
providers: [ProductService, CategoryService, ProductRepository, CategoryRepository,FavoriteRepository],
|
||||||
exports: [ProductRepository, CategoryRepository, ProductService],
|
exports: [ProductRepository, CategoryRepository, FavoriteRepository, ProductService],
|
||||||
})
|
})
|
||||||
export class ProductModule {}
|
export class ProductModule {}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { Variant } from '../entities/variant.entity';
|
|||||||
import { ShopService } from 'src/modules/shops/providers/shops.service';
|
import { ShopService } from 'src/modules/shops/providers/shops.service';
|
||||||
import { CategoryService } from './category.service';
|
import { CategoryService } from './category.service';
|
||||||
import { User } from 'src/modules/users/entities/user.entity';
|
import { User } from 'src/modules/users/entities/user.entity';
|
||||||
|
import { FavoriteRepository } from '../repositories/favorite.repository';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProductService {
|
export class ProductService {
|
||||||
@@ -20,6 +21,7 @@ export class ProductService {
|
|||||||
private readonly categoryRepository: CategoryRepository,
|
private readonly categoryRepository: CategoryRepository,
|
||||||
private readonly categoryService: CategoryService,
|
private readonly categoryService: CategoryService,
|
||||||
private readonly shopService: ShopService,
|
private readonly shopService: ShopService,
|
||||||
|
private readonly favoriteRepository: FavoriteRepository,
|
||||||
private readonly em: EntityManager,
|
private readonly em: EntityManager,
|
||||||
) { }
|
) { }
|
||||||
// TODO : Messages must be in persian
|
// TODO : Messages must be in persian
|
||||||
@@ -223,7 +225,11 @@ export class ProductService {
|
|||||||
|
|
||||||
|
|
||||||
async getMyFavorites(userId: string, shopId: string) {
|
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
|
* 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