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
|
* @description sync protocolAgenda
|
||||||
|
* @param {number} protocolId
|
||||||
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
|
* @param {Array<SynchronizeProtocolAgendaCommand>} syncProtocolAgenda
|
||||||
* @returns {Promise<void>}
|
* @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
|
return await dataSource
|
||||||
.transaction(async (transactionalEntityManager) => {
|
.transaction(async (transactionalEntityManager) => {
|
||||||
|
let removed = currentAgenda.filter((ca) => !syncProtocolAgenda.some((spa) => spa.id == ca.id));
|
||||||
|
|
||||||
for (const agenda of syncProtocolAgenda) {
|
for (const agenda of syncProtocolAgenda) {
|
||||||
await transactionalEntityManager
|
await transactionalEntityManager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(protocolAgenda)
|
.update(protocolAgenda)
|
||||||
.set(agenda)
|
.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();
|
.execute();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -33,12 +33,19 @@ export default abstract class ProtocolDecisionCommandHandler {
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description sync protocolDecision
|
* @description sync protocolDecision
|
||||||
|
* @param {number} protocolId
|
||||||
* @param {Array<SynchronizeProtocolDecisionCommand>} syncProtocolDecisions
|
* @param {Array<SynchronizeProtocolDecisionCommand>} syncProtocolDecisions
|
||||||
* @returns {Promise<void>}
|
* @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
|
return await dataSource
|
||||||
.transaction(async (transactionalEntityManager) => {
|
.transaction(async (transactionalEntityManager) => {
|
||||||
|
let removed = currentDecision.filter((ca) => !syncProtocolDecisions.some((spa) => spa.id == ca.id));
|
||||||
|
|
||||||
for (const decision of syncProtocolDecisions) {
|
for (const decision of syncProtocolDecisions) {
|
||||||
await transactionalEntityManager
|
await transactionalEntityManager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
|
@ -47,8 +54,17 @@ export default abstract class ProtocolDecisionCommandHandler {
|
||||||
.where({ id: decision.id })
|
.where({ id: decision.id })
|
||||||
.execute();
|
.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) => {
|
.catch((err) => {
|
||||||
throw new DatabaseActionException("SYNC", "protocolDecision", err);
|
throw new DatabaseActionException("SYNC", "protocolDecision", err);
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,12 +33,16 @@ export default abstract class ProtocolVotingCommandHandler {
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description sync protocolVoting
|
* @description sync protocolVoting
|
||||||
|
* @param {number} protocolId
|
||||||
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
|
* @param {Array<SynchronizeProtocolVotingCommand>} syncProtocolVotings
|
||||||
* @returns {Promise<void>}
|
* @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
|
return await dataSource
|
||||||
.transaction(async (transactionalEntityManager) => {
|
.transaction(async (transactionalEntityManager) => {
|
||||||
|
let removed = currentVoting.filter((ca) => !syncProtocolVotings.some((spa) => spa.id == ca.id));
|
||||||
|
|
||||||
for (const voting of syncProtocolVotings) {
|
for (const voting of syncProtocolVotings) {
|
||||||
await transactionalEntityManager
|
await transactionalEntityManager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
|
@ -47,8 +51,17 @@ export default abstract class ProtocolVotingCommandHandler {
|
||||||
.where({ id: voting.id })
|
.where({ id: voting.id })
|
||||||
.execute();
|
.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) => {
|
.catch((err) => {
|
||||||
throw new DatabaseActionException("SYNC", "protocolVoting", err);
|
throw new DatabaseActionException("SYNC", "protocolVoting", err);
|
||||||
});
|
});
|
||||||
|
|
|
@ -324,7 +324,7 @@ export async function synchronizeProtocolAgendaById(req: Request, res: Response)
|
||||||
protocolId,
|
protocolId,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
await ProtocolAgendaCommandHandler.sync(syncAgenda);
|
await ProtocolAgendaCommandHandler.sync(protocolId, syncAgenda);
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ export async function synchronizeProtocolDecisonsById(req: Request, res: Respons
|
||||||
protocolId,
|
protocolId,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
await ProtocolDecisionCommandHandler.sync(syncDecision);
|
await ProtocolDecisionCommandHandler.sync(protocolId, syncDecision);
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ export async function synchronizeProtocolVotingsById(req: Request, res: Response
|
||||||
protocolId,
|
protocolId,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
await ProtocolVotingCommandHandler.sync(syncVoting);
|
await ProtocolVotingCommandHandler.sync(protocolId, syncVoting);
|
||||||
|
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue