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:
2026-04-24 23:02:05 +03:30
parent 9b652a3603
commit 12506de863
43 changed files with 4645 additions and 2196 deletions
@@ -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;