forked from avasdao/nexa-exchange
-
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
Ava's DAO
committed
Jan 1, 2024
1 parent
a842dd1
commit f112ea1
Showing
1 changed file
with
50 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Import modules. */ | ||
import PouchDB from 'pouchdb' | ||
|
||
/* Initialize databases. */ | ||
const poolsDb = new PouchDB(`http://${process.env.COUCHDB_USER}:${process.env.COUCHDB_PASSWORD}@127.0.0.1:5984/pools`) | ||
|
||
export default defineEventHandler(async (event) => { | ||
/* Initialize locals. */ | ||
let query | ||
let response | ||
let tokens | ||
|
||
/* Set (request) query. */ | ||
query = getQuery(event) | ||
console.log('POOL QUERY', query) | ||
|
||
/* Set session id. */ | ||
// sessionid = query?.sid | ||
|
||
/* Request (all) pools. */ | ||
response = await poolsDb | ||
.allDocs({ | ||
include_docs: true, | ||
}) | ||
.catch(err => console.error(err)) | ||
// console.log('RESPONSE', response) | ||
|
||
/* Validate response. */ | ||
if (!response) { | ||
return [] | ||
} | ||
|
||
/* Parse tokens. */ | ||
tokens = response.rows.map(_asset => { | ||
let token | ||
|
||
token = { | ||
id: _asset.id, | ||
..._asset.doc, | ||
} | ||
|
||
delete token._id | ||
delete token._rev | ||
|
||
return token | ||
}) | ||
|
||
/* Return (asset) tokens. */ | ||
return tokens | ||
}) |