enhance: enable deletion of protocol content
This commit is contained in:
parent
1a83e4939d
commit
496a60f2df
4 changed files with 52 additions and 9 deletions
|
@ -34,18 +34,32 @@ export default abstract class ProtocolAgendaCommandHandler {
|
|||
|
||||
/**
|
||||
* @description sync protocolAgenda
|
||||
* @param {number} protocolId
|
||||
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
|
||||
static async sync(protocolId: number, syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
|
||||
let currentAgenda = await ProtocolAgendaService.getAll(protocolId);
|
||||
return await dataSource
|
||||
.transaction(async (transactionalEntityManager) => {
|
||||
let removed = currentAgenda.filter((ca) => !syncProtocolAgenda.some((spa) => spa.id == ca.id));
|
||||
|
||||
for (const agenda of syncProtocolAgenda) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.update(protocolAgenda)
|
||||
.set(agenda)
|
||||
.where({ id: agenda.id })
|
||||
.where({ id: agenda.id, protocolId })
|
||||
.execute();
|
||||
}
|
||||
|
||||
if (removed.length != 0) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(protocolAgenda)
|
||||
.where("id IN (:...ids)", { ids: removed.map((m) => m.id) })
|
||||
.andWhere({ protocolId })
|
||||
.execute();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -33,12 +33,19 @@ export default abstract class ProtocolDecisionCommandHandler {
|
|||
}
|
||||
/**
|
||||
* @description sync protocolDecision
|
||||
* @param {number} protocolId
|
||||
* @param {Array<SynchronizeProtocolDecisionCommand>} syncProtocolDecisions
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async sync(syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>): Promise<void> {
|
||||
static async sync(
|
||||
protocolId: number,
|
||||
syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>
|
||||
): Promise<void> {
|
||||
let currentDecision = await ProtocolDecisionService.getAll(protocolId);
|
||||
return await dataSource
|
||||
.transaction(async (transactionalEntityManager) => {
|
||||
let removed = currentDecision.filter((ca) => !syncProtocolDecisions.some((spa) => spa.id == ca.id));
|
||||
|
||||
for (const decision of syncProtocolDecisions) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
|
@ -47,8 +54,17 @@ export default abstract class ProtocolDecisionCommandHandler {
|
|||
.where({ id: decision.id })
|
||||
.execute();
|
||||
}
|
||||
|
||||
if (removed.length != 0) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(protocolDecision)
|
||||
.where("id IN (:...ids)", { ids: removed.map((m) => m.id) })
|
||||
.andWhere({ protocolId })
|
||||
.execute();
|
||||
}
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SYNC", "protocolDecision", err);
|
||||
});
|
||||
|
|
|
@ -33,12 +33,16 @@ export default abstract class ProtocolVotingCommandHandler {
|
|||
}
|
||||
/**
|
||||
* @description sync protocolVoting
|
||||
* @param {number} protocolId
|
||||
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async sync(syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
|
||||
static async sync(protocolId: number, syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
|
||||
let currentVoting = await ProtocolVotingService.getAll(protocolId);
|
||||
return await dataSource
|
||||
.transaction(async (transactionalEntityManager) => {
|
||||
let removed = currentVoting.filter((ca) => !syncProtocolVotings.some((spa) => spa.id == ca.id));
|
||||
|
||||
for (const voting of syncProtocolVotings) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
|
@ -47,8 +51,17 @@ export default abstract class ProtocolVotingCommandHandler {
|
|||
.where({ id: voting.id })
|
||||
.execute();
|
||||
}
|
||||
|
||||
if (removed.length != 0) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(protocolVoting)
|
||||
.where("id IN (:...ids)", { ids: removed.map((m) => m.id) })
|
||||
.andWhere({ protocolId })
|
||||
.execute();
|
||||
}
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SYNC", "protocolVoting", err);
|
||||
});
|
||||
|
|
|
@ -324,7 +324,7 @@ export async function synchronizeProtocolAgendaById(req: Request, res: Response)
|
|||
protocolId,
|
||||
})
|
||||
);
|
||||
await ProtocolAgendaCommandHandler.sync(syncAgenda);
|
||||
await ProtocolAgendaCommandHandler.sync(protocolId, syncAgenda);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ export async function synchronizeProtocolDecisonsById(req: Request, res: Respons
|
|||
protocolId,
|
||||
})
|
||||
);
|
||||
await ProtocolDecisionCommandHandler.sync(syncDecision);
|
||||
await ProtocolDecisionCommandHandler.sync(protocolId, syncDecision);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ export async function synchronizeProtocolVotingsById(req: Request, res: Response
|
|||
protocolId,
|
||||
})
|
||||
);
|
||||
await ProtocolVotingCommandHandler.sync(syncVoting);
|
||||
await ProtocolVotingCommandHandler.sync(protocolId, syncVoting);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue