create license management
This commit is contained in:
+276
-4
@@ -1,4 +1,6 @@
|
||||
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() {
|
||||
@@ -28,8 +30,9 @@ async function main() {
|
||||
},
|
||||
})
|
||||
|
||||
const guildsCount = prisma.guild.count()
|
||||
if (!guildsCount) {
|
||||
// ****************** GUILD Start ****************** //
|
||||
const guilds = await prisma.guild.findMany()
|
||||
if (!guilds.length) {
|
||||
const guilds = await prisma.guild.createMany({
|
||||
data: [
|
||||
{
|
||||
@@ -42,9 +45,17 @@ async function main() {
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
const goldGuildId = guilds[0].id
|
||||
|
||||
// ****************** 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,
|
||||
@@ -62,6 +73,267 @@ async function main() {
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
// ****************** 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()
|
||||
|
||||
Reference in New Issue
Block a user