calender crud operations

This commit is contained in:
Julian Krauser 2024-10-27 11:47:13 +01:00
parent e7b8257336
commit bf701163d6
18 changed files with 703 additions and 0 deletions

View file

@ -0,0 +1,78 @@
import { dataSource } from "../data-source";
import { calendar } from "../entity/calendar";
import InternalException from "../exceptions/internalException";
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")
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("calendars not found", err);
});
}
/**
* @description get calendar by id
* @returns {Promise<calendar>}
*/
static async getById(id: number): Promise<calendar> {
return await dataSource
.getRepository(calendar)
.createQueryBuilder("calendar")
.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>>}
*/
static async getByTypes(types: Array<number>): Promise<Array<calendar>> {
return await dataSource
.getRepository(calendar)
.createQueryBuilder("calendar")
.leftJoinAndSelect("calendar.type", "type")
.where("type.id IN (:...types)", { types: types })
.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")
.where("type.nscdr = :nscdr)", { nscdr: true })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("calendars not found by type nscdr", err);
});
}
}

View file

@ -0,0 +1,58 @@
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);
});
}
}