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) => {
|
||||
|
|
|
@ -317,7 +317,7 @@ export async function synchronizeProtocolAgendaById(req: Request, res: Response)
|
|||
|
||||
let syncAgenda: Array<SynchronizeProtocolAgendaCommand> = agenda.map(
|
||||
(a: ProtocolAgendaViewModel): SynchronizeProtocolAgendaCommand => ({
|
||||
id: a.id ?? null,
|
||||
id: a.id,
|
||||
topic: a.topic,
|
||||
context: a.context,
|
||||
sort: a.sort,
|
||||
|
@ -341,7 +341,7 @@ export async function synchronizeProtocolDecisonsById(req: Request, res: Respons
|
|||
|
||||
let syncDecision: Array<SynchronizeProtocolDecisionCommand> = decisions.map(
|
||||
(d: ProtocolDecisionViewModel): SynchronizeProtocolDecisionCommand => ({
|
||||
id: d.id ?? null,
|
||||
id: d.id,
|
||||
topic: d.topic,
|
||||
context: d.context,
|
||||
sort: d.sort,
|
||||
|
@ -365,7 +365,7 @@ export async function synchronizeProtocolVotingsById(req: Request, res: Response
|
|||
|
||||
let syncVoting: Array<SynchronizeProtocolVotingCommand> = votings.map(
|
||||
(v: ProtocolVotingViewModel): SynchronizeProtocolVotingCommand => ({
|
||||
id: v.id ?? null,
|
||||
id: v.id,
|
||||
topic: v.topic,
|
||||
context: v.context,
|
||||
favour: v.favour,
|
||||
|
|
|
@ -748,7 +748,7 @@ export default abstract class BackupHelper {
|
|||
.insert()
|
||||
.into("template_usage")
|
||||
.values(data?.["template_usage"] ?? [])
|
||||
.orUpdate(["headerId", "bodyId", "footerId", "headerHeight", "footerHeight"], ["scope"])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
}
|
||||
private static async setUser(data: { [key: string]: Array<any> }): Promise<void> {
|
||||
|
|
|
@ -106,7 +106,7 @@ export class CreateSchema1738166167472 implements MigrationInterface {
|
|||
.insert()
|
||||
.into(templateUsage)
|
||||
.values([{ scope: "newsletter" }, { scope: "protocol" }, { scope: "member.list" }])
|
||||
.orUpdate(["headerId", "bodyId", "footerId", "headerHeight", "footerHeight"], ["scope"])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
|
||||
await queryRunner.createTable(protocol_table, true, true, true);
|
||||
|
|
|
@ -11,7 +11,7 @@ export class TemplatesAndProtocolSort1742549956787 implements MigrationInterface
|
|||
.insert()
|
||||
.into(templateUsage)
|
||||
.values([{ scope: "member" }])
|
||||
.orUpdate(["headerId", "bodyId", "footerId", "headerHeight", "footerHeight"], ["scope"])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
|
||||
await queryRunner.manager
|
||||
|
@ -47,7 +47,7 @@ export class TemplatesAndProtocolSort1742549956787 implements MigrationInterface
|
|||
.insert()
|
||||
.into(templateUsage)
|
||||
.values([{ scope: "member.list" }])
|
||||
.orUpdate(["headerId", "bodyId", "footerId", "headerHeight", "footerHeight"], ["scope"])
|
||||
.orIgnore()
|
||||
.execute();
|
||||
|
||||
await queryRunner.manager.createQueryBuilder().delete().from(templateUsage).where({ scope: "member" }).execute();
|
||||
|
|
Loading…
Add table
Reference in a new issue