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