Skip to content

Commit

Permalink
chore(api): txnType attribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shawakash committed Mar 7, 2024
1 parent 271ca55 commit 4056d42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
62 changes: 21 additions & 41 deletions backend/api/src/db/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ const chain = Chain(HASURA_URL, {
*/
export const insertTxn = async ({
clientId,
blockTime,
time,
amount,
fee,
from,
to,
postBalances,
preBalances,
recentBlockhash,
signature,
blockHash,
hash,
network,
slot,
cluster,
nonce,
chainId,
}: InsertTxnType): Promise<{
status: dbResStatus;
Expand All @@ -58,19 +55,15 @@ export const insertTxn = async ({
{
object: {
clientId,
signature,
network,
hash,
slot,
amount,
blockTime,
fee,
from,
to,
preBalances,
postBalances,
recentBlockhash,
blockHash,
cluster,
nonce,
chainId,
},
},
Expand Down Expand Up @@ -120,22 +113,18 @@ export const getTxns = async ({
},
{
id: true,
//@ts-ignore
signature: true,
hash: true,
amount: true,
blockTime: true,
time: true,
clientId: true,
fee: true,
time: true,
from: true,
network: true,
//@ts-ignore
postBalances: true,
//@ts-ignore
preBalances: true,
recentBlockhash: true,
blockHash: true,
slot: true,
to: true,
cluster: true,
status: true
},
],
},
Expand All @@ -160,7 +149,7 @@ export const getTxns = async ({
*/
export const getTxnByHash = async ({
network,
sign,
hash,
clientId,
}: TxnQuerySignType): Promise<{
status: dbResStatus;
Expand All @@ -172,29 +161,25 @@ export const getTxnByHash = async ({
transactions: [
{
where: {
signature: { _contains: sign },
hash: { _eq: hash },
clientId: { _eq: clientId },
network: { _eq: network },
},
},
{
id: true,
//@ts-ignore
signature: true,
amount: true,
blockTime: true,
time: true,
clientId: true,
fee: true,
time: true,
from: true,
network: true,
//@ts-ignore
postBalances: true,
//@ts-ignore
preBalances: true,
recentBlockhash: true,
blockHash: true,
slot: true,
to: true,
hash: true,
cluster: true,
status: true
},
],
},
Expand Down Expand Up @@ -236,23 +221,18 @@ export const getAllTxn = async ({
},
{
id: true,
//@ts-ignore
signature: true,
hash: true,
amount: true,
blockTime: true,
time: true,
clientId: true,
fee: true,
time: true,
from: true,
network: true,
//@ts-ignore
postBalances: true,
//@ts-ignore
preBalances: true,
recentBlockhash: true,
blockHash: true,
slot: true,
to: true,
cluster: true,
status: true
},
],
},
Expand Down
6 changes: 3 additions & 3 deletions backend/api/src/routes/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ txnRouter.get("/get", async (req, res) => {
//@ts-ignore
const id = req.id as string;
if (id) {
let { network, sign } = TxnQeuryByHash.parse(req.query);
let { network, hash } = TxnQeuryByHash.parse(req.query);
/**
* Cache
*/
const isTxn = await cache.txn.cacheGetTxnBySign(sign);
const isTxn = await cache.txn.cacheGetTxnBySign(hash);
if (isTxn) {
return res.status(302).json({ txn: isTxn, status: responseStatus.Ok });
}
//Db query
const txn = await getTxnByHash({ network, sign, clientId: id });
const txn = await getTxnByHash({ network, hash, clientId: id });
if (txn.status == dbResStatus.Error) {
return res
.status(503)
Expand Down

0 comments on commit 4056d42

Please sign in to comment.