2025-01-05 14:14:00 +01:00
|
|
|
import { dataSource } from "../../data-source";
|
|
|
|
import { calendar } from "../../entity/club/calendar";
|
|
|
|
import InternalException from "../../exceptions/internalException";
|
2024-10-27 11:47:13 +01:00
|
|
|
|
|
|
|
export default abstract class CalendarService {
|
|
|
|
/**
|
|
|
|
* @description get all calendars
|
|
|
|
* @returns {Promise<Array<calendar>>}
|
|
|
|
*/
|
|
|
|
static async getAll(): Promise<Array<calendar>> {
|
|
|
|
return await dataSource
|
|
|
|
.getRepository(calendar)
|
|
|
|
.createQueryBuilder("calendar")
|
2024-10-28 16:02:56 +01:00
|
|
|
.leftJoinAndSelect("calendar.type", "type")
|
2024-10-27 11:47:13 +01:00
|
|
|
.getMany()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new InternalException("calendars not found", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get calendar by id
|
|
|
|
* @returns {Promise<calendar>}
|
|
|
|
*/
|
2024-11-07 10:49:34 +01:00
|
|
|
static async getById(id: string): Promise<calendar> {
|
2024-10-27 11:47:13 +01:00
|
|
|
return await dataSource
|
|
|
|
.getRepository(calendar)
|
|
|
|
.createQueryBuilder("calendar")
|
2024-10-28 16:02:56 +01:00
|
|
|
.leftJoinAndSelect("calendar.type", "type")
|
2024-10-27 11:47:13 +01:00
|
|
|
.where("calendar.id = :id", { id: id })
|
|
|
|
.getOneOrFail()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new InternalException("calendar not found by id", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get calendar by types
|
|
|
|
* @returns {Promise<Array<calendar>>}
|
|
|
|
*/
|
2024-12-24 14:06:48 +01:00
|
|
|
static async getByTypes(types: Array<number>, addNscdr: boolean = false): Promise<Array<calendar>> {
|
|
|
|
const query = dataSource
|
2024-10-27 11:47:13 +01:00
|
|
|
.getRepository(calendar)
|
|
|
|
.createQueryBuilder("calendar")
|
|
|
|
.leftJoinAndSelect("calendar.type", "type")
|
2024-12-24 14:06:48 +01:00
|
|
|
.where("type.id IN (:...types)", { types: types });
|
|
|
|
|
|
|
|
if (addNscdr) {
|
|
|
|
query.orWhere("type.nscdr = :nscdr", { nscdr: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
return await query
|
2024-10-27 11:47:13 +01:00
|
|
|
.getMany()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new InternalException("calendars not found by types", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get calendar by types nscdr
|
|
|
|
* @returns {Promise<Array<calendar>>}
|
|
|
|
*/
|
|
|
|
static async getByTypeNSCDR(): Promise<Array<calendar>> {
|
|
|
|
return await dataSource
|
|
|
|
.getRepository(calendar)
|
|
|
|
.createQueryBuilder("calendar")
|
|
|
|
.leftJoinAndSelect("calendar.type", "type")
|
2024-11-07 10:49:34 +01:00
|
|
|
.where("type.nscdr = :nscdr", { nscdr: true })
|
2024-10-27 11:47:13 +01:00
|
|
|
.getMany()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new InternalException("calendars not found by type nscdr", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|