import { PrismaClient } from '@prisma/client'; import { PrismaPg } from '@prisma/adapter-pg'; import { Pool } from 'pg'; import 'dotenv/config'; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const adapter = new PrismaPg(pool); const prisma = new PrismaClient({ adapter }); async function main() { console.log('--- Đang xóa dữ liệu cũ... ---'); await prisma.expense.deleteMany(); await prisma.photo.deleteMany(); await prisma.tour.deleteMany(); await prisma.user.deleteMany(); console.log('--- Đang tạo người dùng mẫu... ---'); const owner = await prisma.user.create({ data: { email: 'owner@travel.com', name: 'Lộc Phạm (Chủ Tour)', passwordHash: 'hashed_password_123', }, }); const photoMember = await prisma.user.create({ data: { email: 'photomember@travel.com', name: 'Nguyễn Văn Ảnh (Chỉ xem ảnh)', passwordHash: 'hashed_password_456', }, }); console.log('--- Đang tạo Tour và phân quyền... ---'); const tour = await prisma.tour.create({ data: { title: 'Hành trình khám phá TP.HCM', startDate: new Date('2023-11-20'), endDate: new Date('2023-11-21'), creatorId: owner.id, members: { create: [ { userId: owner.id, role: 'OWNER' }, { userId: photoMember.id, role: 'MEMBER_PHOTO_ONLY' }, ], }, }, }); console.log('--- Đang tạo chặng và địa điểm... ---'); const leg1 = await prisma.leg.create({ data: { tourId: tour.id, sequenceNumber: 1, notes: 'Khám phá lịch sử trung tâm', places: { create: [ { name: 'Dinh Độc Lập', address: '135 Nam Kỳ Khởi Nghĩa, Quận 1', latitude: 10.777, longitude: 106.695, sequenceInLeg: 1, arrivalTime: new Date('2023-11-20T08:00:00Z'), }, { name: 'Bưu điện Thành phố', address: '02 Công xã Paris, Quận 1', latitude: 10.779, longitude: 106.699, sequenceInLeg: 2, arrivalTime: new Date('2023-11-20T10:00:00Z'), }, ], }, }, }); console.log('--- Đang tạo chi phí mẫu... ---'); await prisma.expense.create({ data: { legId: leg1.id, category: 'DINING', amount: 500000, currency: 'VND', description: 'Ăn trưa đặc sản Quận 1', }, }); console.log('--- Seed dữ liệu hoàn tất! ---'); console.log(`Email đăng nhập Owner: ${owner.email}`); console.log(`Email đăng nhập Photo Only: ${photoMember.email}`); console.log(`Tour ID để test: ${tour.id}`); } main() .catch((e) => { console.error(e); process.exit(1); }) .finally(async () => { await pool.end(); }); //# sourceMappingURL=seed.js.map