Skip to content

Commit

Permalink
Upsert in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jun 28, 2024
1 parent cc0bc98 commit 7af81ba
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/jobs/src/transactions/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,26 @@ client.defineJob({
return null;
}

const { error: transactionsError, data: transactionsData } =
await supabase
.from("transactions")
.upsert(transactions, {
onConflict: "internal_id",
ignoreDuplicates: true,
})
.select("*");
const {
error: transactionsError,
data: transactionsData,
statusText,
} = await supabase
.from("transactions")
.upsert(transactions, {
onConflict: "internal_id",
})
.select("*");

if (transactionsError) {
await io.logger.error("Transactions error", transactionsError);
}

if (transactionsData && transactionsData?.length > 0) {
if (
statusText === "Created" &&
transactionsData &&
transactionsData?.length > 0
) {
await io.sendEvent("🔔 Send notifications", {
name: Events.TRANSACTIONS_NOTIFICATION,
payload: {
Expand Down

0 comments on commit 7af81ba

Please sign in to comment.