mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
This also gets rid of `Db.collection`, which was another source of circular dependencies.
35 lines
984 B
TypeScript
35 lines
984 B
TypeScript
import { Container } from 'typedi';
|
|
import { License } from '@/License';
|
|
import type { ILicenseReadResponse } from '@/Interfaces';
|
|
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
|
|
|
export class LicenseService {
|
|
static async getActiveTriggerCount(): Promise<number> {
|
|
const totalTriggerCount = await Container.get(WorkflowRepository).sum('triggerCount', {
|
|
active: true,
|
|
});
|
|
return totalTriggerCount ?? 0;
|
|
}
|
|
|
|
// Helper for getting the basic license data that we want to return
|
|
static async getLicenseData(): Promise<ILicenseReadResponse> {
|
|
const triggerCount = await LicenseService.getActiveTriggerCount();
|
|
const license = Container.get(License);
|
|
const mainPlan = license.getMainPlan();
|
|
|
|
return {
|
|
usage: {
|
|
executions: {
|
|
value: triggerCount,
|
|
limit: license.getTriggerLimit(),
|
|
warningThreshold: 0.8,
|
|
},
|
|
},
|
|
license: {
|
|
planId: mainPlan?.productId ?? '',
|
|
planName: license.getPlanName(),
|
|
},
|
|
};
|
|
}
|
|
}
|