59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
|
import { dataSource } from "../data-source";
|
||
|
import { calendarType } from "../entity/calendarType";
|
||
|
import InternalException from "../exceptions/internalException";
|
||
|
|
||
|
export default abstract class CalendarTypeService {
|
||
|
/**
|
||
|
* @description get all calendar types
|
||
|
* @returns {Promise<Array<calendarType>>}
|
||
|
*/
|
||
|
static async getAll(): Promise<Array<calendarType>> {
|
||
|
return await dataSource
|
||
|
.getRepository(calendarType)
|
||
|
.createQueryBuilder("calendarType")
|
||
|
.getMany()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("calendarTypes not found", err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @description get calendar type by id
|
||
|
* @returns {Promise<calendarType>}
|
||
|
*/
|
||
|
static async getById(id: number): Promise<calendarType> {
|
||
|
return await dataSource
|
||
|
.getRepository(calendarType)
|
||
|
.createQueryBuilder("calendarType")
|
||
|
.where("calendarType.id = :id", { id: id })
|
||
|
.getOneOrFail()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("calendarType not found by id", err);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @description get calendar by names
|
||
|
* @returns {Promise<Array<calendarType>>}
|
||
|
*/
|
||
|
static async getByTypes(names: Array<string>): Promise<Array<calendarType>> {
|
||
|
return await dataSource
|
||
|
.getRepository(calendarType)
|
||
|
.createQueryBuilder("calendarType")
|
||
|
.where("calendarType.type IN (:...names)", { names: names })
|
||
|
.getMany()
|
||
|
.then((res) => {
|
||
|
return res;
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
throw new InternalException("calendarTypes not found by names", err);
|
||
|
});
|
||
|
}
|
||
|
}
|