#6-messages #24

Merged
jkeffects merged 16 commits from #6-messages into main 2024-12-31 13:25:12 +00:00
2 changed files with 14 additions and 4 deletions
Showing only changes of commit e9b29f8acf - Show all commits

View file

@ -16,6 +16,7 @@ import CalendarFactory from "../factory/admin/calendar";
*/
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
let nscdr = req.query.nscdr == "true";
let output = (req.query.output as "ics" | "json") ?? "ics";
if (output != "ics" && output != "json") {
@ -33,7 +34,10 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom
ti.passphrase == "" ||
ti.passphrase == (types as Array<string>).find((t) => t.includes(ti.type)).split(":")[1]
);
items = await CalendarService.getByTypes(typeIds.map((t) => t.id));
items = await CalendarService.getByTypes(
typeIds.map((t) => t.id),
nscdr
);
} else {
items = await CalendarService.getByTypeNSCDR();
}

View file

@ -44,12 +44,18 @@ export default abstract class CalendarService {
* @description get calendar by types
* @returns {Promise<Array<calendar>>}
*/
static async getByTypes(types: Array<number>): Promise<Array<calendar>> {
return await dataSource
static async getByTypes(types: Array<number>, addNscdr: boolean = false): Promise<Array<calendar>> {
const query = dataSource
.getRepository(calendar)
.createQueryBuilder("calendar")
.leftJoinAndSelect("calendar.type", "type")
.where("type.id IN (:...types)", { types: types })
.where("type.id IN (:...types)", { types: types });
if (addNscdr) {
query.orWhere("type.nscdr = :nscdr", { nscdr: true });
}
return await query
.getMany()
.then((res) => {
return res;