Resolve invalid task creator IDs, fix API routing and file uploads on Vercel, and replace dummy seed data with HR_Dashboard import.
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import 'dotenv/config';
|
|
import bcrypt from 'bcrypt';
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { mapAllHrProjects } from './mapHrProjects';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🌱 Seeding database...');
|
|
|
|
const adminPw = await bcrypt.hash('admin1234!', 12);
|
|
const memberPw = await bcrypt.hash('member1234!', 12);
|
|
|
|
const admin = await prisma.user.upsert({
|
|
where: { email: 'admin@eene.com' },
|
|
update: {},
|
|
create: { email: 'admin@eene.com', password: adminPw, name: '관리자', role: 'ADMIN', department: 'EENE' },
|
|
});
|
|
|
|
const member = await prisma.user.upsert({
|
|
where: { email: 'member@eene.com' },
|
|
update: { name: '정성호' },
|
|
create: { email: 'member@eene.com', password: memberPw, name: '정성호', role: 'MEMBER', department: 'EENE' },
|
|
});
|
|
|
|
console.log('✅ Users ready');
|
|
|
|
const mapped = mapAllHrProjects();
|
|
|
|
await prisma.file.deleteMany({});
|
|
await prisma.taskDetail.deleteMany({});
|
|
await prisma.milestone.deleteMany({});
|
|
await prisma.kpiMetric.deleteMany({});
|
|
await prisma.task.deleteMany({});
|
|
|
|
for (const t of mapped) {
|
|
const { milestones, detailContent, ...taskData } = t;
|
|
const task = await prisma.task.create({
|
|
data: {
|
|
...taskData,
|
|
creatorId: admin.id,
|
|
assigneeId: member.id,
|
|
},
|
|
});
|
|
|
|
for (const [order, ms] of milestones.entries()) {
|
|
await prisma.milestone.create({
|
|
data: { ...ms, taskId: task.id, order },
|
|
});
|
|
}
|
|
|
|
if (detailContent) {
|
|
await prisma.taskDetail.create({
|
|
data: {
|
|
taskId: task.id,
|
|
content: detailContent,
|
|
updatedBy: admin.id,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
console.log(`✅ Tasks created: ${mapped.length}개 (HR_Dashboard 데이터)`);
|
|
console.log('🎉 Seeding complete!');
|
|
}
|
|
|
|
main().catch(console.error).finally(() => prisma.$disconnect());
|