protcol data commands
This commit is contained in:
parent
475a13ce36
commit
b9b258a1f6
16 changed files with 335 additions and 10 deletions
|
@ -9,6 +9,18 @@ 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";
|
||||
|
||||
/**
|
||||
* @description get all protocols
|
||||
|
@ -98,6 +110,25 @@ export async function getProtocolVotingsById(req: Request, res: Response): Promi
|
|||
res.json(ProtocolVotingFactory.mapToBase(votings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 synchronize protocol by id
|
||||
* @param req {Request} Express req object
|
||||
|
@ -106,6 +137,21 @@ export async function getProtocolVotingsById(req: Request, res: Response): Promi
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -118,6 +164,17 @@ export async function synchronizeProtocolById(req: Request, res: Response): Prom
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -130,6 +187,17 @@ export async function synchronizeProtocolAgendaById(req: Request, res: Response)
|
|||
*/
|
||||
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);
|
||||
}
|
||||
|
@ -142,6 +210,13 @@ export async function synchronizeProtocolDecisonsById(req: Request, res: Respons
|
|||
*/
|
||||
export async function synchronizeProtocolPrecenseById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
let presence = req.body.precense as Array<number>;
|
||||
|
||||
let syncPresence: SynchronizeProtocolPresenceCommand = {
|
||||
memberIds: presence,
|
||||
protocolId,
|
||||
};
|
||||
await ProtocolPresenceCommandHandler.sync(syncPresence);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
@ -154,6 +229,20 @@ export async function synchronizeProtocolPrecenseById(req: Request, res: Respons
|
|||
*/
|
||||
export async function synchronizeProtocolVotingsById(req: Request, res: Response): Promise<any> {
|
||||
let protocolId = parseInt(req.params.protocolId);
|
||||
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,
|
||||
})
|
||||
);
|
||||
await ProtocolDecisionCommandHandler.sync(syncDecision);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue