import { dataSource } from "../../data-source"; import { templateUsage } from "../../entity/settings/templateUsage"; import InternalException from "../../exceptions/internalException"; export default abstract class TemplateUsageService { /** * @description get all templateUsages * @returns {Promise>} */ static async getAll(): Promise> { return await dataSource .getRepository(templateUsage) .createQueryBuilder("templateUsage") .leftJoinAndSelect("templateUsage.header", "headerTemplate") .leftJoinAndSelect("templateUsage.body", "bodyTemplate") .leftJoinAndSelect("templateUsage.footer", "footerTemplate") .orderBy("scope", "ASC") .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("templates not found", err); }); } /** * @description get template by scope * @returns {Promise} */ static async getByScope(scope: string): Promise { return await dataSource .getRepository(templateUsage) .createQueryBuilder("templateUsage") .leftJoinAndSelect("templateUsage.header", "headerTemplate") .leftJoinAndSelect("templateUsage.body", "bodyTemplate") .leftJoinAndSelect("templateUsage.footer", "footerTemplate") .where("templateUsage.scope = :scope", { scope: scope }) .getOneOrFail() .then((res) => { return res; }) .catch((err): null => { return null; }); } }