import { PrismaClient } from '@prisma/client'; import * as bcrypt from 'bcrypt'; const prisma = new PrismaClient(); async function main() { const password = await bcrypt.hash('asdf', 10); // bcrypt.hash('asdf', 10, async (err, password) => { const clinetRole = await prisma.role.upsert({ where: { name: 'client' }, update: {}, create: { name: 'client', }, }); const adminRole = await prisma.role.upsert({ where: { name: 'client' }, update: {}, create: { name: 'admin', }, }); const customer = await prisma.user.upsert({ where: { email: 'client@example.com' }, update: {}, create: { email: 'client@example.com', password: password, product: { create: [ { title: 'Product 1', published: true, }, { title: 'Product 2', published: true, }, ], }, }, }); const admin = await prisma.user.upsert({ where: { email: 'admin@example.com' }, update: {}, create: { email: 'admin@example.com', password: password, }, }); await prisma.usersRoles.upsert({ where: { userId_roleId: { userId: customer.id, roleId: clinetRole.id, }, }, update: {}, create: { roleId: clinetRole.id, userId: customer.id, assignedBy: 'seed.ts', }, }); await prisma.usersRoles.upsert({ where: { userId_roleId: { userId: admin.id, roleId: adminRole.id, }, }, update: {}, create: { roleId: adminRole.id, userId: admin.id, assignedBy: 'seed.ts', }, }); console.log({ customer, admin }); // } } main() .then(async () => { await prisma.$disconnect(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); process.exit(1); });