Files
psp_api/prisma/seed.ts
T

81 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { prisma } from '../src/lib/prisma'
async function main() {
if ((await prisma.role.count()) === 0) {
await prisma.role.upsert({
where: { id: 0, name: 'Admin' },
update: {},
create: {
name: 'Admin',
},
})
}
if ((await prisma.inventory.count()) === 0) {
await prisma.inventory.createMany({
data: [
{ name: 'انبار مرکزی', location: 'تهران', isPointOfSale: false, isActive: true },
{
name: 'فروشگاه حضوری',
location: 'مرکز شهر',
isPointOfSale: true,
isActive: true,
},
{
name: 'فروشگاه اینترنتی',
location: 'مرکز شهر',
isPointOfSale: true,
isActive: true,
},
],
})
}
if ((await prisma.productCategory.count()) === 0) {
await prisma.productCategory.createMany({
data: [{ name: 'دسته‌ی ۱' }, { name: 'دسته‌ی ۲' }, { name: 'دسته‌ی ۳' }],
})
}
if ((await prisma.productBrand.count()) === 0) {
await prisma.productBrand.createMany({
data: [{ name: 'برند ۱' }, { name: 'برند ۲' }, { name: 'برند ۳' }],
})
}
if ((await prisma.supplier.count()) === 0) {
await prisma.supplier.createMany({
data: [
{
firstName: 'تامین‌',
lastName: 'کننده ۱',
mobileNumber: '09120000001',
email: 'supplier1@example.com',
},
{
firstName: 'تامین‌',
lastName: 'کننده ۲',
mobileNumber: '09120000002',
email: 'supplier2@example.com',
},
{
firstName: 'تامین‌',
lastName: 'کننده 3',
mobileNumber: '09120000003',
email: 'supplier3@example.com',
},
],
})
}
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async e => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})