348 lines
8.7 KiB
TypeScript
348 lines
8.7 KiB
TypeScript
import { PasswordUtil } from '@/common/utils/password.util'
|
||
import { GoodPricingModel, POSType, UnitType } from '@/generated/prisma/enums'
|
||
import { GoodCreateInput, GoodCreateManyInput } from '@/generated/prisma/models'
|
||
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',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
})
|
||
|
||
// ****************** GUILD Start ****************** //
|
||
const guilds = await prisma.guild.findMany()
|
||
if (!guilds.length) {
|
||
const guilds = await prisma.guild.createMany({
|
||
data: [
|
||
{
|
||
name: 'طلا',
|
||
code: 'Gold',
|
||
},
|
||
{
|
||
name: 'میوه و ترهبار',
|
||
code: 'Fruit',
|
||
},
|
||
],
|
||
})
|
||
}
|
||
|
||
// ****************** GUILD Good Categories Start ****************** //
|
||
const goldGuildId = guilds[0].id
|
||
const goldGuildGoodCategories = await prisma.goodCategory.findMany({
|
||
where: {
|
||
guild_id: goldGuildId,
|
||
is_default_guild_good: true,
|
||
},
|
||
})
|
||
if (!goldGuildGoodCategories) {
|
||
const categoryFactory = (name: string) => ({
|
||
name,
|
||
guild_id: goldGuildId,
|
||
is_default_guild_good: true,
|
||
})
|
||
|
||
await prisma.goodCategory.createMany({
|
||
data: [
|
||
categoryFactory('زیورآلات'),
|
||
categoryFactory('طلا'),
|
||
categoryFactory('سایر'),
|
||
categoryFactory('سکه'),
|
||
categoryFactory('شمش'),
|
||
categoryFactory('شمش'),
|
||
],
|
||
})
|
||
}
|
||
|
||
// ****************** GUILD Good Start ****************** //
|
||
const goodFactory = (
|
||
name: string,
|
||
categoryId: string,
|
||
pricingModel: GoodPricingModel,
|
||
unitType: UnitType,
|
||
): GoodCreateManyInput => ({
|
||
name,
|
||
category_id: categoryId,
|
||
pricing_model: pricingModel,
|
||
sku: '',
|
||
unit_type: unitType,
|
||
is_default_guild_good: true,
|
||
})
|
||
|
||
const zivarCategory = await prisma.goodCategory.findFirst({
|
||
where: {
|
||
name: 'زیورآلات',
|
||
},
|
||
})
|
||
if (zivarCategory) {
|
||
const zivarGoods = await prisma.good.count({
|
||
where: {
|
||
category_id: zivarCategory?.id,
|
||
},
|
||
})
|
||
if (!zivarGoods) {
|
||
const goodItems: GoodCreateManyInput[] = []
|
||
|
||
goodItems.push(
|
||
...[
|
||
goodFactory(
|
||
'آویز گردنبند طلا',
|
||
zivarCategory.id,
|
||
GoodPricingModel.GOLD,
|
||
UnitType.GRAM,
|
||
),
|
||
goodFactory('النگو', zivarCategory.id, GoodPricingModel.GOLD, UnitType.GRAM),
|
||
goodFactory('انگشتر', zivarCategory.id, GoodPricingModel.GOLD, UnitType.GRAM),
|
||
goodFactory('دستبند', zivarCategory.id, GoodPricingModel.GOLD, UnitType.GRAM),
|
||
goodFactory('زنجیر', zivarCategory.id, GoodPricingModel.GOLD, UnitType.GRAM),
|
||
goodFactory('سرویس', zivarCategory.id, GoodPricingModel.GOLD, UnitType.GRAM),
|
||
goodFactory('گوشواره', zivarCategory.id, GoodPricingModel.GOLD, UnitType.GRAM),
|
||
],
|
||
)
|
||
|
||
await prisma.good.createMany({ data: goodItems })
|
||
}
|
||
}
|
||
|
||
const goldCategory = await prisma.goodCategory.findFirst({
|
||
where: {
|
||
name: 'طلا',
|
||
},
|
||
})
|
||
if (goldCategory) {
|
||
const goldGoods = await prisma.good.count({
|
||
where: {
|
||
category_id: goldCategory?.id,
|
||
},
|
||
})
|
||
if (!goldGoods) {
|
||
const goodItems: GoodCreateInput[] = []
|
||
goodItems.push(
|
||
...[
|
||
goodFactory(
|
||
'طلای آب شده',
|
||
goldCategory.id,
|
||
GoodPricingModel.GOLD,
|
||
UnitType.GRAM,
|
||
),
|
||
goodFactory(
|
||
'طلای شکسته',
|
||
goldCategory.id,
|
||
GoodPricingModel.GOLD,
|
||
UnitType.GRAM,
|
||
),
|
||
goodFactory(
|
||
'طلای مستعمل',
|
||
goldCategory.id,
|
||
GoodPricingModel.GOLD,
|
||
UnitType.GRAM,
|
||
),
|
||
],
|
||
)
|
||
await prisma.good.createMany({ data: goodItems })
|
||
}
|
||
}
|
||
|
||
const coinCategory = await prisma.goodCategory.findFirst({
|
||
where: {
|
||
name: 'سکه',
|
||
},
|
||
})
|
||
if (coinCategory) {
|
||
const coinGoods = await prisma.good.count({
|
||
where: {
|
||
category_id: coinCategory?.id,
|
||
},
|
||
})
|
||
if (!coinGoods) {
|
||
const goodItems: GoodCreateInput[] = []
|
||
goodItems.push(
|
||
...[
|
||
goodFactory(
|
||
'مسکوکات خارجی',
|
||
coinCategory.id,
|
||
GoodPricingModel.STANDARD,
|
||
UnitType.COUNT,
|
||
),
|
||
goodFactory(
|
||
'مسکوکات داخلی (پارسیان)',
|
||
coinCategory.id,
|
||
GoodPricingModel.STANDARD,
|
||
UnitType.COUNT,
|
||
),
|
||
goodFactory(
|
||
'تمام بهار آزادی (طرح جدید)',
|
||
coinCategory.id,
|
||
GoodPricingModel.STANDARD,
|
||
UnitType.COUNT,
|
||
),
|
||
goodFactory(
|
||
'تمام بهار آزادی (طرح قدیم)',
|
||
coinCategory.id,
|
||
GoodPricingModel.STANDARD,
|
||
UnitType.COUNT,
|
||
),
|
||
],
|
||
)
|
||
await prisma.good.createMany({ data: goodItems })
|
||
}
|
||
}
|
||
|
||
const shemshCategory = await prisma.goodCategory.findFirst({
|
||
where: {
|
||
name: 'شمش',
|
||
},
|
||
})
|
||
|
||
if (shemshCategory) {
|
||
const shemshGoods = await prisma.good.count({
|
||
where: {
|
||
category_id: shemshCategory?.id,
|
||
},
|
||
})
|
||
if (!shemshGoods) {
|
||
await prisma.good.create({
|
||
data: goodFactory(
|
||
'شمش استاندارد',
|
||
shemshCategory.id,
|
||
GoodPricingModel.GOLD,
|
||
UnitType.GRAM,
|
||
),
|
||
})
|
||
}
|
||
}
|
||
|
||
// ****************** BA Start ****************** //
|
||
const ba = await prisma.businessActivity.count()
|
||
|
||
if (!ba) {
|
||
await prisma.businessActivity.create({
|
||
data: {
|
||
name: 'طلا فروشی',
|
||
user: {
|
||
create: {
|
||
first_name: 'محمد',
|
||
last_name: 'زرگر',
|
||
mobile_number: '09120258155',
|
||
accounts: {
|
||
create: {
|
||
role: 'OWNER',
|
||
account: {
|
||
create: {
|
||
username: 'zargar',
|
||
password: await PasswordUtil.hash('123456'),
|
||
status: 'ACTIVE',
|
||
type: 'CONSUMER',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
guild: {
|
||
connect: {
|
||
id: guilds[0].id,
|
||
},
|
||
},
|
||
complexes: {
|
||
create: {
|
||
name: 'فروشگاه طلای مرکزی',
|
||
address: 'تهران، خیابان جمهوری',
|
||
tax_id: '12312452345765',
|
||
pos_list: {
|
||
create: {
|
||
name: 'لاین ۱',
|
||
pos_type: POSType.WEB,
|
||
serial: '12312312',
|
||
status: 'ACTIVE',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
})
|
||
}
|
||
// ****************** BA Start ****************** //
|
||
|
||
// ****************** partner Start ****************** //
|
||
const partner = await prisma.partner.count()
|
||
if (!partner) {
|
||
await prisma.partner.create({
|
||
data: {
|
||
name: 'تیس',
|
||
code: 'TIS',
|
||
license_quota: 5,
|
||
status: 'ACTIVE',
|
||
accounts: {
|
||
create: {
|
||
role: 'OWNER',
|
||
account: {
|
||
create: {
|
||
username: 'tis',
|
||
password: await PasswordUtil.hash('123456'),
|
||
status: 'ACTIVE',
|
||
type: 'PARTNER',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
})
|
||
}
|
||
|
||
// ****************** provider Start ****************** //
|
||
const provider = await prisma.provider.count()
|
||
if (!provider) {
|
||
await prisma.provider.create({
|
||
data: {
|
||
name: 'توسن',
|
||
code: 'Tosan',
|
||
status: 'ACTIVE',
|
||
accounts: {
|
||
create: {
|
||
role: 'OWNER',
|
||
account: {
|
||
create: {
|
||
username: 'tosan',
|
||
password: await PasswordUtil.hash('123456'),
|
||
status: 'ACTIVE',
|
||
type: 'PROVIDER',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
})
|
||
}
|
||
}
|
||
|
||
main()
|
||
.then(async () => {
|
||
await prisma.$disconnect()
|
||
})
|
||
.catch(async e => {
|
||
console.error(e)
|
||
await prisma.$disconnect()
|
||
process.exit(1)
|
||
})
|