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