Files
psp_api/prisma/seed.ts
T

76 lines
1.6 KiB
TypeScript

import { PasswordUtil } from '@/common/utils/password.util'
import { prisma } from '../src/lib/prisma'
async function main() {
const password = await PasswordUtil.hash('123456')
const adminUser = await prisma.admin.upsert({
where: {
mobile_number: '09120258156',
},
update: {},
create: {
first_name: 'عباس',
last_name: 'حسنی',
national_code: '0016022289',
mobile_number: '09120258156',
accounts: {
create: {
account: {
create: {
username: 'superAdmin',
password,
type: 'ADMIN',
status: 'ACTIVE',
},
},
},
},
},
})
const guildsCount = prisma.guild.count()
if (!guildsCount) {
const guilds = await prisma.guild.createMany({
data: [
{
name: 'طلا',
code: 'Gold',
},
{
name: 'میوه و تره‌بار',
code: 'Fruit',
},
],
})
const goldGuildId = guilds[0].id
const categoryFactory = (name: string) => ({
name,
guild_id: goldGuildId,
is_default_guild_good: true,
})
await prisma.goodCategory.createMany({
data: [
categoryFactory('زیورآلات'),
categoryFactory('طلا'),
categoryFactory('سایر'),
categoryFactory('سکه'),
categoryFactory('شمش'),
categoryFactory('شمش'),
],
})
}
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async e => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})