protcol table services

This commit is contained in:
Julian Krauser 2024-10-11 14:44:09 +02:00
parent dd74005043
commit 475a13ce36
19 changed files with 502 additions and 10 deletions

View file

@ -1,6 +1,14 @@
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";
/**
* @description get all protocols
@ -33,3 +41,119 @@ export async function getProtocolById(req: Request, res: Response): Promise<any>
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 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);
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);
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);
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);
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);
res.sendStatus(204);
}

View file

@ -33,10 +33,11 @@ import { protocol } from "./entity/protocol";
import { ProtocolInit1727953803404 } from "./migrations/1727953803404-protocol-init";
import { ProtocolBase1728037129072 } from "./migrations/1728037129072-protocolBase";
import { protocolAgenda } from "./entity/protocolAgenda";
import { protocolDecisions } from "./entity/protocolDecisions";
import { protocolDecision } from "./entity/protocolDecision";
import { protocolPresence } from "./entity/protocolPresence";
import { protocolVotings } from "./entity/protocolVotings";
import { protocolVoting } from "./entity/protocolVoting";
import { ProtocolTables1728563204766 } from "./migrations/1728563204766-protocolTables";
import { ProtocolTableRename1728645611919 } from "./migrations/1728645611919-protocolTableRename";
const dataSource = new DataSource({
type: DB_TYPE as any,
@ -68,9 +69,9 @@ const dataSource = new DataSource({
membership,
protocol,
protocolAgenda,
protocolDecisions,
protocolDecision,
protocolPresence,
protocolVotings,
protocolVoting,
],
migrations: [
Initial1724317398939,
@ -84,6 +85,7 @@ const dataSource = new DataSource({
ProtocolInit1727953803404,
ProtocolBase1728037129072,
ProtocolTables1728563204766,
ProtocolTableRename1728645611919,
],
migrationsRun: true,
migrationsTransactionMode: "each",

View file

@ -4,7 +4,7 @@ import { protocol } from "./protocol";
@Entity()
export class protocolAgenda {
@PrimaryGeneratedColumn("increment")
id: string;
id: number;
@Column({ type: "varchar", length: 255 })
topic: string;

View file

@ -2,9 +2,9 @@ import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { protocol } from "./protocol";
@Entity()
export class protocolDecisions {
export class protocolDecision {
@PrimaryGeneratedColumn("increment")
id: string;
id: number;
@Column({ type: "varchar", length: 255 })
topic: string;

View file

@ -2,9 +2,9 @@ import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { protocol } from "./protocol";
@Entity()
export class protocolVotings {
export class protocolVoting {
@PrimaryGeneratedColumn("increment")
id: string;
id: number;
@Column({ type: "varchar", length: 255 })
topic: string;

View file

@ -0,0 +1,27 @@
import { protocolAgenda } from "../../entity/protocolAgenda";
import { ProtocolAgendaViewModel } from "../../viewmodel/admin/protocolAgenda.models";
export default abstract class ProtocolAgendaFactory {
/**
* @description map record to protocolAgenda
* @param {protocol} record
* @returns {ProtocolAgendaViewModel}
*/
public static mapToSingle(record: protocolAgenda): ProtocolAgendaViewModel {
return {
id: record.id,
topic: record.topic,
context: record.context,
protocolId: record.protocol.id,
};
}
/**
* @description map records to protocolAgenda
* @param {Array<protocol>} records
* @returns {Array<ProtocolAgendaViewModel>}
*/
public static mapToBase(records: Array<protocolAgenda>): Array<ProtocolAgendaViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,27 @@
import { protocolDecision } from "../../entity/protocolDecision";
import { ProtocolDecisionViewModel } from "../../viewmodel/admin/protocolDecision.models";
export default abstract class ProtocolDecisionFactory {
/**
* @description map record to protocolDecision
* @param {protocol} record
* @returns {ProtocolDecisionViewModel}
*/
public static mapToSingle(record: protocolDecision): ProtocolDecisionViewModel {
return {
id: record.id,
topic: record.topic,
context: record.context,
protocolId: record.protocol.id,
};
}
/**
* @description map records to protocolDecision
* @param {Array<protocol>} records
* @returns {Array<ProtocolDecisionViewModel>}
*/
public static mapToBase(records: Array<protocolDecision>): Array<ProtocolDecisionViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,27 @@
import { protocolPresence } from "../../entity/protocolPresence";
import { ProtocolPresenceViewModel } from "../../viewmodel/admin/protocolPresence.models";
import MemberFactory from "./member";
export default abstract class ProtocolPresenceFactory {
/**
* @description map record to protocolPresence
* @param {protocol} record
* @returns {ProtocolPresenceViewModel}
*/
public static mapToSingle(record: protocolPresence): ProtocolPresenceViewModel {
return {
memberId: record.member.id,
member: MemberFactory.mapToSingle(record.member),
protocolId: record.protocol.id,
};
}
/**
* @description map records to protocolPresence
* @param {Array<protocol>} records
* @returns {Array<ProtocolPresenceViewModel>}
*/
public static mapToBase(records: Array<protocolPresence>): Array<ProtocolPresenceViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,30 @@
import { protocolVoting } from "../../entity/protocolVoting";
import { ProtocolVotingViewModel } from "../../viewmodel/admin/protocolVoting.models";
export default abstract class ProtocolVotingFactory {
/**
* @description map record to protocolVoting
* @param {protocol} record
* @returns {ProtocolVotingViewModel}
*/
public static mapToSingle(record: protocolVoting): ProtocolVotingViewModel {
return {
id: record.id,
topic: record.topic,
context: record.context,
favour: record.favour,
abstain: record.abstain,
against: record.against,
protocolId: record.protocol.id,
};
}
/**
* @description map records to protocolVoting
* @param {Array<protocol>} records
* @returns {Array<ProtocolVotingViewModel>}
*/
public static mapToBase(records: Array<protocolVoting>): Array<ProtocolVotingViewModel> {
return records.map((r) => this.mapToSingle(r));
}
}

View file

@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class ProtocolTableRename1728645611919 implements MigrationInterface {
name = "ProtocolTableRename1728645611919";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.renameTable("protocol_decisions", "protocol_decision");
await queryRunner.renameTable("protocol_votings", "protocol_voting");
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.renameTable("protocol_decision", "protocol_decisions");
await queryRunner.renameTable("protocol_voting", "protocol_votings");
}
}

View file

@ -1,5 +1,17 @@
import express, { Request, Response } from "express";
import { getAllProtocols, getProtocolById } from "../../controller/admin/protocolController";
import {
getAllProtocols,
getProtocolAgendaById,
getProtocolById,
getProtocolDecisonsById,
getProtocolPrecenseById,
getProtocolVotingsById,
synchronizeProtocolAgendaById,
synchronizeProtocolById,
synchronizeProtocolDecisonsById,
synchronizeProtocolPrecenseById,
synchronizeProtocolVotingsById,
} from "../../controller/admin/protocolController";
var router = express.Router({ mergeParams: true });
@ -11,4 +23,40 @@ router.get("/:id", async (req: Request, res: Response) => {
await getProtocolById(req, res);
});
router.get("/:protocolId/agenda", async (req: Request, res: Response) => {
await getProtocolAgendaById(req, res);
});
router.get("/:protocolId/decisions", async (req: Request, res: Response) => {
await getProtocolDecisonsById(req, res);
});
router.get("/:protocolId/presence", async (req: Request, res: Response) => {
await getProtocolPrecenseById(req, res);
});
router.get("/:protocolId/votings", async (req: Request, res: Response) => {
await getProtocolVotingsById(req, res);
});
router.get("/:id/synchronize", async (req: Request, res: Response) => {
await synchronizeProtocolById(req, res);
});
router.get("/:protocolId/synchronize/agenda", async (req: Request, res: Response) => {
await synchronizeProtocolAgendaById(req, res);
});
router.get("/:protocolId/synchronize/decisions", async (req: Request, res: Response) => {
await synchronizeProtocolDecisonsById(req, res);
});
router.get("/:protocolId/synchronize/presence", async (req: Request, res: Response) => {
await synchronizeProtocolPrecenseById(req, res);
});
router.get("/:protocolId/synchronize/votings", async (req: Request, res: Response) => {
await synchronizeProtocolVotingsById(req, res);
});
export default router;

View file

@ -0,0 +1,41 @@
import { dataSource } from "../data-source";
import { protocolAgenda } from "../entity/protocolAgenda";
import InternalException from "../exceptions/internalException";
export default abstract class ProtocolAgendaService {
/**
* @description get all protocolAgendas
* @returns {Promise<Array<protocolAgenda>>}
*/
static async getAll(protocolId: number): Promise<Array<protocolAgenda>> {
return await dataSource
.getRepository(protocolAgenda)
.createQueryBuilder("protocolAgenda")
.where("protocolAgenda.protocolId = :protocolId", { protocolId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolAgendas not found", err);
});
}
/**
* @description get protocolAgenda by id
* @returns {Promise<protocolAgenda>}
*/
static async getById(id: number): Promise<protocolAgenda> {
return await dataSource
.getRepository(protocolAgenda)
.createQueryBuilder("protocolAgenda")
.where("protocolAgenda.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolAgenda not found by id", err);
});
}
}

View file

@ -0,0 +1,41 @@
import { dataSource } from "../data-source";
import { protocolDecision } from "../entity/protocolDecision";
import InternalException from "../exceptions/internalException";
export default abstract class ProtocolDecisionService {
/**
* @description get all protocolDecisionss
* @returns {Promise<Array<protocolDecision>>}
*/
static async getAll(protocolId: number): Promise<Array<protocolDecision>> {
return await dataSource
.getRepository(protocolDecision)
.createQueryBuilder("protocolDecisions")
.where("protocolAgenda.protocolId = :protocolId", { protocolId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolDecisions not found", err);
});
}
/**
* @description get protocolDecision by id
* @returns {Promise<protocolDecision>}
*/
static async getById(id: number): Promise<protocolDecision> {
return await dataSource
.getRepository(protocolDecision)
.createQueryBuilder("protocolDecisions")
.where("protocolDecisions.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolDecision not found by id", err);
});
}
}

View file

@ -0,0 +1,41 @@
import { dataSource } from "../data-source";
import { protocolPresence } from "../entity/protocolPresence";
import InternalException from "../exceptions/internalException";
export default abstract class ProtocolPresenceService {
/**
* @description get all protocolPresences
* @returns {Promise<Array<protocolPresence>>}
*/
static async getAll(protocolId: number): Promise<Array<protocolPresence>> {
return await dataSource
.getRepository(protocolPresence)
.createQueryBuilder("protocolPresence")
.where("protocolAgenda.protocolId = :protocolId", { protocolId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolPresence not found", err);
});
}
/**
* @description get protocolDecision by id
* @returns {Promise<protocolPresence>}
*/
static async getById(id: number): Promise<protocolPresence> {
return await dataSource
.getRepository(protocolPresence)
.createQueryBuilder("protocolPresence")
.where("protocolPresence.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolDecision not found by id", err);
});
}
}

View file

@ -0,0 +1,41 @@
import { dataSource } from "../data-source";
import { protocolVoting } from "../entity/protocolVoting";
import InternalException from "../exceptions/internalException";
export default abstract class ProtocolVotingService {
/**
* @description get all protocolVotingss
* @returns {Promise<Array<protocolVoting>>}
*/
static async getAll(protocolId: number): Promise<Array<protocolVoting>> {
return await dataSource
.getRepository(protocolVoting)
.createQueryBuilder("protocolVotings")
.where("protocolAgenda.protocolId = :protocolId", { protocolId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolVotings not found", err);
});
}
/**
* @description get protocolVoting by id
* @returns {Promise<protocolVoting>}
*/
static async getById(id: number): Promise<protocolVoting> {
return await dataSource
.getRepository(protocolVoting)
.createQueryBuilder("protocolVotings")
.where("protocolVotings.id = :id", { id: id })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("protocolVoting not found by id", err);
});
}
}

View file

@ -0,0 +1,6 @@
export interface ProtocolAgendaViewModel {
id: number;
topic: string;
context: string;
protocolId: number;
}

View file

@ -0,0 +1,6 @@
export interface ProtocolDecisionViewModel {
id: number;
topic: string;
context: string;
protocolId: number;
}

View file

@ -0,0 +1,7 @@
import { MemberViewModel } from "./member.models";
export interface ProtocolPresenceViewModel {
memberId: number;
member: MemberViewModel;
protocolId: number;
}

View file

@ -0,0 +1,9 @@
export interface ProtocolVotingViewModel {
id: number;
topic: string;
context: string;
favour: number;
abstain: number;
against: number;
protocolId: number;
}