97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import { hash } from 'bcryptjs'
|
|
import { PrismaClient } from '@prisma/client'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
const user = await prisma.user.upsert({
|
|
where: { email: 'user@example.com' },
|
|
update: {},
|
|
create: {
|
|
email: 'user@example.com',
|
|
name: '사용자',
|
|
passwordHash: await hash('money1234', 10)
|
|
}
|
|
})
|
|
|
|
const cash = await prisma.asset.upsert({
|
|
where: { id: 'seed-cash' },
|
|
update: {},
|
|
create: {
|
|
id: 'seed-cash',
|
|
userId: user.id,
|
|
name: '현금',
|
|
balanceType: 'cumulative',
|
|
initialBalance: 0,
|
|
sortOrder: 0
|
|
}
|
|
})
|
|
|
|
await prisma.asset.upsert({
|
|
where: { id: 'seed-living' },
|
|
update: {},
|
|
create: {
|
|
id: 'seed-living',
|
|
userId: user.id,
|
|
name: '생활비',
|
|
balanceType: 'monthly_reset',
|
|
sortOrder: 1
|
|
}
|
|
})
|
|
|
|
const incomeParent = await prisma.category.upsert({
|
|
where: { id: 'seed-income-work' },
|
|
update: {},
|
|
create: { id: 'seed-income-work', userId: user.id, type: 'income', name: '근로', sortOrder: 0 }
|
|
})
|
|
|
|
const salary = await prisma.category.upsert({
|
|
where: { id: 'seed-income-salary' },
|
|
update: {},
|
|
create: { id: 'seed-income-salary', userId: user.id, type: 'income', name: '월급', parentId: incomeParent.id, sortOrder: 0 }
|
|
})
|
|
|
|
const foodParent = await prisma.category.upsert({
|
|
where: { id: 'seed-expense-food' },
|
|
update: {},
|
|
create: { id: 'seed-expense-food', userId: user.id, type: 'expense', name: '식비', sortOrder: 0 }
|
|
})
|
|
|
|
const meal = await prisma.category.upsert({
|
|
where: { id: 'seed-expense-meal' },
|
|
update: {},
|
|
create: { id: 'seed-expense-meal', userId: user.id, type: 'expense', name: '외식', parentId: foodParent.id, sortOrder: 0 }
|
|
})
|
|
|
|
const transactionCount = await prisma.transaction.count({ where: { userId: user.id } })
|
|
if (transactionCount === 0) {
|
|
await prisma.transaction.createMany({
|
|
data: [
|
|
{
|
|
userId: user.id,
|
|
type: 'income',
|
|
occurredAt: new Date(),
|
|
assetId: cash.id,
|
|
categoryId: salary.id,
|
|
amount: 3200000,
|
|
title: '월급'
|
|
},
|
|
{
|
|
userId: user.id,
|
|
type: 'expense',
|
|
occurredAt: new Date(),
|
|
assetId: cash.id,
|
|
categoryId: meal.id,
|
|
amount: 14980,
|
|
title: '이마트칠성점'
|
|
}
|
|
]
|
|
})
|
|
}
|
|
}
|
|
|
|
main()
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|