template preparation
This commit is contained in:
parent
5f18e614be
commit
6cb8ca0a12
16 changed files with 414 additions and 21 deletions
46
src/service/templateUsageService.ts
Normal file
46
src/service/templateUsageService.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { templateUsage } from "../entity/templateUsage";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
|
||||
export default abstract class TemplateUsageService {
|
||||
/**
|
||||
* @description get all templateUsages
|
||||
* @returns {Promise<Array<templateUsage>>}
|
||||
*/
|
||||
static async getAll(): Promise<Array<templateUsage>> {
|
||||
return await dataSource
|
||||
.getRepository(templateUsage)
|
||||
.createQueryBuilder("templateUsage")
|
||||
.leftJoinAndSelect("templateUsage.header", "headerTemplate")
|
||||
.leftJoinAndSelect("templateUsage.body", "bodyTemplate")
|
||||
.leftJoinAndSelect("templateUsage.footer", "footerTemplate")
|
||||
.getMany()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("templates not found", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get template by scope
|
||||
* @returns {Promise<templateUsage>}
|
||||
*/
|
||||
static async getByScope(scope: string): Promise<templateUsage | null> {
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue