Skip to content

Commit

Permalink
Feat: add seed data & testing account (#92)
Browse files Browse the repository at this point in the history
* feat: add report api

* feat: report dto

* feat: seeding stock history

* feat: add seed data

* feat: add allow business number for testing
  • Loading branch information
raipen authored Nov 23, 2023
1 parent f757d1f commit 3c57f08
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 48 deletions.
133 changes: 129 additions & 4 deletions seeding/testSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const materialData = materialRawData.split('\n').slice(2).map((row) => {
name,
amount: parseInt(amount),
unit,
price
price:price===""?Math.floor(Math.random() * 10000+2000).toString():price
};
});

Expand Down Expand Up @@ -49,6 +49,11 @@ const menuData = menuRawData.split('\n').slice(3).join('\n').split('\n,,,,,,,\n'

const categoryData = [...new Set(menuData.map((menu) => menu.category))];

const getDateBeforeToday = (days: number, time: number,minites: number):Date => {
const date = new Date(new Date().getTime() - days * 24 * 60 * 60 * 1000);
return new Date(`${date.toISOString().split('T')[0]}T0${time}:${minites+10}:00.000Z`);
}

export const printAllStocks = () => {
const stocks = [...new Set([...new Set(menuData.flatMap((menu) => menu.materials.map((material) => material.name)))].flatMap((name) => {
const materials = mixedMaterialData.find((material) => material.name === name)?.materials;
Expand All @@ -64,10 +69,10 @@ export default async (prisma: PrismaClient, storeId: number) => {
data: materialData.map((material) => ({
name: material.name,
amount: isNaN(material.amount)?undefined:material.amount,
currentAmount: Math.floor(Math.random() * 2500+500),
currentAmount: material.name=="물"?-1:Math.floor(Math.random() * 2500+500),
noticeThreshold: Math.floor(Math.random() * 500+500),
unit: material.unit===""?undefined:material.unit,
price: material.price===""?undefined:material.price,
unit: material.unit,
price: material.price,
storeId
}))
});
Expand All @@ -77,9 +82,29 @@ export default async (prisma: PrismaClient, storeId: number) => {
}
});

await prisma.stockHistory.createMany({
data: materials.filter(({name})=>name!="물").map((material) => ({
stockId: material.id,
amount: material.amount!,
price: Math.floor(material.price!.toNumber()-Math.random() * 1800).toString(),
createdAt: new Date(new Date().getTime() - 48 * 24 * 60 * 60 * 1000),
})).concat(materials.filter(({name})=>name!="물").map((material) => ({
stockId: material.id,
amount: material.amount!,
price: Math.floor(material.price!.toNumber()-Math.random() * 1000).toString(),
createdAt: new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000),
}))).concat(materials.filter(({name})=>name!="물").map((material) => ({
stockId: material.id,
amount: material.amount!,
price: material.price!.toString(),
createdAt: new Date(new Date().getTime() - 2 * 24 * 60 * 60 * 1000),
})))
});

const mixedMaterialDataWithMaterials = mixedMaterialData.map((material) => {
return {
name: material.name,
totalAmount: material.materials.reduce((acc, cur) => acc + parseInt(cur.amount), 0),
materials: material.materials.map((material) => {
const stock = materials.find((stock) => stock.name === material.name);
if(!stock) throw new Error(`Stock not found: ${material.name}`);
Expand All @@ -94,6 +119,8 @@ export default async (prisma: PrismaClient, storeId: number) => {
await prisma.mixedStock.createMany({
data: mixedMaterialDataWithMaterials.map((material,index) => ({
name: material.name,
unit: 'g',
totalAmount: material.totalAmount,
storeId
}))
});
Expand Down Expand Up @@ -192,4 +219,102 @@ export default async (prisma: PrismaClient, storeId: number) => {
mixedStockId: material.mixedStockId
})))
});

await prisma.mileage.createMany({
data: new Array(20).fill(0).map((_, index) => ({
storeId,
mileage: 0,
phone: `010100000${10+index}`,
}))
});

const mileages = await prisma.mileage.findMany({
where: {
storeId
}
});

const preOrderItems = new Array(20).fill(0).map((_, index) => new Array(Math.floor(Math.random() * 5)+1).fill(0).map((_, index) => ({
menu: menus[Math.floor(Math.random() * menus.length)],
count: Math.floor(Math.random() * 3)+1,
})));

await prisma.preOrder.createMany({
data: preOrderItems.map((orderItem, index) => ({
storeId,
totalPrice: orderItem.reduce((acc, cur) => acc + cur.menu.price.toNumber() * cur.count, 0).toString(),
createdAt: getDateBeforeToday(30,0,0),
phone: `010${Math.floor(Math.random() * 100000000).toString().padStart(10, '0')}`,
orderedFor: getDateBeforeToday(Math.floor(Math.random() * 30),Math.floor(Math.random() * 9),Math.floor(Math.random() * 49)),
deletedAt: new Date()
}))
});

await prisma.preOrderItem.createMany({
data: preOrderItems.flatMap((orderItem, index) => orderItem.map((orderItem) => ({
preOrderId: index+1,
menuId: orderItem.menu.id,
count: orderItem.count
})))
});

const preOrders = await prisma.preOrder.findMany({
where: {
storeId
}
});

const orderItems = new Array(80).fill(0).map((_, index) => new Array(Math.floor(Math.random() * 5)+1).fill(0).map((_, index) => ({
menu: menus[Math.floor(Math.random() * menus.length)],
count: Math.floor(Math.random() * 3)+1,
})));

await prisma.order.createMany({
data: orderItems.map((orderItem, index) => ({
storeId,
paymentStatus: 'PAID',
totalPrice: orderItem.reduce((acc, cur) => acc + cur.menu.price.toNumber() * cur.count, 0).toString(),
mileageId: Math.floor(Math.random() * 5)>2?mileages[Math.floor(Math.random() * 20)].id:undefined,
useMileage: 0,
saveMileage: 0,
createdAt: getDateBeforeToday(Math.floor(Math.random() * 30),Math.floor(Math.random() * 9),Math.floor(Math.random() * 49)),
preOrderId: undefined as number | undefined
})).concat(
preOrders.map((order) => ({
storeId,
paymentStatus: 'PAID',
totalPrice: order.totalPrice.toString(),
mileageId: Math.floor(Math.random() * 5)>2?mileages[Math.floor(Math.random() * 20)].id:undefined,
useMileage: 0,
saveMileage: 0,
createdAt: order.orderedFor,
preOrderId: order.id
}))
)
});

const orders = await prisma.order.findMany({
where: {
storeId
}
});

const orderItemsWithPreOrder = orderItems.concat(preOrderItems);

await prisma.orderItem.createMany({
data: orders.flatMap((order,index) => orderItemsWithPreOrder[index].map((orderItem) => ({
orderId: order.id,
menuId: orderItem.menu.id,
count: orderItem.count
})))
});

await prisma.payment.createMany({
data: orders.map((order) => ({
orderId: order.id,
paymentMethod: ['CARD', 'CASH', 'BANK'][Math.floor(Math.random() * 3)],
price: order.totalPrice,
createdAt: order.createdAt,
}))
});
}
84 changes: 42 additions & 42 deletions seeding/소예다방-재료.csv
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
,,,
재료이름,용량,단위,가격
물,,,
원두,,,
생크림,,,
휘핑크림,,,
우유,,,
설탕,,,
헤이즐넛 시럽,,,
바닐라 시럽,,,
아몬드 우유,,,
초코 시럽,,,
카라멜 시럽,,,
원액,,,
초코시럽,,,
딸기청,,,
녹차가루,,,
곡물가루,,,
꿀,,,
패션후르츠 코디얼,,,
구운소금,,,
레몬 제스트,,,
오디 코디얼,,,
생강 코디얼,,,
호박 코디얼,,,
고구마 코디얼,,,
탄산수,,,
오렌지 과육,,,
오렌지 착즙,,,
레몬즙,,,
탄산수,,,
자몽 과육,,,
자몽 착즙,,,
블루베리 과육,,,
블루베리 착즙,,,
매실 청,,,
오미자 청,,,
생강레몬 코디얼,,,
대추 편,,,
유자 코디얼,,,
수제 청 과육,,,
아이스티,,,
무가당 홍차 베이스,,,
가당 홍차 베이스,,,
물,,ml,
원두,1000,g,7000
생크림,15000,g,
휘핑크림,4000,ml,
우유,8000,ml,22000
설탕,36000,ml,
헤이즐넛 시럽,2000,g,
바닐라 시럽,4000,g,
아몬드 우유,4000,g,
초코 시럽,2000,ml,
카라멜 시럽,4000,g,
원액,4000,g,
초코시럽,1000,ml,
딸기청,4000,g,
녹차가루,6000,g,
곡물가루,1000,g,
꿀,1000,g,
패션후르츠 코디얼,1000,g,
구운소금,3000,g,
레몬 제스트,100,g,
오디 코디얼,100,g,
생강 코디얼,4000,ml,
호박 코디얼,4000,ml,
고구마 코디얼,1000,g,
탄산수,1000,g,
오렌지 과육,100,개,
오렌지 착즙,2000,g,
레몬즙,4000,ml,
탄산수,10000,ml,
자몽 과육,2000,g,
자몽 착즙,4000,ml,
블루베리 과육,2000,g,
블루베리 착즙,4000,ml,
매실 청,6000,ml,
오미자 청,6000,ml,
생강레몬 코디얼,2000,g,
대추 편,100,g,
유자 코디얼,2000,g,
수제 청 과육,2000,g,
아이스티,1000,g,
무가당 홍차 베이스,3000,ml,
가당 홍차 베이스,3000,ml,
Loading

0 comments on commit 3c57f08

Please sign in to comment.