-
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.
- Loading branch information
Showing
4 changed files
with
86 additions
and
53 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,87 @@ | ||
import { baseRequest } from "./utils"; | ||
|
||
const query = "SELECT * FROM events WHERE name = $1 AND module = $2 AND chainid = $3 LIMIT $4 OFFSET $5" | ||
|
||
export const resolvers = { | ||
Query: { | ||
getEvents: async (_, args) => { | ||
getCommitments: async (_, args) => { | ||
const offset = (args.page - 1) * args.size; | ||
|
||
const query = "SELECT * FROM events LIMIT $1 OFFSET $2;"; | ||
const result = await baseRequest(query, [ | ||
'new-commitment', | ||
args.module, | ||
args.chainId, | ||
args.size, | ||
offset, | ||
]); | ||
|
||
const events = | ||
result?.rows.map(({ params }) => { | ||
console.log('params', params) | ||
const value = params[0]?.int; | ||
|
||
const order = params[1]?.int; | ||
|
||
const result = await baseRequest(query, [args.size, offset]); | ||
return { | ||
order, | ||
value, | ||
}; | ||
}) || []; | ||
|
||
return result.rows; | ||
const hasNextPage = events?.length === args.size; | ||
|
||
return { | ||
events, | ||
hasNextPage, | ||
currentPage: args.page, | ||
itemCount: events.length, | ||
}; | ||
}, | ||
|
||
getEventsByModule: async (_, args) => { | ||
getNullifiers: async (_, args) => { | ||
const offset = (args.page - 1) * args.size; | ||
|
||
const query = | ||
"SELECT * FROM events WHERE module = $1 LIMIT $2 OFFSET $3;"; | ||
const result = await baseRequest(query, [ | ||
'new-nullifier', | ||
args.module, | ||
args.chainId, | ||
args.size, | ||
offset, | ||
]); | ||
|
||
const events = result?.rows.map(({ params }) => params[0]?.int) || []; | ||
|
||
const result = await baseRequest(query, [args.module, args.size, offset]); | ||
const hasNextPage = events.length === args.size; | ||
|
||
return result.rows; | ||
return { | ||
events, | ||
hasNextPage, | ||
currentPage: args.page, | ||
itemCount: events.length, | ||
}; | ||
}, | ||
|
||
getTransactions: async (_, args) => { | ||
getUtxos: async (_, args) => { | ||
const offset = (args.page - 1) * args.size; | ||
|
||
const query = "SELECT * FROM transactions LIMIT $1 OFFSET $2;"; | ||
const result = await baseRequest(query, [ | ||
'new-encrypted-output', | ||
args.module, | ||
args.chainId, | ||
args.size, | ||
offset, | ||
]); | ||
|
||
const events = result?.rows.map(({ params }) => params[0]) || []; | ||
|
||
const result = await baseRequest(query, [args.size, offset]); | ||
const hasNextPage = events.length === args.size; | ||
|
||
return result.rows; | ||
return { | ||
events, | ||
hasNextPage, | ||
currentPage: args.page, | ||
itemCount: events.length, | ||
}; | ||
}, | ||
}, | ||
}; |
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