41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { dataSource } from "../../data-source";
|
|
import { education } from "../../entity/configuration/education";
|
|
import DatabaseActionException from "../../exceptions/databaseActionException";
|
|
|
|
export default abstract class EducationService {
|
|
/**
|
|
* @description get all educations
|
|
* @returns {Promise<Array<education>>}
|
|
*/
|
|
static async getAll(): Promise<Array<education>> {
|
|
return await dataSource
|
|
.getRepository(education)
|
|
.createQueryBuilder("education")
|
|
.orderBy("education", "ASC")
|
|
.getMany()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "education", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description get education by id
|
|
* @returns {Promise<education>}
|
|
*/
|
|
static async getById(id: number): Promise<education> {
|
|
return await dataSource
|
|
.getRepository(education)
|
|
.createQueryBuilder("education")
|
|
.where("education.id = :id", { id: id })
|
|
.getOneOrFail()
|
|
.then((res) => {
|
|
return res;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("SELECT", "education", err);
|
|
});
|
|
}
|
|
}
|