Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
[wip]implement #65
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Jul 22, 2017
1 parent 5da34a8 commit f592a4b
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/routes/users/id/timelines/home.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
'use strict';

const ApiResult = require('../../../../helpers/apiResult');
const Post = require('../../../../documentModels/post');
const UserFollowing = require('../../../../documentModels/userFollowing');

// TODO: 不完全な実装

exports.get = async (request) => {
const result = await request.checkRequestAsync({
query: [],
permissions: ['postRead', 'userRead']
});

if (result != null) {
return result;
}

return new ApiResult(501, 'not implemented');
let limit = request.query.limit;
if (limit != null) {
limit = parseInt(limit);
if (isNaN(limit) || limit <= 0 || limit > 100) {
return new ApiResult(400, 'limit is invalid');
}
}
else {
limit = 30;
}

let posts;

try {
const followings = await UserFollowing.findTargetsAsync(request.user.document._id, 30, request.db, request.config);
const ids = followings.map(i => i.document.target);

posts = await Post.findArrayAsync({
$and: [
{userId: {$in: ids}},
{type: 'status'}
]
}, false, limit, request.db, request.config);
}
catch(err) {
// noop
}

if (posts == null || posts.length == 0) {
return new ApiResult(204);
}

const serializedPosts = [];

for (const post of posts) {
serializedPosts.push(await post.serializeAsync(true));
}

return new ApiResult(200, {posts: serializedPosts});
};

0 comments on commit f592a4b

Please sign in to comment.