Files
n8n-enterprise-unlocked/packages/cli/src/license/License.service.ts
कारतोफ्फेलस्क्रिप्ट™ 000e76e3b4 ci(core): Reduce memory usage in tests (part-2) (no-changelog) (#7671)
This also gets rid of `Db.collection`, which was another source of
circular dependencies.
2023-11-10 15:04:26 +01:00

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(),
},
};
}
}