template storing

This commit is contained in:
Julian Krauser 2024-12-22 10:29:42 +01:00
parent 98477eafde
commit 160d82459d
12 changed files with 386 additions and 1 deletions

View file

@ -0,0 +1,41 @@
import { dataSource } from "../data-source";
import { template } from "../entity/template";
import { member } from "../entity/member";
import InternalException from "../exceptions/internalException";
export default abstract class TemplateService {
/**
* @description get all templates
* @returns {Promise<Array<template>>}
*/
static async getAll(): Promise<Array<template>> {
return await dataSource
.getRepository(template)
.createQueryBuilder("template")
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("templates not found", err);
});
}
/**
* @description get template by id
* @returns {Promise<template>}
*/
static async getById(id: number): Promise<template> {
return await dataSource
.getRepository(template)
.createQueryBuilder("template")
.where("template.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("template not found by id", err);
});
}
}