-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from citizenwallet/interaction-for-transaction
upsert interaction between from-to for transaction
- Loading branch information
Showing
5 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ | |
], | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} | ||
}, | ||
"deno.enable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { SupabaseClient } from "jsr:@supabase/supabase-js@2"; | ||
import { Transaction } from "./transactions.ts"; | ||
|
||
const INTERACTIONS_TABLE = "a_interactions"; | ||
|
||
export const upsertInteraction = async ( | ||
client: SupabaseClient, | ||
transaction: Pick<Transaction, "id" | "from" | "to">, | ||
) => { | ||
const timestamp = new Date().toISOString(); | ||
|
||
// First direction: from->to | ||
await client | ||
.from(INTERACTIONS_TABLE) | ||
.upsert( | ||
{ | ||
transaction_id: transaction.id, | ||
account: transaction.from, | ||
with: transaction.to, | ||
updated_at: timestamp, | ||
created_at: timestamp, | ||
new_interaction: true, | ||
}, | ||
{ | ||
onConflict: "account,with", | ||
ignoreDuplicates: false, | ||
}, | ||
) | ||
.select() | ||
.single(); | ||
|
||
// Second direction: to->from | ||
await client | ||
.from(INTERACTIONS_TABLE) | ||
.upsert({ | ||
transaction_id: transaction.id, | ||
account: transaction.to, | ||
with: transaction.from, | ||
updated_at: timestamp, | ||
created_at: timestamp, | ||
new_interaction: true, | ||
}, { | ||
onConflict: "account,with", | ||
ignoreDuplicates: false, | ||
}) | ||
.select() | ||
.single(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters