Skip to content

Commit

Permalink
sort responses
Browse files Browse the repository at this point in the history
  • Loading branch information
tacyarg committed Oct 3, 2019
1 parent b5477eb commit 70b239e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 7 deletions.
10 changes: 5 additions & 5 deletions libs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = ({ events, trades, bybit, stats, traders, users, tokens }) => {
return { user, token }
},
async listUsers() {
return users.list()
return users.listSorted()
},
async listTraders() {
return traders.keys()
Expand All @@ -51,13 +51,13 @@ module.exports = ({ events, trades, bybit, stats, traders, users, tokens }) => {
assert(token, 'token required')
const { valid, userid, type } = await tokens.get(token)
assert(valid, 'token is no longer valid')
return trades.getBy('userid', userid)
return trades.listUserSorted(userid)
},
async listMyEvents({ token }) {
assert(token, 'token required')
const { valid, userid, type } = await tokens.get(token)
assert(valid, 'token is no longer valid')
return events.getBy('userid', userid)
return events.listUserSorted(userid)
},
async getMyStats({ token }) {
assert(token, 'token required')
Expand All @@ -69,7 +69,7 @@ module.exports = ({ events, trades, bybit, stats, traders, users, tokens }) => {
},
async listMyTokens({ token }) {
const { userid } = await tokens.get(token)
return tokens.getBy('userid', userid)
}
return tokens.listUserSorted(userid)
},
}
}
17 changes: 17 additions & 0 deletions models/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ module.exports = async con => {
const query = table.table().orderBy({index: 'created'})
return table.streamify(query)
},
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.coerceTo('array')
return table.run(query)
},
// listTopSites() {
// const query = table
// .table()
Expand Down
17 changes: 17 additions & 0 deletions models/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ module.exports = async con => {
const query = table.table().orderBy({index: 'created'})
return table.streamify(query)
},
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.coerceTo('array')
return table.run(query)
},
// listTopSites() {
// const query = table
// .table()
Expand Down
17 changes: 17 additions & 0 deletions models/tickers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,22 @@ module.exports = async con => {
const query = table.table().orderBy({index: 'created'})
return table.streamify(query)
},
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.coerceTo('array')
return table.run(query)
},
}
}
17 changes: 17 additions & 0 deletions models/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ module.exports = async con => {
expires: ONE_DAY_MS,
})
},
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.coerceTo('array')
return table.run(query)
},
// listTopSites() {
// const query = table
// .table()
Expand Down
19 changes: 17 additions & 2 deletions models/trades.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ module.exports = async con => {
const schema = {
table: 'trades',
indices: ['created', 'type', 'provider', 'userid'],
compound: [
{
//Compound index
name: 'created_userid',
fields: ['created', 'userid'],
},
],
}

const table = await Table(con, schema)
Expand All @@ -18,15 +25,23 @@ module.exports = async con => {
const query = table.table().orderBy({ index: 'created' })
return table.streamify(query)
},
listClosed() {
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.filter({ done: true })
.limit(100)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
const query = table
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.coerceTo('array')
return table.run(query)
},
// listTopSites() {
// const query = table
// .table()
Expand Down
8 changes: 8 additions & 0 deletions models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = async con => {
const query = table.table().orderBy({ index: 'created' })
return table.streamify(query)
},
listSorted() {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.coerceTo('array')
return table.run(q)
},
async create(username) {
assert(username, 'username required')
username = username.toLowerCase()
Expand Down

0 comments on commit 70b239e

Please sign in to comment.