Merge branch 'main' into #1-account-management
# Conflicts: # src/data-source.ts
This commit is contained in:
commit
273745f830
66 changed files with 3721 additions and 10 deletions
24
src/command/calendarCommand.ts
Normal file
24
src/command/calendarCommand.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
export interface CreateCalendarCommand {
|
||||
starttime: Date;
|
||||
endtime: Date;
|
||||
title: string;
|
||||
content: string;
|
||||
location: string;
|
||||
allDay: boolean;
|
||||
typeId: number;
|
||||
}
|
||||
|
||||
export interface UpdateCalendarCommand {
|
||||
id: string;
|
||||
starttime: Date;
|
||||
endtime: Date;
|
||||
title: string;
|
||||
content: string;
|
||||
location: string;
|
||||
allDay: boolean;
|
||||
typeId: number;
|
||||
}
|
||||
|
||||
export interface DeleteCalendarCommand {
|
||||
id: string;
|
||||
}
|
96
src/command/calendarCommandHandler.ts
Normal file
96
src/command/calendarCommandHandler.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { calendar } from "../entity/calendar";
|
||||
import { calendarType } from "../entity/calendarType";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "./calendarCommand";
|
||||
|
||||
export default abstract class CalendarCommandHandler {
|
||||
/**
|
||||
* @description create calendar
|
||||
* @param CreateCalendarCommand
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createCalendar: CreateCalendarCommand): Promise<number> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(calendar)
|
||||
.values({
|
||||
starttime: createCalendar.starttime,
|
||||
endtime: createCalendar.endtime,
|
||||
title: createCalendar.title,
|
||||
content: createCalendar.content,
|
||||
location: createCalendar.location,
|
||||
allDay: createCalendar.allDay,
|
||||
type: await dataSource
|
||||
.getRepository(calendarType)
|
||||
.createQueryBuilder("type")
|
||||
.where("id = :id", { id: createCalendar.typeId })
|
||||
.getOneOrFail(),
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
return result.identifiers[0].id;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating calendar", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendar
|
||||
* @param UpdateCalendarCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateCalendar: UpdateCalendarCommand): Promise<void> {
|
||||
let sequence = await dataSource
|
||||
.getRepository(calendar)
|
||||
.createQueryBuilder("calendar")
|
||||
.where("id = :id", { id: updateCalendar.id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res.sequence;
|
||||
});
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(calendar)
|
||||
.set({
|
||||
starttime: updateCalendar.starttime,
|
||||
endtime: updateCalendar.endtime,
|
||||
title: updateCalendar.title,
|
||||
content: updateCalendar.content,
|
||||
location: updateCalendar.location,
|
||||
allDay: updateCalendar.allDay,
|
||||
type: await dataSource
|
||||
.getRepository(calendarType)
|
||||
.createQueryBuilder("type")
|
||||
.where("id = :id", { id: updateCalendar.typeId })
|
||||
.getOneOrFail(),
|
||||
sequence: sequence + 1,
|
||||
})
|
||||
.where("id = :id", { id: updateCalendar.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating award", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendar
|
||||
* @param DeleteCalendarCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deleteCalendar: DeleteCalendarCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(calendar)
|
||||
.where("id = :id", { id: deleteCalendar.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting calendar", err);
|
||||
});
|
||||
}
|
||||
}
|
16
src/command/calendarTypeCommand.ts
Normal file
16
src/command/calendarTypeCommand.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
export interface CreateCalendarTypeCommand {
|
||||
type: string;
|
||||
nscdr: boolean;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface UpdateCalendarTypeCommand {
|
||||
id: number;
|
||||
type: string;
|
||||
nscdr: boolean;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface DeleteCalendarTypeCommand {
|
||||
id: number;
|
||||
}
|
70
src/command/calendarTypeCommandHandler.ts
Normal file
70
src/command/calendarTypeCommandHandler.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { calendarType } from "../entity/calendarType";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { CreateCalendarTypeCommand, DeleteCalendarTypeCommand, UpdateCalendarTypeCommand } from "./calendarTypeCommand";
|
||||
|
||||
export default abstract class CalendarTypeCommandHandler {
|
||||
/**
|
||||
* @description create calendarType
|
||||
* @param CreateCalendarTypeCommand
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createCalendarType: CreateCalendarTypeCommand): Promise<number> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(calendarType)
|
||||
.values({
|
||||
type: createCalendarType.type,
|
||||
nscdr: createCalendarType.nscdr,
|
||||
color: createCalendarType.color,
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
return result.identifiers[0].id;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating calendarType", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendarType
|
||||
* @param UpdateCalendarTypeCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateCalendarType: UpdateCalendarTypeCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(calendarType)
|
||||
.set({
|
||||
type: updateCalendarType.type,
|
||||
nscdr: updateCalendarType.nscdr,
|
||||
color: updateCalendarType.color,
|
||||
})
|
||||
.where("id = :id", { id: updateCalendarType.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating award", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendarType
|
||||
* @param DeleteCalendarTypeCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deleteCalendarType: DeleteCalendarTypeCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(calendarType)
|
||||
.where("id = :id", { id: deleteCalendarType.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting calendarType", err);
|
||||
});
|
||||
}
|
||||
}
|
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;
|
||||
}
|
49
src/command/protocolAgendaCommandHandler.ts
Normal file
49
src/command/protocolAgendaCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
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;
|
||||
}
|
48
src/command/protocolDecisionCommandHandler.ts
Normal file
48
src/command/protocolDecisionCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
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;
|
||||
}
|
69
src/command/protocolPresenceCommandHandler.ts
Normal file
69
src/command/protocolPresenceCommandHandler.ts
Normal 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();
|
||||
}
|
||||
}
|
6
src/command/protocolPrintoutCommand.ts
Normal file
6
src/command/protocolPrintoutCommand.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface CreateProtocolPrintoutCommand {
|
||||
title: string;
|
||||
iteration: number;
|
||||
filename: string;
|
||||
protocolId: number;
|
||||
}
|
31
src/command/protocolPrintoutCommandHandler.ts
Normal file
31
src/command/protocolPrintoutCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
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;
|
||||
}
|
48
src/command/protocolVotingCommandHandler.ts
Normal file
48
src/command/protocolVotingCommandHandler.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue