feat: refactor ComplexPosesService to remove unused defaultInsert method and improve findAll logic

fix: update PartnersService to use 'isNot' instead of 'not' for allocation checks

refactor: enhance BusinessActivityComplexesService to validate license activation before creating a complex

fix: adjust ComplexPosesService to ensure account allocation checks are accurate and handle errors properly

refactor: modify ConsumerMiddleware to set consumerData instead of partnerData for better clarity

feat: expand SaleInvoicesService to include additional fields in the invoice selection

chore: update business-activities module to include accounts-charge module for better organization

fix: ensure ComplexPosesService correctly handles account allocation during POS creation

feat: implement PartnerBusinessActivityAccountsCharge module with create functionality for account charges

refactor: streamline getPartnerBusinessActivityAllocationLimits utility for better clarity and functionality

chore: add migration script to update database schema with necessary constraints and foreign keys

feat: create DTO for accounts charge to validate incoming data
This commit is contained in:
2026-04-25 15:16:59 +03:30
parent 12506de863
commit b72e6c7194
36 changed files with 975 additions and 568 deletions
@@ -0,0 +1,53 @@
/*
Warnings:
- You are about to drop the column `allocation_id` on the `partner_account_quota_credit` table. All the data in the column will be lost.
- A unique constraint covering the columns `[economic_code,consumer_id]` on the table `business_activities` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[credit_id]` on the table `license_account_allocation` will be added. If there are existing duplicate values, this will fail.
- Made the column `account_id` on table `poses` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE `license_renew` DROP FOREIGN KEY `license_renew_activation_id_fkey`;
-- DropForeignKey
ALTER TABLE `partner_account_quota_credit` DROP FOREIGN KEY `partner_account_quota_credit_allocation_id_fkey`;
-- DropForeignKey
ALTER TABLE `poses` DROP FOREIGN KEY `poses_account_id_fkey`;
-- DropIndex
DROP INDEX `business_activities_economic_code_key` ON `business_activities`;
-- DropIndex
DROP INDEX `license_renew_activation_id_fkey` ON `license_renew`;
-- DropIndex
DROP INDEX `partner_account_quota_credit_allocation_id_key` ON `partner_account_quota_credit`;
-- AlterTable
ALTER TABLE `license_account_allocation` ADD COLUMN `credit_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `license_renew` MODIFY `activation_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `partner_account_quota_credit` DROP COLUMN `allocation_id`;
-- AlterTable
ALTER TABLE `poses` MODIFY `account_id` VARCHAR(191) NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX `business_activities_economic_code_consumer_id_key` ON `business_activities`(`economic_code`, `consumer_id`);
-- CreateIndex
CREATE UNIQUE INDEX `license_account_allocation_credit_id_key` ON `license_account_allocation`(`credit_id`);
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `license_renew` ADD CONSTRAINT `license_renew_activation_id_fkey` FOREIGN KEY (`activation_id`) REFERENCES `licenses_activated`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `license_account_allocation` ADD CONSTRAINT `license_account_allocation_credit_id_fkey` FOREIGN KEY (`credit_id`) REFERENCES `partner_account_quota_credit`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
+5 -4
View File
@@ -44,7 +44,7 @@ model Consumer {
model BusinessActivity {
id String @id @default(ulid())
economic_code String @unique()
economic_code String
name String
created_at DateTime @default(now()) @db.Timestamp(0)
@@ -60,6 +60,7 @@ model BusinessActivity {
permission_businesses PermissionBusiness[]
license_activation LicenseActivation?
@@unique([economic_code, consumer_id])
@@map("business_activities")
}
@@ -103,12 +104,12 @@ model Pos {
device_id String?
device Device? @relation(fields: [device_id], references: [id])
account_id String? @unique
account ConsumerAccount? @relation(fields: [account_id], references: [id])
provider_id String?
provider Provider? @relation(fields: [provider_id], references: [id])
account_id String @unique
account ConsumerAccount @relation(fields: [account_id], references: [id])
permission_pos PermissionPos[]
sales_invoices SalesInvoice[]
+5 -5
View File
@@ -77,8 +77,8 @@ model LicenseRenew {
charge_transaction_id String
charge_transaction LicenseRenewChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
activation_id String
activation LicenseActivation @relation(fields: [activation_id], references: [id])
activation_id String?
activation LicenseActivation? @relation(fields: [activation_id], references: [id])
@@map("license_renew")
}
@@ -109,8 +109,7 @@ model PartnerAccountQuotaCredit {
charge_transaction_id String?
charge_transaction PartnerAccountQuotaChargeTransaction? @relation(fields: [charge_transaction_id], references: [id])
allocation_id String? @unique
allocation LicenseAccountAllocation? @relation(fields: [allocation_id], references: [id])
allocation LicenseAccountAllocation?
@@map("partner_account_quota_credit")
}
@@ -127,7 +126,8 @@ model LicenseAccountAllocation {
account_id String? @unique
account ConsumerAccount? @relation(fields: [account_id], references: [id])
partner_account_quota_credit PartnerAccountQuotaCredit?
credit_id String? @unique
credit PartnerAccountQuotaCredit? @relation(fields: [credit_id], references: [id])
@@map("license_account_allocation")
}
+1 -1
View File
@@ -5,7 +5,7 @@ model PartnerAccount {
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
partner_id String @unique
partner_id String
partner Partner @relation(fields: [partner_id], references: [id])
account_id String @unique
+25 -8
View File
@@ -1,6 +1,6 @@
import { PasswordUtil } from '@/common/utils/password.util'
import { generateTrackingCode } from '@/common/utils/tracking-code-generator.util'
import { GoodPricingModel, POSType, UnitType } from '@/generated/prisma/enums'
import { GoodPricingModel, UnitType } from '@/generated/prisma/enums'
import { GoodCreateInput, GoodCreateManyInput } from '@/generated/prisma/models'
import { prisma } from '../src/lib/prisma'
@@ -377,13 +377,30 @@ async function main() {
name: 'فروشگاه طلای مرکزی',
address: 'تهران، خیابان جمهوری',
branch_code: '12332',
pos_list: {
create: {
name: 'لاین ۱',
pos_type: POSType.WEB,
status: 'ACTIVE',
},
},
// pos_list: {
// create: {
// name: 'لاین ۱',
// pos_type: POSType.WEB,
// status: 'ACTIVE',
// account: {
// create: {
// role: 'OPERATOR',
// account_allocation: {
// },
// account: {
// create: {
// username: 'line1',
// password: await PasswordUtil.hash('123456'),
// status: 'ACTIVE',
// type: 'CONSUMER',
// },
// },
// }
// }
// },
// },
},
},
},