update seeder
This commit is contained in:
@@ -9,15 +9,15 @@ import { ShopId } from 'src/common/decorators/shop-id.decorator';
|
||||
import { SetAllCartParmsDto } from '../dto/set-all-cart-params.dto';
|
||||
import { API_HEADER_SLUG } from 'src/common/constants/index';
|
||||
|
||||
@Controller('public/cart')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('cart')
|
||||
@Controller('public/cart')
|
||||
export class CartController {
|
||||
constructor(private readonly cartService: CartService) { }
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get cart for current user and shop' })
|
||||
@ApiOperation({ summary: 'Get or Create cart for current user and shop' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
async findOne(@UserId() userId: string, @ShopId() shopId: string) {
|
||||
return this.cartService.getOrCreateCart(userId, shopId);
|
||||
|
||||
@@ -1,42 +1,91 @@
|
||||
export interface ProductData {
|
||||
title: string;
|
||||
desc: string;
|
||||
price: number;
|
||||
shopSlug: string;
|
||||
categoryTitle: string;
|
||||
isActive: boolean;
|
||||
stock: number;
|
||||
stockDefault: number;
|
||||
images: string[];
|
||||
content?: string[];
|
||||
discount?: number;
|
||||
score?: number;
|
||||
isSpecialOffer?: boolean;
|
||||
varrinats: { price: number, value: string | null }[]
|
||||
attribute?: null | string
|
||||
}
|
||||
|
||||
export const productsData: ProductData[] = [
|
||||
{
|
||||
title: 'بیف استراگانف ژیوان ',
|
||||
title: 'محصول یک',
|
||||
desc: 'فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان..veal fillet/ mayonnaise sauce/mushroom/potato/parmesan cheese ',
|
||||
price: 505000,
|
||||
shopSlug: 'zhivan',
|
||||
categoryTitle: 'گوشت و مرغ',
|
||||
isActive: true,
|
||||
stock: 0,
|
||||
stockDefault: 0,
|
||||
attribute: 'اسم تنوع',
|
||||
images: ["https://dmenu.danakcorp.com/uploads/images/product/food_1714292844747.png"],
|
||||
varrinats: [
|
||||
{
|
||||
price: 15000, value: 'تنوع یک'
|
||||
},
|
||||
{
|
||||
price: 25000, value: 'تنوع دوم'
|
||||
},
|
||||
{
|
||||
price: 35000, value: 'تنوع سوم'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'محصول دوم',
|
||||
desc: 'فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان..veal fillet/ mayonnaise sauce/mushroom/potato/parmesan cheese ',
|
||||
shopSlug: 'zhivan',
|
||||
categoryTitle: 'گوشت و مرغ',
|
||||
isActive: true,
|
||||
stockDefault: 0,
|
||||
attribute: 'اسم تنوع',
|
||||
images: ["https://dmenu.danakcorp.com/uploads/images/product/food_1714292844747.png"],
|
||||
varrinats: [
|
||||
{
|
||||
price: 15000, value: 'تنوع یک'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
title: 'بیف استراگانف بوته',
|
||||
desc: 'فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان..veal fillet/ mayonnaise sauce/mushroom/potato/parmesan cheese ',
|
||||
price: 505000,
|
||||
shopSlug: 'boote',
|
||||
categoryTitle: 'گوشت و مرغ',
|
||||
isActive: true,
|
||||
stock: 0,
|
||||
stockDefault: 0,
|
||||
images: ["https://dmenu.danakcorp.com/uploads/images/product/food_1714292844747.png"],
|
||||
varrinats: [
|
||||
{
|
||||
price: 15000, value: null
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
title: 'محصول دوم',
|
||||
desc: 'فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان..veal fillet/ mayonnaise sauce/mushroom/potato/parmesan cheese ',
|
||||
shopSlug: 'boote',
|
||||
categoryTitle: 'گوشت و مرغ',
|
||||
isActive: true,
|
||||
stockDefault: 0,
|
||||
attribute: 'اسم تنوع',
|
||||
images: ["https://dmenu.danakcorp.com/uploads/images/product/food_1714292844747.png"],
|
||||
varrinats: [
|
||||
{
|
||||
price: 15000, value: 'تنوع یک'
|
||||
},
|
||||
{
|
||||
price: 25000, value: 'تنوع دوم'
|
||||
},
|
||||
{
|
||||
price: 35000, value: 'تنوع سوم'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
@@ -3,6 +3,7 @@ import { Product } from '../modules/products/entities/product.entity';
|
||||
import type { Shop } from '../modules/shops/entities/shop.entity';
|
||||
import type { Category } from '../modules/products/entities/category.entity';
|
||||
import { productsData } from './data/products.data';
|
||||
import { Variant } from 'src/modules/products/entities/variant.entity';
|
||||
|
||||
export class ProductsSeeder {
|
||||
async run(
|
||||
@@ -47,7 +48,7 @@ export class ProductsSeeder {
|
||||
const product = em.create(Product, {
|
||||
title: productData.title,
|
||||
desc: productData.desc,
|
||||
shop,
|
||||
shop,
|
||||
category,
|
||||
isActive: productData.isActive,
|
||||
discount: productData.discount ?? 0,
|
||||
@@ -55,6 +56,15 @@ export class ProductsSeeder {
|
||||
images: productData.images,
|
||||
isSpecialOffer: productData.isSpecialOffer ?? false,
|
||||
});
|
||||
|
||||
productData.varrinats.forEach(variant => {
|
||||
const variantRecord = em.create(Variant, {
|
||||
product,
|
||||
value: variant.value ?? '',
|
||||
price: variant.price,
|
||||
});
|
||||
em.persist(variantRecord);
|
||||
});
|
||||
|
||||
em.persist(product);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user