2024-10-03 13:31:05 +02:00
|
|
|
import { Request, Response } from "express";
|
|
|
|
import ProtocolService from "../../service/protocolService";
|
|
|
|
import ProtocolFactory from "../../factory/admin/protocol";
|
2024-10-11 14:44:09 +02:00
|
|
|
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";
|
2024-10-13 15:48:01 +02:00
|
|
|
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";
|
2024-10-15 16:25:42 +02:00
|
|
|
import ProtocolVotingCommandHandler from "../../command/protocolVotingCommandHandler";
|
2024-10-03 13:31:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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,
|
|
|
|
});
|
|
|
|
}
|
2024-10-04 12:47:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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));
|
|
|
|
}
|
2024-10-11 14:44:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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));
|
|
|
|
}
|
|
|
|
|
2024-10-13 15:48:01 +02:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2024-10-15 16:25:42 +02:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2024-10-11 14:44:09 +02:00
|
|
|
/**
|
|
|
|
* @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);
|
2024-10-13 15:48:01 +02:00
|
|
|
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);
|
2024-10-11 14:44:09 +02:00
|
|
|
|
|
|
|
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);
|
2024-10-13 15:48:01 +02:00
|
|
|
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);
|
2024-10-11 14:44:09 +02:00
|
|
|
|
|
|
|
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);
|
2024-10-13 15:48:01 +02:00
|
|
|
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);
|
2024-10-11 14:44:09 +02:00
|
|
|
|
|
|
|
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);
|
2024-10-13 15:48:01 +02:00
|
|
|
let decisions = req.body.decisions as Array<ProtocolVotingViewModel>;
|
|
|
|
|
|
|
|
let syncDecision: Array<SynchronizeProtocolVotingCommand> = decisions.map(
|
|
|
|
(d: ProtocolVotingViewModel): SynchronizeProtocolVotingCommand => ({
|
|
|
|
id: d.id ?? null,
|
|
|
|
topic: d.topic,
|
|
|
|
context: d.context,
|
|
|
|
favour: d.favour,
|
|
|
|
abstain: d.abstain,
|
|
|
|
against: d.abstain,
|
|
|
|
protocolId,
|
|
|
|
})
|
|
|
|
);
|
2024-10-15 16:25:42 +02:00
|
|
|
await ProtocolVotingCommandHandler.sync(syncDecision);
|
|
|
|
|
|
|
|
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);
|
2024-10-11 14:44:09 +02:00
|
|
|
|
|
|
|
res.sendStatus(204);
|
|
|
|
}
|