76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import bcrypt from 'bcryptjs'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
// Create a demo user
|
|
const hashedPassword = await bcrypt.hash('demo123456', 12)
|
|
|
|
const demoUser = await prisma.user.upsert({
|
|
where: { email: 'demo@example.com' },
|
|
update: {},
|
|
create: {
|
|
email: 'demo@example.com',
|
|
name: 'Demo User',
|
|
password: hashedPassword,
|
|
},
|
|
})
|
|
|
|
console.log('Created demo user:', demoUser.email)
|
|
|
|
// Create sample tasks
|
|
const tasks = [
|
|
{
|
|
title: 'Hoàn thành báo cáo dự án',
|
|
description: 'Viết báo cáo tổng kết dự án Q4',
|
|
status: 'IN_PROGRESS',
|
|
deadline: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000), // 2 days from now
|
|
},
|
|
{
|
|
title: 'Review code PR #123',
|
|
description: 'Review pull request của team member',
|
|
status: 'TODO',
|
|
deadline: new Date(Date.now() + 1 * 24 * 60 * 60 * 1000), // tomorrow
|
|
},
|
|
{
|
|
title: 'Họp team weekly',
|
|
description: 'Cuộc họp hàng tuần với team',
|
|
status: 'DONE',
|
|
deadline: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), // yesterday
|
|
},
|
|
{
|
|
title: 'Cập nhật documentation',
|
|
description: 'Cập nhật tài liệu API cho version mới',
|
|
status: 'TODO',
|
|
deadline: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // next week
|
|
},
|
|
{
|
|
title: 'Fix bug login page',
|
|
description: null,
|
|
status: 'TODO',
|
|
deadline: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000), // 2 days ago (overdue)
|
|
},
|
|
]
|
|
|
|
for (const task of tasks) {
|
|
await prisma.task.create({
|
|
data: {
|
|
...task,
|
|
userId: demoUser.id,
|
|
},
|
|
})
|
|
}
|
|
|
|
console.log('Created sample tasks')
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|