2026-03-07 11:25:11 +03:30
|
|
|
|
import { PasswordUtil } from '@/common/utils/password.util'
|
2026-04-06 13:31:40 +03:30
|
|
|
|
import { GoodPricingModel, POSType, UnitType } from '@/generated/prisma/enums'
|
|
|
|
|
|
import { GoodCreateInput, GoodCreateManyInput } from '@/generated/prisma/models'
|
2025-12-06 17:48:10 +03:30
|
|
|
|
import { prisma } from '../src/lib/prisma'
|
|
|
|
|
|
|
|
|
|
|
|
async function main() {
|
2026-03-07 11:25:11 +03:30
|
|
|
|
const password = await PasswordUtil.hash('123456')
|
2026-03-16 00:33:40 +03:30
|
|
|
|
const adminUser = await prisma.admin.upsert({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
mobile_number: '09120258156',
|
|
|
|
|
|
},
|
2026-03-07 11:25:11 +03:30
|
|
|
|
update: {},
|
|
|
|
|
|
create: {
|
2026-03-16 00:33:40 +03:30
|
|
|
|
first_name: 'عباس',
|
|
|
|
|
|
last_name: 'حسنی',
|
|
|
|
|
|
national_code: '0016022289',
|
|
|
|
|
|
mobile_number: '09120258156',
|
2026-04-11 14:47:05 +03:30
|
|
|
|
adminAccounts: {
|
2026-03-07 11:25:11 +03:30
|
|
|
|
create: {
|
2026-03-16 00:33:40 +03:30
|
|
|
|
account: {
|
|
|
|
|
|
create: {
|
|
|
|
|
|
username: 'superAdmin',
|
|
|
|
|
|
password,
|
|
|
|
|
|
type: 'ADMIN',
|
|
|
|
|
|
status: 'ACTIVE',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2026-03-07 11:25:11 +03:30
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
2026-03-16 00:33:40 +03:30
|
|
|
|
|
2026-04-06 13:31:40 +03:30
|
|
|
|
// ****************** GUILD Start ****************** //
|
|
|
|
|
|
const guilds = await prisma.guild.findMany()
|
|
|
|
|
|
if (!guilds.length) {
|
2026-04-11 14:47:05 +03:30
|
|
|
|
await prisma.guild.createMany({
|
2026-03-16 00:33:40 +03:30
|
|
|
|
data: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'طلا',
|
|
|
|
|
|
code: 'Gold',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'میوه و ترهبار',
|
|
|
|
|
|
code: 'Fruit',
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
})
|
2026-04-06 13:31:40 +03:30
|
|
|
|
}
|
2026-03-16 00:33:40 +03:30
|
|
|
|
|
2026-04-06 13:31:40 +03:30
|
|
|
|
// ****************** GUILD Good Categories Start ****************** //
|
2026-04-11 14:47:05 +03:30
|
|
|
|
|
|
|
|
|
|
const goldGuild = await prisma.guild.findFirst({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
name: 'طلا',
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const goldGuildId = goldGuild?.id
|
2026-04-06 13:31:40 +03:30
|
|
|
|
const goldGuildGoodCategories = await prisma.goodCategory.findMany({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
guild_id: goldGuildId,
|
|
|
|
|
|
is_default_guild_good: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
2026-04-11 14:47:05 +03:30
|
|
|
|
|
|
|
|
|
|
if (!goldGuildGoodCategories?.length) {
|
2026-03-16 00:33:40 +03:30
|
|
|
|
const categoryFactory = (name: string) => ({
|
|
|
|
|
|
name,
|
|
|
|
|
|
guild_id: goldGuildId,
|
|
|
|
|
|
is_default_guild_good: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
await prisma.goodCategory.createMany({
|
|
|
|
|
|
data: [
|
|
|
|
|
|
categoryFactory('زیورآلات'),
|
|
|
|
|
|
categoryFactory('طلا'),
|
|
|
|
|
|
categoryFactory('سایر'),
|
|
|
|
|
|
categoryFactory('سکه'),
|
|
|
|
|
|
categoryFactory('شمش'),
|
|
|
|
|
|
categoryFactory('شمش'),
|
|
|
|
|
|
],
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-04-06 13:31:40 +03:30
|
|
|
|
|
|
|
|
|
|
// ****************** 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: 'طلا فروشی',
|
2026-04-11 14:47:05 +03:30
|
|
|
|
consumer: {
|
2026-04-06 13:31:40 +03:30
|
|
|
|
create: {
|
|
|
|
|
|
first_name: 'محمد',
|
|
|
|
|
|
last_name: 'زرگر',
|
|
|
|
|
|
mobile_number: '09120258155',
|
2026-04-11 14:47:05 +03:30
|
|
|
|
consumer_accounts: {
|
2026-04-06 13:31:40 +03:30
|
|
|
|
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',
|
2026-04-11 14:47:05 +03:30
|
|
|
|
partner_accounts: {
|
2026-04-06 13:31:40 +03:30
|
|
|
|
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',
|
2026-04-11 14:47:05 +03:30
|
|
|
|
provider_accounts: {
|
2026-04-06 13:31:40 +03:30
|
|
|
|
create: {
|
|
|
|
|
|
role: 'OWNER',
|
|
|
|
|
|
account: {
|
|
|
|
|
|
create: {
|
|
|
|
|
|
username: 'tosan',
|
|
|
|
|
|
password: await PasswordUtil.hash('123456'),
|
|
|
|
|
|
status: 'ACTIVE',
|
|
|
|
|
|
type: 'PROVIDER',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-12-06 17:48:10 +03:30
|
|
|
|
}
|
2025-12-14 10:15:57 +03:30
|
|
|
|
|
2025-12-06 17:48:10 +03:30
|
|
|
|
main()
|
|
|
|
|
|
.then(async () => {
|
|
|
|
|
|
await prisma.$disconnect()
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(async e => {
|
|
|
|
|
|
console.error(e)
|
|
|
|
|
|
await prisma.$disconnect()
|
|
|
|
|
|
process.exit(1)
|
|
|
|
|
|
})
|