-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathget.js
More file actions
36 lines (29 loc) · 698 Bytes
/
get.js
File metadata and controls
36 lines (29 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const joi = require('joi')
const redis = require('../../../../models/redis')
const querySchema = joi.object({
limit: joi.number()
.default(10),
offset: joi.number()
.default(0)
})
.unknown()
.required()
function * getTweets () {
const { error, value: query } = joi.validate(this.query, querySchema)
if (error) {
this.throw(400)
}
let tweets = yield redis.zrevrangebyscore(redis.SET.tweets, Date.now(), 0, 'LIMIT', query.offset, query.limit)
tweets = tweets.map((string) => {
let tweet
try {
tweet = JSON.parse(string)
} catch (ex) {
/* ignore */
}
return tweet
})
this.body = tweets
}
module.exports = getTweets