hotfix: insert or update with postgres

This commit is contained in:
Julian Krauser 2025-03-24 09:19:11 +01:00
parent 1f5ddc05d2
commit eb4db01b27
11 changed files with 43 additions and 32 deletions

View file

@ -1,7 +1,7 @@
export interface SynchronizeProtocolAgendaCommand {
id?: number;
id: number;
topic: string;
context: string;
sort?: number;
sort: number;
protocolId: number;
}

View file

@ -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);
});

View file

@ -1,7 +1,7 @@
export interface SynchronizeProtocolDecisionCommand {
id?: number;
id: number;
topic: string;
context: string;
sort?: number;
sort: number;
protocolId: number;
}

View file

@ -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);

View file

@ -5,6 +5,6 @@ export interface SynchronizeProtocolVotingCommand {
favour: number;
abstain: number;
against: number;
sort?: number;
sort: number;
protocolId: number;
}

View file

@ -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);

View file

@ -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) => {