Merge branch 'main' into #1-account-management
# Conflicts: # src/data-source.ts
This commit is contained in:
commit
273745f830
66 changed files with 3721 additions and 10 deletions
201
src/controller/admin/calendarController.ts
Normal file
201
src/controller/admin/calendarController.ts
Normal file
|
@ -0,0 +1,201 @@
|
|||
import { Request, Response } from "express";
|
||||
import CalendarService from "../../service/calendarService";
|
||||
import CalendarFactory from "../../factory/admin/calendar";
|
||||
import CalendarTypeService from "../../service/calendarTypeService";
|
||||
import CalendarTypeFactory from "../../factory/admin/calendarType";
|
||||
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "../../command/calendarCommand";
|
||||
import CalendarCommandHandler from "../../command/calendarCommandHandler";
|
||||
import {
|
||||
CreateCalendarTypeCommand,
|
||||
DeleteCalendarTypeCommand,
|
||||
UpdateCalendarTypeCommand,
|
||||
} from "../../command/calendarTypeCommand";
|
||||
import CalendarTypeCommandHandler from "../../command/calendarTypeCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all calendar items
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllCalendarItems(req: Request, res: Response): Promise<any> {
|
||||
let items = await CalendarService.getAll();
|
||||
|
||||
res.json(CalendarFactory.mapToBase(items));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get calendar item by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getCalendarItemById(req: Request, res: Response): Promise<any> {
|
||||
const id = req.params.id;
|
||||
let item = await CalendarService.getById(id);
|
||||
|
||||
res.json(CalendarFactory.mapToSingle(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get all calendar types
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllCalendarTypes(req: Request, res: Response): Promise<any> {
|
||||
let types = await CalendarTypeService.getAll();
|
||||
|
||||
res.json(CalendarTypeFactory.mapToBase(types));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get calendar type by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getCalendarTypeById(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
let type = await CalendarTypeService.getById(id);
|
||||
|
||||
res.json(CalendarTypeFactory.mapToSingle(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create calendar item
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createCalendarItem(req: Request, res: Response): Promise<any> {
|
||||
const starttime = req.body.starttime;
|
||||
const endtime = req.body.endtime;
|
||||
const title = req.body.title;
|
||||
const content = req.body.content;
|
||||
const location = req.body.location;
|
||||
const allDay = req.body.allDay;
|
||||
const typeId = req.body.typeId;
|
||||
|
||||
let createItem: CreateCalendarCommand = {
|
||||
starttime,
|
||||
endtime,
|
||||
title,
|
||||
content,
|
||||
location,
|
||||
allDay,
|
||||
typeId,
|
||||
};
|
||||
let id = await CalendarCommandHandler.create(createItem);
|
||||
|
||||
res.send(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create calendar type
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createCalendarType(req: Request, res: Response): Promise<any> {
|
||||
const type = req.body.type;
|
||||
const nscdr = req.body.nscdr;
|
||||
const color = req.body.color;
|
||||
|
||||
let createType: CreateCalendarTypeCommand = {
|
||||
type,
|
||||
nscdr,
|
||||
color,
|
||||
};
|
||||
let id = await CalendarTypeCommandHandler.create(createType);
|
||||
|
||||
res.send(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendar item
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateCalendarItem(req: Request, res: Response): Promise<any> {
|
||||
const id = req.params.id;
|
||||
const starttime = req.body.starttime;
|
||||
const endtime = req.body.endtime;
|
||||
const title = req.body.title;
|
||||
const content = req.body.content;
|
||||
const location = req.body.location;
|
||||
const allDay = req.body.allDay;
|
||||
const typeId = req.body.typeId;
|
||||
|
||||
let updateItem: UpdateCalendarCommand = {
|
||||
id,
|
||||
starttime,
|
||||
endtime,
|
||||
title,
|
||||
content,
|
||||
location,
|
||||
allDay,
|
||||
typeId,
|
||||
};
|
||||
await CalendarCommandHandler.update(updateItem);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendar type
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateCalendarType(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
const type = req.body.type;
|
||||
const nscdr = req.body.nscdr;
|
||||
const color = req.body.color;
|
||||
|
||||
let updateType: UpdateCalendarTypeCommand = {
|
||||
id,
|
||||
type,
|
||||
nscdr,
|
||||
color,
|
||||
};
|
||||
await CalendarTypeCommandHandler.update(updateType);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendar item
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function deleteCalendarItem(req: Request, res: Response): Promise<any> {
|
||||
const id = req.params.id;
|
||||
|
||||
let deleteItem: DeleteCalendarCommand = {
|
||||
id,
|
||||
};
|
||||
await CalendarCommandHandler.delete(deleteItem);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendar type
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function deleteCalendarType(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
|
||||
let deleteType: DeleteCalendarTypeCommand = {
|
||||
id,
|
||||
};
|
||||
await CalendarTypeCommandHandler.delete(deleteType);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
386
src/controller/admin/protocolController.ts
Normal file
386
src/controller/admin/protocolController.ts
Normal file
|
@ -0,0 +1,386 @@
|
|||
import { Request, Response } from "express";
|
||||
import ProtocolService from "../../service/protocolService";
|
||||
import ProtocolFactory from "../../factory/admin/protocol";
|
||||
import ProtocolAgendaService from "../../service/protocolAgendaService";
|
||||
import ProtocolAgendaFactory from "../../factory/admin/protocolAgenda";
|
||||
import ProtocolDecisionService from "../../service/protocolDecisionService";
|
||||
import ProtocolDecisionFactory from "../../factory/admin/protocolDecision";
|
||||
import ProtocolPresenceService from "../../service/protocolPrecenseService";
|
||||
import ProtocolPresenceFactory from "../../factory/admin/protocolPresence";
|
||||
import ProtocolVotingService from "../../service/protocolVotingService";
|
||||
import ProtocolVotingFactory from "../../factory/admin/protocolVoting";
|
||||
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "../../command/protocolCommand";
|
||||
import ProtocolCommandHandler from "../../command/protocolCommandHandler";
|
||||
import { SynchronizeProtocolAgendaCommand } from "../../command/protocolAgendaCommand";
|
||||
import ProtocolAgendaCommandHandler from "../../command/protocolAgendaCommandHandler";
|
||||
import { ProtocolAgendaViewModel } from "../../viewmodel/admin/protocolAgenda.models";
|
||||
import ProtocolDecisionCommandHandler from "../../command/protocolDecisionCommandHandler";
|
||||
import { ProtocolDecisionViewModel } from "../../viewmodel/admin/protocolDecision.models";
|
||||
import ProtocolPresenceCommandHandler from "../../command/protocolPresenceCommandHandler";
|
||||
import { SynchronizeProtocolPresenceCommand } from "../../command/protocolPresenceCommand";
|
||||
import { SynchronizeProtocolDecisionCommand } from "../../command/protocolDecisionCommand";
|
||||
import { SynchronizeProtocolVotingCommand } from "../../command/protocolVotingCommand";
|
||||
import { ProtocolVotingViewModel } from "../../viewmodel/admin/protocolVoting.models";
|
||||
import ProtocolVotingCommandHandler from "../../command/protocolVotingCommandHandler";
|
||||
import { PdfExport } from "../../helpers/pdfExport";
|
||||
import ProtocolPrintoutService from "../../service/protocolPrintoutService";
|
||||
import ProtocolPrintoutFactory from "../../factory/admin/protocolPrintout";
|
||||
import { CreateProtocolPrintoutCommand } from "../../command/protocolPrintoutCommand";
|
||||
import ProtocolPrintoutCommandHandler from "../../command/protocolPrintoutCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all protocols
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllProtocols(req: Request, res: Response): Promise<any> {
|
||||
let offset = parseInt((req.query.offset as string) ?? "0");
|
||||
let count = parseInt((req.query.count as string) ?? "25");
|
||||
let [protocols, total] = await ProtocolService.getAll(offset, count);
|
||||
|
||||
res.json({
|
||||
protocols: ProtocolFactory.mapToBase(protocols),
|
||||
total: total,
|
||||
offset: offset,
|
||||
count: count,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolById(req: Request, res: Response): Promise<any> {
|
||||
let id = parseInt(req.params.id);
|
||||
let protocol = await ProtocolService.getById(id);
|
||||
|
||||
res.json(ProtocolFactory.mapToSingle(protocol));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol agenda by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolAgendaById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let agenda = await ProtocolAgendaService.getAll(protocolId);
|
||||
|
||||
res.json(ProtocolAgendaFactory.mapToBase(agenda));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol decisions by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolDecisonsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let decisions = await ProtocolDecisionService.getAll(protocolId);
|
||||
|
||||
res.json(ProtocolDecisionFactory.mapToBase(decisions));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol precense by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolPrecenseById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let presence = await ProtocolPresenceService.getAll(protocolId);
|
||||
|
||||
res.json(ProtocolPresenceFactory.mapToBase(presence));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol votings by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let votings = await ProtocolVotingService.getAll(protocolId);
|
||||
|
||||
res.json(ProtocolVotingFactory.mapToBase(votings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol printouts by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolPrintoutsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let printouts = await ProtocolPrintoutService.getAll(protocolId);
|
||||
|
||||
res.json(ProtocolPrintoutFactory.mapToBase(printouts));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get protocol printout by id and print
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getProtocolPrintoutByIdAndPrint(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let printoutId = parseInt(req.params.printoutId);
|
||||
|
||||
let printout = await ProtocolPrintoutService.getById(printoutId, protocolId);
|
||||
|
||||
res.sendFile(process.cwd() + `/export/${printout.filename}.pdf`, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create protocol
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createProtocol(req: Request, res: Response): Promise<any> {
|
||||
let title = req.body.title;
|
||||
let date = req.body.date;
|
||||
|
||||
let createProtocol: CreateProtocolCommand = {
|
||||
title,
|
||||
date,
|
||||
};
|
||||
let id = await ProtocolCommandHandler.create(createProtocol);
|
||||
|
||||
res.send(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create protocol agenda by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createProtocolAgendaById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let agenda = await ProtocolAgendaCommandHandler.create(protocolId);
|
||||
|
||||
res.send(agenda);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create protocol decisions by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createProtocolDecisonsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let decision = await ProtocolDecisionCommandHandler.create(protocolId);
|
||||
|
||||
res.send(decision);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create protocol votings by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
|
||||
let voting = await ProtocolVotingCommandHandler.create(protocolId);
|
||||
|
||||
res.send(voting);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create protocol printout by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createProtocolPrintoutById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let protocol = await ProtocolService.getById(protocolId);
|
||||
let agenda = await ProtocolAgendaService.getAll(protocolId);
|
||||
let decisions = await ProtocolDecisionService.getAll(protocolId);
|
||||
let presence = await ProtocolPresenceService.getAll(protocolId);
|
||||
let votings = await ProtocolVotingService.getAll(protocolId);
|
||||
let iteration = await ProtocolPrintoutService.getCount(protocolId);
|
||||
|
||||
let title = `Sitzungsprotokoll - ${new Date(protocol.date).toLocaleDateString("de-DE", {
|
||||
day: "2-digit",
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
})}`;
|
||||
|
||||
let filename = `P_${protocol.title.replace(/[^a-zA-Z0-9]/g, "")}_${iteration + 1}_${new Date().toLocaleDateString()}`;
|
||||
|
||||
await PdfExport.renderFile({
|
||||
template: "protocol.template.html",
|
||||
title,
|
||||
filename,
|
||||
data: {
|
||||
title: protocol.title,
|
||||
summary: protocol.summary,
|
||||
iteration: iteration + 1,
|
||||
date: new Date(protocol.date).toLocaleDateString("de-DE", {
|
||||
weekday: "long",
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
}),
|
||||
start: protocol.starttime,
|
||||
end: protocol.endtime,
|
||||
agenda,
|
||||
decisions,
|
||||
presence: presence.map((p) => p.member),
|
||||
votings,
|
||||
},
|
||||
});
|
||||
|
||||
let printout: CreateProtocolPrintoutCommand = {
|
||||
title,
|
||||
iteration: iteration + 1,
|
||||
filename,
|
||||
protocolId,
|
||||
};
|
||||
await ProtocolPrintoutCommandHandler.create(printout);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description synchronize protocol by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function synchronizeProtocolById(req: Request, res: Response): Promise<any> {
|
||||
let id = parseInt(req.params.id);
|
||||
let title = req.body.title;
|
||||
let date = req.body.date;
|
||||
let starttime = req.body.starttime;
|
||||
let endtime = req.body.endtime;
|
||||
let summary = req.body.summary;
|
||||
|
||||
let syncProtocol: SynchronizeProtocolCommand = {
|
||||
id,
|
||||
title,
|
||||
date,
|
||||
starttime,
|
||||
endtime,
|
||||
summary,
|
||||
};
|
||||
await ProtocolCommandHandler.sync(syncProtocol);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description synchronize protocol agenda by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function synchronizeProtocolAgendaById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let agenda = req.body.agenda as Array<ProtocolAgendaViewModel>;
|
||||
|
||||
let syncAgenda: Array<SynchronizeProtocolAgendaCommand> = agenda.map(
|
||||
(a: ProtocolAgendaViewModel): SynchronizeProtocolAgendaCommand => ({
|
||||
id: a.id ?? null,
|
||||
topic: a.topic,
|
||||
context: a.context,
|
||||
protocolId,
|
||||
})
|
||||
);
|
||||
await ProtocolAgendaCommandHandler.sync(syncAgenda);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description synchronize protocol decisions by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function synchronizeProtocolDecisonsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let decisions = req.body.decisions as Array<ProtocolDecisionViewModel>;
|
||||
|
||||
let syncDecision: Array<SynchronizeProtocolDecisionCommand> = decisions.map(
|
||||
(d: ProtocolDecisionViewModel): SynchronizeProtocolDecisionCommand => ({
|
||||
id: d.id ?? null,
|
||||
topic: d.topic,
|
||||
context: d.context,
|
||||
protocolId,
|
||||
})
|
||||
);
|
||||
await ProtocolDecisionCommandHandler.sync(syncDecision);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description synchronize protocol votings by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function synchronizeProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let votings = req.body.votings as Array<ProtocolVotingViewModel>;
|
||||
|
||||
let syncVoting: Array<SynchronizeProtocolVotingCommand> = votings.map(
|
||||
(d: ProtocolVotingViewModel): SynchronizeProtocolVotingCommand => ({
|
||||
id: d.id ?? null,
|
||||
topic: d.topic,
|
||||
context: d.context,
|
||||
favour: d.favour,
|
||||
abstain: d.abstain,
|
||||
against: d.abstain,
|
||||
protocolId,
|
||||
})
|
||||
);
|
||||
await ProtocolVotingCommandHandler.sync(syncVoting);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description synchronize protocol precense by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function synchronizeProtocolPrecenseById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let presence = req.body.presence as Array<number>;
|
||||
|
||||
let syncPresence: SynchronizeProtocolPresenceCommand = {
|
||||
memberIds: presence,
|
||||
protocolId,
|
||||
};
|
||||
await ProtocolPresenceCommandHandler.sync(syncPresence);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
66
src/controller/publicController.ts
Normal file
66
src/controller/publicController.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { Request, Response } from "express";
|
||||
import CalendarService from "../service/calendarService";
|
||||
import CalendarTypeService from "../service/calendarTypeService";
|
||||
import { calendar } from "../entity/calendar";
|
||||
import { createEvents } from "ics";
|
||||
import moment from "moment";
|
||||
|
||||
/**
|
||||
* @description get all calendar items by types or nscdr
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
|
||||
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
|
||||
|
||||
let items: Array<calendar> = [];
|
||||
if (types.length == 0) {
|
||||
let typeIds = await CalendarTypeService.getByTypes(types as Array<string>);
|
||||
items = await CalendarService.getByTypes(typeIds.map((t) => t.id));
|
||||
} else {
|
||||
items = await CalendarService.getByTypeNSCDR();
|
||||
}
|
||||
|
||||
let events = createEvents(
|
||||
items.map((i) => ({
|
||||
calName: process.env.CLUB_NAME,
|
||||
uid: i.id,
|
||||
sequence: 1,
|
||||
start: moment(i.starttime)
|
||||
.format("YYYY-M-D-H-m")
|
||||
.split("-")
|
||||
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
||||
end: moment(i.endtime)
|
||||
.format("YYYY-M-D-H-m")
|
||||
.split("-")
|
||||
.map((a) => parseInt(a)) as [number, number, number, number, number],
|
||||
title: i.title,
|
||||
description: i.content,
|
||||
location: i.location,
|
||||
categories: [i.type.type],
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue