Merge branch 'main' into #3-calendar

# Conflicts:
#	package-lock.json
#	src/data-source.ts
#	src/routes/admin/index.ts
#	src/type/permissionTypes.ts
This commit is contained in:
Julian Krauser 2024-11-07 11:09:52 +01:00
commit 98eb870385
48 changed files with 2672 additions and 9 deletions

View file

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

View file

@ -0,0 +1,49 @@
import { dataSource } from "../data-source";
import { protocolAgenda } from "../entity/protocolAgenda";
import InternalException from "../exceptions/internalException";
import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand";
export default abstract class ProtocolAgendaCommandHandler {
/**
* @description create protocolAgenda
* @param {number}
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolAgenda)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocolAgenda
* @param {Array<SynchronizeProtocolAgendaCommand>}
* @returns {Promise<void>}
*/
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolAgenda)
.values(syncProtocolAgenda)
.orUpdate(["topic", "context"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -0,0 +1,13 @@
export interface CreateProtocolCommand {
title: string;
date: Date;
}
export interface SynchronizeProtocolCommand {
id: number;
title: string;
date: Date;
starttime: Date;
endtime: Date;
summary: string;
}

View file

@ -0,0 +1,53 @@
import { dataSource } from "../data-source";
import { protocol } from "../entity/protocol";
import InternalException from "../exceptions/internalException";
import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand";
export default abstract class ProtocolCommandHandler {
/**
* @description create protocol
* @param CreateProtocolCommand
* @returns {Promise<number>}
*/
static async create(createProtocol: CreateProtocolCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocol)
.values({
title: createProtocol.title,
date: createProtocol.date,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocol
* @param SynchronizeProtocolCommand
* @returns {Promise<void>}
*/
static async sync(syncProtocol: SynchronizeProtocolCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(protocol)
.set({
title: syncProtocol.title,
date: syncProtocol.date,
starttime: syncProtocol.starttime,
endtime: syncProtocol.endtime,
summary: syncProtocol.summary,
})
.where("id = :id", { id: syncProtocol.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

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

View file

@ -0,0 +1,48 @@
import { dataSource } from "../data-source";
import { protocolDecision } from "../entity/protocolDecision";
import InternalException from "../exceptions/internalException";
import { SynchronizeProtocolDecisionCommand } from "./protocolDecisionCommand";
export default abstract class ProtocolDecisionCommandHandler {
/**
* @description create protocolDecision
* @param {number}
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolDecision)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocolDecision
* @param {Array<SynchronizeProtocolDecisionCommand>}
* @returns {Promise<void>}
*/
static async sync(syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolDecision)
.values(syncProtocolDecisions)
.orUpdate(["topic", "context"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

@ -0,0 +1,4 @@
export interface SynchronizeProtocolPresenceCommand {
memberIds: Array<number>;
protocolId: number;
}

View file

@ -0,0 +1,69 @@
import { DeleteResult, EntityManager, InsertResult } from "typeorm";
import { dataSource } from "../data-source";
import { protocolPresence } from "../entity/protocolPresence";
import InternalException from "../exceptions/internalException";
import ProtocolPresenceService from "../service/protocolPrecenseService";
import { SynchronizeProtocolPresenceCommand } from "./protocolPresenceCommand";
export default abstract class ProtocolPresenceCommandHandler {
/**
* @description sync protocolPresence
* @param {SynchronizeProtocolPresenceCommand}
* @returns {Promise<void>}
*/
static async sync(syncProtocolPresences: SynchronizeProtocolPresenceCommand): Promise<void> {
let currentPresence = (await ProtocolPresenceService.getAll(syncProtocolPresences.protocolId)).map(
(r) => r.memberId
);
return await dataSource.manager
.transaction(async (manager) => {
let newMembers = syncProtocolPresences.memberIds.filter((r) => !currentPresence.includes(r));
let removeMembers = currentPresence.filter((r) => !syncProtocolPresences.memberIds.includes(r));
if (newMembers.length != 0) {
await this.syncPresenceAdd(manager, syncProtocolPresences.protocolId, newMembers);
}
if (removeMembers.length != 0) {
await this.syncPresenceRemove(manager, syncProtocolPresences.protocolId, removeMembers);
}
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed saving protocol presence", err);
});
}
private static async syncPresenceAdd(
manager: EntityManager,
protocolId: number,
memberIds: Array<number>
): Promise<InsertResult> {
return await manager
.createQueryBuilder()
.insert()
.into(protocolPresence)
.values(
memberIds.map((m) => ({
protocolId,
memberId: m,
}))
)
.execute();
}
private static async syncPresenceRemove(
manager: EntityManager,
protocolId: number,
memberIds: Array<number>
): Promise<DeleteResult> {
return await manager
.createQueryBuilder()
.delete()
.from(protocolPresence)
.where("memberId IN (:...ids)", { ids: memberIds })
.andWhere("protocolId = :protocolId", { protocolId })
.execute();
}
}

View file

@ -0,0 +1,6 @@
export interface CreateProtocolPrintoutCommand {
title: string;
iteration: number;
filename: string;
protocolId: number;
}

View file

@ -0,0 +1,31 @@
import { dataSource } from "../data-source";
import { protocolPrintout } from "../entity/protocolPrintout";
import InternalException from "../exceptions/internalException";
import { CreateProtocolPrintoutCommand } from "./protocolPrintoutCommand";
export default abstract class ProtocolPrintoutCommandHandler {
/**
* @description create protocolPrintout
* @param {number}
* @returns {Promise<number>}
*/
static async create(printout: CreateProtocolPrintoutCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolPrintout)
.values({
title: printout.title,
iteration: printout.iteration,
filename: printout.filename,
protocolId: printout.protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}

View file

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

View file

@ -0,0 +1,48 @@
import { dataSource } from "../data-source";
import { protocolVoting } from "../entity/protocolVoting";
import InternalException from "../exceptions/internalException";
import { SynchronizeProtocolVotingCommand } from "./protocolVotingCommand";
export default abstract class ProtocolVotingCommandHandler {
/**
* @description create protocolVoting
* @param {number}
* @returns {Promise<number>}
*/
static async create(protocolId: number): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolVoting)
.values({
topic: "",
context: "",
protocolId,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
/**
* @description sync protocolVoting
* @param {Array<SynchronizeProtocolVotingCommand>}
* @returns {Promise<void>}
*/
static async sync(syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
return await dataSource
.createQueryBuilder()
.insert()
.into(protocolVoting)
.values(syncProtocolVotings)
.orUpdate(["topic", "context", "favour", "abstain", "against"], ["id"])
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed creating protocol", err);
});
}
}