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

Commit

Permalink
[wip]implement #64
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Jul 23, 2017
1 parent 162e5a5 commit ae2c697
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/routes/users/id/timelines/user.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
'use strict';

const ApiResult = require('../../../../helpers/apiResult');
const Post = require('../../../../documentModels/post');
const User = require('../../../../documentModels/user');

// 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');
// user
const user = await User.findByIdAsync(request.params.id, request.db, request.config);
if (user == null) {
return new ApiResult(404, 'user as premise not found');
}

// limit
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 {
posts = await Post.findArrayAsync({
$and: [
{userId: user.document._id},
{type: 'status'}
]
}, false, limit, request.db, request.config);
}
catch(err) {
console.dir(err);
}

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 ae2c697

Please sign in to comment.