extend calendar link
This commit is contained in:
parent
020ae4a939
commit
e9b29f8acf
2 changed files with 14 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue