Files
Automata/packages/cli/src/license/License.service.ts
कारतोफ्फेलस्क्रिप्ट™ 9bd7529193 refactor(core): Use an IoC container to manage singleton classes [Part-2] (no-changelog) (#5690)
* use typedi for UserManagementMailer

* use typedi for SamlService

* fix typos

* use typedi for Queue

* use typedi for License

* convert some more code to use typedi
2023-03-16 15:34:13 +01:00

33 lines
921 B
TypeScript

import { Container } from 'typedi';
import { License } from '@/License';
import type { ILicenseReadResponse } from '@/Interfaces';
import * as Db from '@/Db';
export class LicenseService {
static async getActiveTriggerCount(): Promise<number> {
const totalTriggerCount = await Db.collections.Workflow.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(),
},
};
}
}