From d855213d6c8599f2f14401647b8693aa8eeb271f Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 12 Feb 2026 10:21:25 +0330 Subject: [PATCH] product --- .../products/providers/product.service.ts | 20 +++++++++---------- src/modules/shops/entities/shop.entity.ts | 14 ++++++++----- src/seeders/data/categories.data.ts | 20 ++++++++++++++++--- src/seeders/data/products.data.ts | 16 +++++++++++++-- src/seeders/data/shops.data.ts | 6 +++--- 5 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/modules/products/providers/product.service.ts b/src/modules/products/providers/product.service.ts index b0ff4ca..cfefa9b 100644 --- a/src/modules/products/providers/product.service.ts +++ b/src/modules/products/providers/product.service.ts @@ -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 { - const queryFilter: FilterQuery = { - shop: { slug }, - isActive: true, - } as unknown as FilterQuery; + 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 diff --git a/src/modules/shops/entities/shop.entity.ts b/src/modules/shops/entities/shop.entity.ts index 247b544..ba8f2dc 100644 --- a/src/modules/shops/entities/shop.entity.ts +++ b/src/modules/shops/entities/shop.entity.ts @@ -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(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; } diff --git a/src/seeders/data/categories.data.ts b/src/seeders/data/categories.data.ts index c6bcc7e..3e81aca 100644 --- a/src/seeders/data/categories.data.ts +++ b/src/seeders/data/categories.data.ts @@ -4,6 +4,20 @@ export interface CategoryData { } export const categoriesData: CategoryData[] = [ - { title: 'پاستا', shopSlug: 'zhivan' }, - { title: 'پیتزا ایتالیایی', shopSlug: 'zhivan' }, -]; \ No newline at end of file + // سوپرمارکت پروتئین زاگرس + { 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' }, +]; diff --git a/src/seeders/data/products.data.ts b/src/seeders/data/products.data.ts index 339260c..5cb8690 100644 --- a/src/seeders/data/products.data.ts +++ b/src/seeders/data/products.data.ts @@ -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, diff --git a/src/seeders/data/shops.data.ts b/src/seeders/data/shops.data.ts index f3ccf94..b83e766 100644 --- a/src/seeders/data/shops.data.ts +++ b/src/seeders/data/shops.data.ts @@ -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', }, ] \ No newline at end of file