return json or ics and provide all day entries
This commit is contained in:
parent
8b7bbf8edd
commit
597feef9ef
1 changed files with 63 additions and 39 deletions
|
@ -4,6 +4,8 @@ import CalendarTypeService from "../service/calendarTypeService";
|
||||||
import { calendar } from "../entity/calendar";
|
import { calendar } from "../entity/calendar";
|
||||||
import { createEvents } from "ics";
|
import { createEvents } from "ics";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import InternalException from "../exceptions/internalException";
|
||||||
|
import CalendarFactory from "../factory/admin/calendar";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get all calendar items by types or nscdr
|
* @description get all calendar items by types or nscdr
|
||||||
|
@ -13,6 +15,11 @@ import moment from "moment";
|
||||||
*/
|
*/
|
||||||
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
|
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
|
||||||
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
|
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
|
||||||
|
let output = (req.query.output as "ics" | "json") ?? "ics";
|
||||||
|
|
||||||
|
if (output != "ics" && output != "json") {
|
||||||
|
throw new InternalException("set output query value to `ics` or `json` (defaults to `ics`)");
|
||||||
|
}
|
||||||
|
|
||||||
let items: Array<calendar> = [];
|
let items: Array<calendar> = [];
|
||||||
if (types.length == 0) {
|
if (types.length == 0) {
|
||||||
|
@ -22,45 +29,62 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom
|
||||||
items = await CalendarService.getByTypeNSCDR();
|
items = await CalendarService.getByTypeNSCDR();
|
||||||
}
|
}
|
||||||
|
|
||||||
let events = createEvents(
|
if (output == "json") {
|
||||||
items.map((i) => ({
|
res.json(CalendarFactory.mapToBase(items));
|
||||||
calName: process.env.CLUB_NAME,
|
} else {
|
||||||
uid: i.id,
|
let events = createEvents(
|
||||||
sequence: 1,
|
items.map((i) => ({
|
||||||
start: moment(i.starttime)
|
calName: process.env.CLUB_NAME,
|
||||||
.format("YYYY-M-D-H-m")
|
uid: i.id,
|
||||||
.split("-")
|
sequence: 1,
|
||||||
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
...(i.allDay
|
||||||
end: moment(i.endtime)
|
? {
|
||||||
.format("YYYY-M-D-H-m")
|
start: moment(i.starttime)
|
||||||
.split("-")
|
.format("YYYY-M-D")
|
||||||
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
.split("-")
|
||||||
title: i.title,
|
.map((a) => parseInt(a)) as [number, number, number],
|
||||||
description: i.content,
|
end: moment(i.endtime)
|
||||||
location: i.location,
|
.format("YYYY-M-D")
|
||||||
categories: [i.type.type],
|
.split("-")
|
||||||
created: moment(i.createdAt)
|
.map((a) => parseInt(a)) as [number, number, number],
|
||||||
.format("YYYY-M-D-H-m")
|
}
|
||||||
.split("-")
|
: {
|
||||||
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
start: moment(i.starttime)
|
||||||
lastModified: moment(i.updatedAt)
|
.format("YYYY-M-D-H-m")
|
||||||
.format("YYYY-M-D-H-m")
|
.split("-")
|
||||||
.split("-")
|
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
||||||
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
end: moment(i.endtime)
|
||||||
transp: "OPAQUE" as "OPAQUE",
|
.format("YYYY-M-D-H-m")
|
||||||
url: "https://www.ff-merching.de",
|
.split("-")
|
||||||
alarms: [
|
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
||||||
{
|
}),
|
||||||
action: "display",
|
title: i.title,
|
||||||
description: "Erinnerung",
|
description: i.content,
|
||||||
trigger: {
|
location: i.location,
|
||||||
minutes: 30,
|
categories: [i.type.type],
|
||||||
before: true,
|
created: moment(i.createdAt)
|
||||||
|
.format("YYYY-M-D-H-m")
|
||||||
|
.split("-")
|
||||||
|
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
||||||
|
lastModified: moment(i.updatedAt)
|
||||||
|
.format("YYYY-M-D-H-m")
|
||||||
|
.split("-")
|
||||||
|
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
||||||
|
transp: "OPAQUE" as "OPAQUE",
|
||||||
|
url: "https://www.ff-merching.de",
|
||||||
|
alarms: [
|
||||||
|
{
|
||||||
|
action: "display",
|
||||||
|
description: "Erinnerung",
|
||||||
|
trigger: {
|
||||||
|
minutes: 30,
|
||||||
|
before: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
}))
|
||||||
}))
|
);
|
||||||
);
|
|
||||||
|
|
||||||
res.type("ics").send(events.value);
|
res.type("ics").send(events.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue