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
@@ -19,15 +19,7 @@ export class BusinessActivitiesService {
name: true,
},
},
complexes: {
select: {
_count: {
select: {
pos_list: true,
},
},
},
},
license_activation: {
select: {
id: true,
@@ -35,10 +27,14 @@ export class BusinessActivitiesService {
expires_at: true,
license: {
select: {
accounts_limit: true,
_count: {
activation: {
select: {
account_allocations: true,
account_allocations: {
select: {
id: true,
account_id: true,
},
},
},
},
},
@@ -50,17 +46,16 @@ export class BusinessActivitiesService {
private readonly prepareBusinessActivityResponse = (businessActivity: any) => {
const { license_activation, complexes, ...rest } = businessActivity
const { license, ...license_activation_rest } = license_activation
const { accounts_limit, _count } = license
const { account_allocations } = license.activation
return {
...rest,
license_info: {
...license_activation_rest,
accounts_limit: accounts_limit + _count.account_allocations,
allocated_account_count: complexes.reduce(
(acc: number, complex: any) => acc + complex._count.pos_list,
0,
),
accounts_limit: account_allocations.length,
allocated_account_count: account_allocations.filter(
allocation => allocation.account_id,
).length,
},
}
}