salutation CRUD and controller

This commit is contained in:
Julian Krauser 2025-01-25 11:58:10 +01:00
parent b55d0554e4
commit 1ab4d93d2b
10 changed files with 288 additions and 3 deletions

View file

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