hotfix: insert or update with postgres
This commit is contained in:
parent
1f5ddc05d2
commit
eb4db01b27
11 changed files with 43 additions and 32 deletions
|
@ -1,7 +1,7 @@
|
|||
export interface SynchronizeProtocolAgendaCommand {
|
||||
id?: number;
|
||||
id: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
sort?: number;
|
||||
sort: number;
|
||||
protocolId: number;
|
||||
}
|
||||
|
|
|
@ -39,13 +39,16 @@ export default abstract class ProtocolAgendaCommandHandler {
|
|||
*/
|
||||
static async sync(syncProtocolAgenda: Array<SynchronizeProtocolAgendaCommand>): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(protocolAgenda)
|
||||
.values(syncProtocolAgenda)
|
||||
.orUpdate(["topic", "context", "sort"], ["id"])
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.transaction(async (transactionalEntityManager) => {
|
||||
for (const agenda of syncProtocolAgenda) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.update(protocolAgenda)
|
||||
.set(agenda)
|
||||
.where({ id: agenda.id })
|
||||
.execute();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SYNC", "protocolAgenda", err);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export interface SynchronizeProtocolDecisionCommand {
|
||||
id?: number;
|
||||
id: number;
|
||||
topic: string;
|
||||
context: string;
|
||||
sort?: number;
|
||||
sort: number;
|
||||
protocolId: number;
|
||||
}
|
||||
|
|
|
@ -38,12 +38,16 @@ export default abstract class ProtocolDecisionCommandHandler {
|
|||
*/
|
||||
static async sync(syncProtocolDecisions: Array<SynchronizeProtocolDecisionCommand>): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(protocolDecision)
|
||||
.values(syncProtocolDecisions)
|
||||
.orUpdate(["topic", "context", "sort"], ["id"])
|
||||
.execute()
|
||||
.transaction(async (transactionalEntityManager) => {
|
||||
for (const decision of syncProtocolDecisions) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.update(protocolDecision)
|
||||
.set(decision)
|
||||
.where({ id: decision.id })
|
||||
.execute();
|
||||
}
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SYNC", "protocolDecision", err);
|
||||
|
|
|
@ -5,6 +5,6 @@ export interface SynchronizeProtocolVotingCommand {
|
|||
favour: number;
|
||||
abstain: number;
|
||||
against: number;
|
||||
sort?: number;
|
||||
sort: number;
|
||||
protocolId: number;
|
||||
}
|
||||
|
|
|
@ -38,12 +38,16 @@ export default abstract class ProtocolVotingCommandHandler {
|
|||
*/
|
||||
static async sync(syncProtocolVotings: Array<SynchronizeProtocolVotingCommand>): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(protocolVoting)
|
||||
.values(syncProtocolVotings)
|
||||
.orUpdate(["topic", "context", "favour", "abstain", "against", "sort"], ["id"])
|
||||
.execute()
|
||||
.transaction(async (transactionalEntityManager) => {
|
||||
for (const voting of syncProtocolVotings) {
|
||||
await transactionalEntityManager
|
||||
.createQueryBuilder()
|
||||
.update(protocolVoting)
|
||||
.set(voting)
|
||||
.where({ id: voting.id })
|
||||
.execute();
|
||||
}
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SYNC", "protocolVoting", err);
|
||||
|
|
|
@ -19,7 +19,7 @@ export default abstract class NewsletterConfigCommandHandler {
|
|||
comTypeId: setNewsletterConfig.comTypeId,
|
||||
config: setNewsletterConfig.config,
|
||||
})
|
||||
.orUpdate(["config"], "comTypeId")
|
||||
.orUpdate(["config"], ["comTypeId"])
|
||||
.execute()
|
||||
.then((result) => {})
|
||||
.catch((err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue