product
This commit is contained in:
@@ -4,7 +4,7 @@ import { FindProductsDto } from '../dto/find-products.dto';
|
||||
import { ProductRepository } from '../repositories/product.repository';
|
||||
import { CategoryRepository } from '../repositories/category.repository';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RequiredEntityData, FilterQuery } from '@mikro-orm/core';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { Product } from '../entities/product.entity';
|
||||
import { CategoryMessage, ProductMessage } from 'src/common/enums/message.enum';
|
||||
import { Favorite } from '../entities/favorite.entity';
|
||||
@@ -100,15 +100,12 @@ export class ProductService {
|
||||
|
||||
|
||||
async findByShop(slug: string): Promise<Product[]> {
|
||||
const queryFilter: FilterQuery<Product> = {
|
||||
shop: { slug },
|
||||
isActive: true,
|
||||
} as unknown as FilterQuery<Product>;
|
||||
const shop = await this.shopService.findBySlug(slug);
|
||||
|
||||
return this.productRepository.find(queryFilter, {
|
||||
populate: ['category', 'variants'],
|
||||
orderBy: { order: 'asc' }
|
||||
});
|
||||
return this.productRepository.find(
|
||||
{ shop: { id: shop.id }, isActive: true },
|
||||
{ populate: ['category', 'variants'], orderBy: { order: 'asc' } }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,9 +224,10 @@ export class ProductService {
|
||||
async getMyFavorites(userId: string, shopId: string) {
|
||||
return this.favoriteRepository.find({
|
||||
user: { id: userId },
|
||||
product: { shop: { id: shopId } }
|
||||
// product: { shop: { id: shopId } }
|
||||
},
|
||||
{ populate: ['product'] });
|
||||
{ populate: ['product'] }
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Helper
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { Collection, Entity, Enum, Index, OneToMany, Property } from '@mikro-orm/core';
|
||||
import { Collection, Entity, Index, OneToMany, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Delivery } from '../../delivery/entities/delivery.entity';
|
||||
|
||||
import { Product } from 'src/modules/products/entities/product.entity';
|
||||
|
||||
@Entity({ tableName: 'shops' })
|
||||
@Index({ properties: ['isActive'] })
|
||||
@Index({ properties: ['slug', 'isActive'] })
|
||||
export class Shop extends BaseEntity {
|
||||
|
||||
@OneToMany(() => Product, (product) => product.shop)
|
||||
products = new Collection<Product>(this);
|
||||
// --- اطلاعات پایه ---
|
||||
@Property()
|
||||
name!: string;
|
||||
@@ -97,13 +101,13 @@ export class Shop extends BaseEntity {
|
||||
} | null = null;
|
||||
|
||||
|
||||
@Property({unique: true,nullable: true})
|
||||
@Property({ unique: true, nullable: true })
|
||||
subscriptionId?: string;
|
||||
|
||||
@Property({nullable: true})
|
||||
@Property({ nullable: true })
|
||||
subscriptionEndDate?: Date;
|
||||
|
||||
@Property({nullable: true})
|
||||
@Property({ nullable: true })
|
||||
subscriptionStartDate?: Date;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,20 @@ export interface CategoryData {
|
||||
}
|
||||
|
||||
export const categoriesData: CategoryData[] = [
|
||||
{ title: 'پاستا', shopSlug: 'zhivan' },
|
||||
{ title: 'پیتزا ایتالیایی', shopSlug: 'zhivan' },
|
||||
];
|
||||
// سوپرمارکت پروتئین زاگرس
|
||||
{ title: 'گوشت و مرغ', shopSlug: 'boote' },
|
||||
{ title: 'تخم مرغ', shopSlug: 'boote' },
|
||||
{ title: 'لبنیات و پنیر', shopSlug: 'boote' },
|
||||
{ title: 'مکملهای پروتئین', shopSlug: 'boote' },
|
||||
{ title: 'تنقلات پروتئینی', shopSlug: 'boote' },
|
||||
{ title: 'کنسرو و گوشت آماده', shopSlug: 'boote' },
|
||||
{ title: 'ماهی و غذاهای دریایی', shopSlug: 'boote' },
|
||||
// سوپرمارکت پروتئین البرز
|
||||
{ title: 'گوشت و مرغ', shopSlug: 'zhivan' },
|
||||
{ title: 'تخم مرغ', shopSlug: 'zhivan' },
|
||||
{ title: 'لبنیات و پنیر', shopSlug: 'zhivan' },
|
||||
{ title: 'مکملهای پروتئین', shopSlug: 'zhivan' },
|
||||
{ title: 'تنقلات پروتئینی', shopSlug: 'zhivan' },
|
||||
{ title: 'کنسرو و گوشت آماده', shopSlug: 'zhivan' },
|
||||
{ title: 'ماهی و غذاهای دریایی', shopSlug: 'zhivan' },
|
||||
];
|
||||
|
||||
@@ -16,11 +16,23 @@ export interface ProductData {
|
||||
|
||||
export const productsData: ProductData[] = [
|
||||
{
|
||||
title: 'بیف استراگانف .. beef stroganoff ',
|
||||
title: 'بیف استراگانف ژیوان ',
|
||||
desc: 'فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان..veal fillet/ mayonnaise sauce/mushroom/potato/parmesan cheese ',
|
||||
price: 505000,
|
||||
shopSlug: 'zhivan',
|
||||
categoryTitle: 'پاستا',
|
||||
categoryTitle: 'گوشت و مرغ',
|
||||
isActive: true,
|
||||
stock: 0,
|
||||
stockDefault: 0,
|
||||
images: ["https://dmenu.danakcorp.com/uploads/images/product/food_1714292844747.png"],
|
||||
},
|
||||
|
||||
{
|
||||
title: 'بیف استراگانف بوته',
|
||||
desc: 'فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان..veal fillet/ mayonnaise sauce/mushroom/potato/parmesan cheese ',
|
||||
price: 505000,
|
||||
shopSlug: 'boote',
|
||||
categoryTitle: 'گوشت و مرغ',
|
||||
isActive: true,
|
||||
stock: 0,
|
||||
stockDefault: 0,
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface ShopData {
|
||||
subscriptionId: string;
|
||||
}
|
||||
|
||||
export const shopsData: ShopData[] =[
|
||||
export const shopsData: ShopData[] = [
|
||||
{
|
||||
name: 'ژیوان',
|
||||
slug: 'zhivan',
|
||||
@@ -37,7 +37,7 @@ export const shopsData: ShopData[] =[
|
||||
marriageDateScore: '0',
|
||||
referrerScore: '0',
|
||||
},
|
||||
subscriptionId: 'sub_seed_zhivan_001',
|
||||
subscriptionId: 'sub_seed_zhivan_001',
|
||||
},
|
||||
{
|
||||
name: 'بوته',
|
||||
@@ -56,6 +56,6 @@ export const shopsData: ShopData[] =[
|
||||
marriageDateScore: '0',
|
||||
referrerScore: '0',
|
||||
},
|
||||
subscriptionId: 'sub_seed_boote_001',
|
||||
subscriptionId: 'sub_seed_boote_001',
|
||||
},
|
||||
]
|
||||
Reference in New Issue
Block a user