-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from AII-the-time/dev
Dev
- Loading branch information
Showing
29 changed files
with
2,272 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
const materialRawData = fs.readFileSync(path.join(process.cwd(),'prisma', '소예다방-재료.csv'), 'utf8').toString().trim(); | ||
const materialData = materialRawData.split('\n').slice(2).map((row) => { | ||
const [name, amount, unit, price] = row.split(','); | ||
return { | ||
name, | ||
amount: parseInt(amount), | ||
unit, | ||
price | ||
}; | ||
}); | ||
|
||
const mixedMaterialRawData = fs.readFileSync(path.join(process.cwd(),'prisma', '소예다방-Mixed재료.csv'), 'utf8').toString().trim(); | ||
const mixedMaterialData = mixedMaterialRawData.split('\n').slice(2).join('\n').split('\n,,\n').map((material) => { | ||
const rows = material.split('\n'); | ||
const name = rows[0].split(',')[0]; | ||
const materials = rows.map((row) => { | ||
const [_,name, amount] = row.split(','); | ||
return { | ||
name, | ||
amount | ||
}; | ||
}); | ||
return { name, materials }; | ||
}); | ||
|
||
const menuRawData = fs.readFileSync(path.join(process.cwd(),'prisma', '소예다방-메뉴.csv'), 'utf8').toString().trim(); | ||
const menuData = menuRawData.split('\n').slice(3).join('\n').split('\n,,,,,,\n').map((menu) => { | ||
const rows = menu.split('\n'); | ||
const name = rows[0].split(',')[0]; | ||
const price = rows[0].split(',')[1]; | ||
const materials = rows.map((row) => { | ||
const [_,__,name, ...amounts] = row.split(','); | ||
const [coldRegularAmount, coldSizeUpAmount, hotRegularAmount, hotSizeUpAmount] = amounts.map(Number); | ||
return { | ||
name, | ||
coldRegularAmount, | ||
coldSizeUpAmount, | ||
hotRegularAmount, | ||
hotSizeUpAmount | ||
}; | ||
}); | ||
return { name, price, materials }; | ||
}); | ||
|
||
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; | ||
if(!materials) return name; | ||
return materials.map((material) => material.name); | ||
}))]; | ||
|
||
console.log(stocks.join('\n')); | ||
} | ||
|
||
export default async (prisma: PrismaClient, storeId: number) => { | ||
const materials = await Promise.all(materialData.map(async (material) => { | ||
return await prisma.stock.create({ | ||
data: { | ||
name: material.name, | ||
amount: isNaN(material.amount)?undefined:material.amount, | ||
unit: material.unit===""?undefined:material.unit, | ||
price: material.price===""?undefined:material.price, | ||
storeId | ||
} | ||
}); | ||
})); | ||
|
||
const mixedMaterialDataWithMaterials = mixedMaterialData.map((material) => { | ||
return { | ||
name: material.name, | ||
materials: material.materials.map((material) => { | ||
const stock = materials.find((stock) => stock.name === material.name); | ||
if(!stock) throw new Error(`Stock not found: ${material.name}`); | ||
return { | ||
name: stock.name, | ||
amount: material.amount, | ||
stockId: stock.id | ||
}; | ||
}) | ||
}; | ||
}); | ||
const mixedMaterials = await Promise.all(mixedMaterialDataWithMaterials.map(async (material) => { | ||
return await prisma.mixedStock.create({ | ||
data: { | ||
name: material.name, | ||
storeId, | ||
mixings: { | ||
create: material.materials.map((material) => ({ | ||
amount: parseInt(material.amount), | ||
stockId: material.stockId, | ||
})) | ||
} | ||
} | ||
}); | ||
})); | ||
|
||
const menuDataWithMaterials = menuData.map((menu) => { | ||
return { | ||
name: menu.name, | ||
price: menu.price, | ||
materials: menu.materials.map((material) => { | ||
let stock:{id:number}|undefined= materials.find((stock) => stock.name === material.name); | ||
if(!stock) { | ||
stock = mixedMaterials.find((stock) => stock.name === material.name); | ||
if(!stock) throw new Error(`Stock not found: ${material.name}`); | ||
} | ||
return { | ||
name: material.name, | ||
coldRegularAmount: material.coldRegularAmount, | ||
coldSizeUpAmount: material.coldSizeUpAmount, | ||
hotRegularAmount: material.hotRegularAmount, | ||
hotSizeUpAmount: material.hotSizeUpAmount, | ||
stockId: stock.id | ||
}; | ||
}) | ||
}; | ||
}); | ||
const category3 = await prisma.category.create({ | ||
data: { | ||
id: 3, | ||
storeId, | ||
name: '미분류', | ||
sort: 3, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
}); | ||
const menus = await Promise.all(menuDataWithMaterials.map(async (menu,index) => { | ||
return await prisma.menu.create({ | ||
data: { | ||
name: menu.name, | ||
price: menu.price, | ||
categoryId: 3, | ||
sort: index+1, | ||
storeId, | ||
recipes: { | ||
create: menu.materials.map((material) => ({ | ||
coldRegularAmount: material.coldRegularAmount, | ||
coldSizeUpAmount: material.coldSizeUpAmount, | ||
hotRegularAmount: material.hotRegularAmount, | ||
hotSizeUpAmount: material.hotSizeUpAmount, | ||
stockId: material.stockId, | ||
})) | ||
} | ||
} | ||
}); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- CreateTable | ||
CREATE TABLE `Recipe` ( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`storeId` INTEGER NOT NULL, | ||
`menuId` INTEGER NOT NULL, | ||
`stockId` INTEGER NOT NULL, | ||
`coldRegularAmount` INTEGER NULL, | ||
`coldSizeUpAmount` INTEGER NULL, | ||
`hotRegularAmount` INTEGER NULL, | ||
`hotSizeUpAmount` INTEGER NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- CreateTable | ||
CREATE TABLE `Stock` ( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`storeId` INTEGER NOT NULL, | ||
`name` VARCHAR(191) NOT NULL, | ||
`standard` INTEGER NOT NULL, | ||
`count` INTEGER NOT NULL, | ||
`sort` INTEGER NOT NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Recipe` ADD CONSTRAINT `Recipe_storeId_fkey` FOREIGN KEY (`storeId`) REFERENCES `Store`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Recipe` ADD CONSTRAINT `Recipe_menuId_fkey` FOREIGN KEY (`menuId`) REFERENCES `Menu`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Recipe` ADD CONSTRAINT `Recipe_stockId_fkey` FOREIGN KEY (`stockId`) REFERENCES `Stock`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Stock` ADD CONSTRAINT `Stock_storeId_fkey` FOREIGN KEY (`storeId`) REFERENCES `Store`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `count` on the `Stock` table. All the data in the column will be lost. | ||
- You are about to drop the column `sort` on the `Stock` table. All the data in the column will be lost. | ||
- You are about to drop the column `standard` on the `Stock` table. All the data in the column will be lost. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE `Recipe` DROP FOREIGN KEY `Recipe_stockId_fkey`; | ||
|
||
-- AlterTable | ||
ALTER TABLE `Recipe` ADD COLUMN `mixedStockId` INTEGER NULL, | ||
MODIFY `stockId` INTEGER NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE `Stock` DROP COLUMN `count`, | ||
DROP COLUMN `sort`, | ||
DROP COLUMN `standard`, | ||
ADD COLUMN `amount` INTEGER NULL, | ||
ADD COLUMN `unit` VARCHAR(191) NULL; | ||
|
||
-- CreateTable | ||
CREATE TABLE `MixedStock` ( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`storeId` INTEGER NOT NULL, | ||
`name` VARCHAR(191) NOT NULL, | ||
`totalAmount` INTEGER NULL, | ||
`unit` VARCHAR(191) NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- CreateTable | ||
CREATE TABLE `Mixing` ( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`storeId` INTEGER NOT NULL, | ||
`mixedStockId` INTEGER NOT NULL, | ||
`stockId` INTEGER NOT NULL, | ||
`amount` INTEGER NOT NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Recipe` ADD CONSTRAINT `Recipe_stockId_fkey` FOREIGN KEY (`stockId`) REFERENCES `Stock`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Recipe` ADD CONSTRAINT `Recipe_mixedStockId_fkey` FOREIGN KEY (`mixedStockId`) REFERENCES `MixedStock`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `MixedStock` ADD CONSTRAINT `MixedStock_storeId_fkey` FOREIGN KEY (`storeId`) REFERENCES `Store`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Mixing` ADD CONSTRAINT `Mixing_storeId_fkey` FOREIGN KEY (`storeId`) REFERENCES `Store`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Mixing` ADD CONSTRAINT `Mixing_mixedStockId_fkey` FOREIGN KEY (`mixedStockId`) REFERENCES `MixedStock`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE `Mixing` ADD CONSTRAINT `Mixing_stockId_fkey` FOREIGN KEY (`stockId`) REFERENCES `Stock`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE `Stock` ADD COLUMN `price` DECIMAL(65, 30) NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `storeId` on the `Mixing` table. All the data in the column will be lost. | ||
- You are about to drop the column `storeId` on the `Recipe` table. All the data in the column will be lost. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE `Mixing` DROP FOREIGN KEY `Mixing_storeId_fkey`; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE `Recipe` DROP FOREIGN KEY `Recipe_storeId_fkey`; | ||
|
||
-- AlterTable | ||
ALTER TABLE `Mixing` DROP COLUMN `storeId`; | ||
|
||
-- AlterTable | ||
ALTER TABLE `Recipe` DROP COLUMN `storeId`; | ||
|
||
-- AlterTable | ||
ALTER TABLE `Stock` ADD COLUMN `currentAmount` INTEGER NOT NULL DEFAULT 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
원재료 레시피,, | ||
,, | ||
소스,생크림,485 | ||
,휘핑크림,485 | ||
,, | ||
자몽 청,자몽 과육,600 | ||
,자몽 착즙,1000 | ||
,설탕,2000 | ||
,레몬즙,400 | ||
,구운소금,4 | ||
,레몬 제스트,8 | ||
,, | ||
오렌지 청,오렌지 과육,600 | ||
,오렌지 착즙,1000 | ||
,설탕,2000 | ||
,레몬즙,400 | ||
,구운소금,4 | ||
,레몬 제스트,8 | ||
,, | ||
블루베리 청,블루베리 과육,1000 | ||
,블루베리 착즙,600 | ||
,설탕,1800 | ||
,레몬즙,400 | ||
,구운소금,4 | ||
,레몬 제스트,8 | ||
,, | ||
패션후르츠 청,패션후르츠 코디얼,2000 | ||
,설탕,2000 | ||
,구운소금,4 | ||
,레몬 제스트,8 | ||
,, | ||
밀크티 베이스,무가당 홍차 베이스,1000 | ||
,가당 홍차 베이스,1000 |
Oops, something went wrong.