protcol data commands
This commit is contained in:
parent
475a13ce36
commit
b9b258a1f6
16 changed files with 335 additions and 10 deletions
6
src/command/protocolAgendaCommand.ts
Normal file
6
src/command/protocolAgendaCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface SynchronizeProtocolAgendaCommand {
|
||||
id?: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
protocolId: number;
|
||||
}
|
25
src/command/protocolAgendaCommandHandler.ts
Normal file
25
src/command/protocolAgendaCommandHandler.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
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 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);
|
||||
});
|
||||
}
|
||||
}
|
13
src/command/protocolCommand.ts
Normal file
13
src/command/protocolCommand.ts
Normal 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;
|
||||
}
|
53
src/command/protocolCommandHandler.ts
Normal file
53
src/command/protocolCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
6
src/command/protocolDecisionCommand.ts
Normal file
6
src/command/protocolDecisionCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface SynchronizeProtocolDecisionCommand {
|
||||
id?: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
protocolId: number;
|
||||
}
|
25
src/command/protocolDecisionCommandHandler.ts
Normal file
25
src/command/protocolDecisionCommandHandler.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
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 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);
|
||||
});
|
||||
}
|
||||
}
|
4
src/command/protocolPresenceCommand.ts
Normal file
4
src/command/protocolPresenceCommand.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export interface SynchronizeProtocolPresenceCommand {
|
||||
memberIds: Array<number>;
|
||||
protocolId: number;
|
||||
}
|
65
src/command/protocolPresenceCommandHandler.ts
Normal file
65
src/command/protocolPresenceCommandHandler.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
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));
|
||||
|
||||
await this.syncPresenceAdd(manager, syncProtocolPresences.protocolId, newMembers);
|
||||
|
||||
await this.syncPresenceRemove(manager, syncProtocolPresences.protocolId, removeMembers);
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed saving user roles", 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,
|
||||
memberIds: 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("protcolId = :protocolId", { protocolId })
|
||||
.execute();
|
||||
}
|
||||
}
|
9
src/command/protocolVotingCommand.ts
Normal file
9
src/command/protocolVotingCommand.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
export interface SynchronizeProtocolVotingCommand {
|
||||
id: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
favour: number;
|
||||
abstain: number;
|
||||
against: number;
|
||||
protocolId: number;
|
||||
}
|
25
src/command/protocolVotingCommandHandler.ts
Normal file
25
src/command/protocolVotingCommandHandler.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
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 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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue