diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-02-05 03:59:29 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-02-05 03:59:29 +0900 |
| commit | dbd3cdb308d2edf600b20a8b632045c6163ae326 (patch) | |
| tree | de3630065fcddeb1916668ef3b0b43a219340e2e /src/api/endpoints/users/posts.ts | |
| parent | Fix (diff) | |
| parent | Merge pull request #1097 from syuilo/refactor (diff) | |
| download | sharkey-dbd3cdb308d2edf600b20a8b632045c6163ae326.tar.gz sharkey-dbd3cdb308d2edf600b20a8b632045c6163ae326.tar.bz2 sharkey-dbd3cdb308d2edf600b20a8b632045c6163ae326.zip | |
Merge remote-tracking branch 'refs/remotes/origin/master' into vue-#972
Diffstat (limited to 'src/api/endpoints/users/posts.ts')
| -rw-r--r-- | src/api/endpoints/users/posts.ts | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/api/endpoints/users/posts.ts b/src/api/endpoints/users/posts.ts index fe821cf17a..0c8bceee3d 100644 --- a/src/api/endpoints/users/posts.ts +++ b/src/api/endpoints/users/posts.ts @@ -2,9 +2,8 @@ * Module dependencies */ import $ from 'cafy'; -import Post from '../../models/post'; +import Post, { pack } from '../../models/post'; import User from '../../models/user'; -import serialize from '../../serializers/post'; /** * Get posts of a user @@ -42,21 +41,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$; if (sinceIdErr) return rej('invalid since_id param'); - // Get 'max_id' parameter - const [maxId, maxIdErr] = $(params.max_id).optional.id().$; - if (maxIdErr) return rej('invalid max_id param'); + // Get 'until_id' parameter + const [untilId, untilIdErr] = $(params.until_id).optional.id().$; + if (untilIdErr) return rej('invalid until_id param'); // Get 'since_date' parameter const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$; if (sinceDateErr) throw 'invalid since_date param'; - // Get 'max_date' parameter - const [maxDate, maxDateErr] = $(params.max_date).optional.number().$; - if (maxDateErr) throw 'invalid max_date param'; + // Get 'until_date' parameter + const [untilDate, untilDateErr] = $(params.until_date).optional.number().$; + if (untilDateErr) throw 'invalid until_date param'; - // Check if only one of since_id, max_id, since_date, max_date specified - if ([sinceId, maxId, sinceDate, maxDate].filter(x => x != null).length > 1) { - throw 'only one of since_id, max_id, since_date, max_date can be specified'; + // Check if only one of since_id, until_id, since_date, until_date specified + if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) { + throw 'only one of since_id, until_id, since_date, until_date can be specified'; } const q = userId !== undefined @@ -88,18 +87,18 @@ module.exports = (params, me) => new Promise(async (res, rej) => { query._id = { $gt: sinceId }; - } else if (maxId) { + } else if (untilId) { query._id = { - $lt: maxId + $lt: untilId }; } else if (sinceDate) { sort._id = 1; query.created_at = { $gt: new Date(sinceDate) }; - } else if (maxDate) { + } else if (untilDate) { query.created_at = { - $lt: new Date(maxDate) + $lt: new Date(untilDate) }; } @@ -124,6 +123,6 @@ module.exports = (params, me) => new Promise(async (res, rej) => { // Serialize res(await Promise.all(posts.map(async (post) => - await serialize(post, me) + await pack(post, me) ))); }); |