-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
45 lines (39 loc) · 1.17 KB
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const prisma = require('../src/shared/prisma');
const { UserRole } = require('@prisma/client');
const bcrypt = require('bcrypt');
const seedSuperAdmin = async () => {
try {
const isExistSuperAdmin = await prisma.user.findFirst({
where: {
role: UserRole.SUPER_ADMIN
}
});
if (isExistSuperAdmin) {
console.log('Super admin already exists!');
return;
}
const hashedPassword = await bcrypt.hash('superadmin', 12);
await prisma.user.create({
data: {
email: 'super@admin.com',
password: hashedPassword,
role: UserRole.SUPER_ADMIN,
admin: {
create: {
name: 'Super Admin',
contactNumber: '01540581443'
}
}
}
});
console.log('Super Admin Created Successfully!', {
email: 'super@admin.com',
password: 'superadmin'
});
} catch (err) {
console.error(err);
} finally {
await prisma.$disconnect();
}
};
seedSuperAdmin();