feat(partners): add utility functions for partner business activity allocation limits and remaining licenses
- Implemented `getPartnerBusinessActivityAllocationLimits` to retrieve allocation limits for a partner's business activity. - Added `ensurePartnerBusinessActivityHasRemainingAllocation` to validate remaining allocation credits. - Created `getPartnerRemainingLicenses` to count remaining licenses for a partner. - Developed `getPartnerFirstRemainingLicense` to fetch the first unused license for a partner. - Introduced `ensurePartnerHasRemainingLicense` to ensure a partner has at least one unused license.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `partner_account_quota_allocation` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `partner_account_quota_allocation` DROP FOREIGN KEY `partner_account_quota_allocation_charge_transaction_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `partner_account_quota_allocation` DROP FOREIGN KEY `partner_account_quota_allocation_license_id_fkey`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `partner_account_quota_allocation`;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `partner_account_quota_credit` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`charge_transaction_id` VARCHAR(191) NOT NULL,
|
||||
`allocation_id` VARCHAR(191) NULL,
|
||||
|
||||
UNIQUE INDEX `partner_account_quota_credit_allocation_id_key`(`allocation_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `license_account_allocation` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`license_activation_id` VARCHAR(191) NOT NULL,
|
||||
`account_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `license_account_allocation_account_id_key`(`account_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `partner_account_quota_credit` ADD CONSTRAINT `partner_account_quota_credit_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `partner_account_quota_charge_transaction`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `partner_account_quota_credit` ADD CONSTRAINT `partner_account_quota_credit_allocation_id_fkey` FOREIGN KEY (`allocation_id`) REFERENCES `license_account_allocation`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_account_allocation` ADD CONSTRAINT `license_account_allocation_license_activation_id_fkey` FOREIGN KEY (`license_activation_id`) REFERENCES `licenses_activated`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_account_allocation` ADD CONSTRAINT `license_account_allocation_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,30 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `license_account_allocation` DROP FOREIGN KEY `license_account_allocation_account_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `license_account_allocation` DROP FOREIGN KEY `license_account_allocation_license_activation_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `partner_account_quota_credit` DROP FOREIGN KEY `partner_account_quota_credit_charge_transaction_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `license_account_allocation_license_activation_id_fkey` ON `license_account_allocation`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `partner_account_quota_credit_charge_transaction_id_fkey` ON `partner_account_quota_credit`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `license_account_allocation` MODIFY `license_activation_id` VARCHAR(191) NULL,
|
||||
MODIFY `account_id` VARCHAR(191) NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `partner_account_quota_credit` MODIFY `charge_transaction_id` VARCHAR(191) NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `partner_account_quota_credit` ADD CONSTRAINT `partner_account_quota_credit_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `partner_account_quota_charge_transaction`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_account_allocation` ADD CONSTRAINT `license_account_allocation_license_activation_id_fkey` FOREIGN KEY (`license_activation_id`) REFERENCES `licenses_activated`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_account_allocation` ADD CONSTRAINT `license_account_allocation_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -11,9 +11,10 @@ model ConsumerAccount {
|
||||
account_id String @unique()
|
||||
account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
pos Pos?
|
||||
permission PermissionConsumer?
|
||||
sales_invoices SalesInvoice[]
|
||||
pos Pos?
|
||||
permission PermissionConsumer?
|
||||
account_allocation LicenseAccountAllocation?
|
||||
sales_invoices SalesInvoice[]
|
||||
|
||||
@@map("consumer_accounts")
|
||||
}
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
model License {
|
||||
id String @id @default(ulid())
|
||||
accounts_limit Int @default(2)
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
charge_transaction_id String
|
||||
charge_transaction LicenseChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
|
||||
activation LicenseActivation?
|
||||
account_allocations PartnerAccountQuotaAllocation[]
|
||||
|
||||
@@map("licenses")
|
||||
}
|
||||
|
||||
model LicenseActivation {
|
||||
id String @id @unique() @default(ulid())
|
||||
starts_at DateTime
|
||||
expires_at DateTime
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
license_id String @unique
|
||||
license License @relation(fields: [license_id], references: [id])
|
||||
|
||||
business_activity_id String @unique
|
||||
business_activity BusinessActivity @relation(fields: [business_activity_id], references: [id])
|
||||
license_renews LicenseRenew[]
|
||||
|
||||
@@map("licenses_activated")
|
||||
}
|
||||
|
||||
model LicenseChargeTransaction {
|
||||
id String @id @default(ulid())
|
||||
activation_expires_at DateTime
|
||||
@@ -49,20 +15,39 @@ model LicenseChargeTransaction {
|
||||
@@map("license_charged_transactions")
|
||||
}
|
||||
|
||||
model LicenseRenew {
|
||||
id String @id @default(ulid())
|
||||
expires_at DateTime
|
||||
model License {
|
||||
id String @id @default(ulid())
|
||||
accounts_limit Int @default(2)
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
charge_transaction_id String
|
||||
charge_transaction LicenseRenewChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
charge_transaction LicenseChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
|
||||
activation_id String
|
||||
activation LicenseActivation @relation(fields: [activation_id], references: [id])
|
||||
activation LicenseActivation?
|
||||
|
||||
@@map("license_renew")
|
||||
@@map("licenses")
|
||||
}
|
||||
|
||||
model LicenseActivation {
|
||||
id String @id @unique() @default(ulid())
|
||||
starts_at DateTime
|
||||
expires_at DateTime
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
license_id String @unique
|
||||
license License @relation(fields: [license_id], references: [id])
|
||||
|
||||
business_activity_id String @unique
|
||||
business_activity BusinessActivity @relation(fields: [business_activity_id], references: [id])
|
||||
|
||||
license_renews LicenseRenew[]
|
||||
account_allocations LicenseAccountAllocation[]
|
||||
|
||||
@@map("licenses_activated")
|
||||
}
|
||||
|
||||
model LicenseRenewChargeTransaction {
|
||||
@@ -82,6 +67,22 @@ model LicenseRenewChargeTransaction {
|
||||
@@map("license_renew_charge_transaction")
|
||||
}
|
||||
|
||||
model LicenseRenew {
|
||||
id String @id @default(ulid())
|
||||
expires_at DateTime
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
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])
|
||||
|
||||
@@map("license_renew")
|
||||
}
|
||||
|
||||
model PartnerAccountQuotaChargeTransaction {
|
||||
id String @id @default(ulid())
|
||||
activation_expires_at DateTime
|
||||
@@ -94,22 +95,39 @@ model PartnerAccountQuotaChargeTransaction {
|
||||
partner_id String
|
||||
partner Partner @relation(fields: [partner_id], references: [id])
|
||||
|
||||
allocations PartnerAccountQuotaAllocation[]
|
||||
credits PartnerAccountQuotaCredit[]
|
||||
|
||||
@@map("partner_account_quota_charge_transaction")
|
||||
}
|
||||
|
||||
model PartnerAccountQuotaAllocation {
|
||||
model PartnerAccountQuotaCredit {
|
||||
id String @id @default(ulid())
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
charge_transaction_id String
|
||||
charge_transaction PartnerAccountQuotaChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
charge_transaction_id String?
|
||||
charge_transaction PartnerAccountQuotaChargeTransaction? @relation(fields: [charge_transaction_id], references: [id])
|
||||
|
||||
license_id String?
|
||||
license License? @relation(fields: [license_id], references: [id])
|
||||
allocation_id String? @unique
|
||||
allocation LicenseAccountAllocation? @relation(fields: [allocation_id], references: [id])
|
||||
|
||||
@@map("partner_account_quota_allocation")
|
||||
@@map("partner_account_quota_credit")
|
||||
}
|
||||
|
||||
model LicenseAccountAllocation {
|
||||
id String @id @default(ulid())
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
license_activation_id String?
|
||||
license_activation LicenseActivation? @relation(fields: [license_activation_id], references: [id])
|
||||
|
||||
account_id String? @unique
|
||||
account ConsumerAccount? @relation(fields: [account_id], references: [id])
|
||||
|
||||
partner_account_quota_credit PartnerAccountQuotaCredit?
|
||||
|
||||
@@map("license_account_allocation")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
partner_id String @unique
|
||||
partner Partner @relation(fields: [partner_id], references: [id])
|
||||
|
||||
account_id String @unique
|
||||
|
||||
Reference in New Issue
Block a user