Skip to content

Commit

Permalink
fix: add null check in getting list of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal committed Feb 4, 2023
1 parent bf2cae6 commit 3447d74
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions server/schema/comment/comment.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ module.exports = {
getListOfComments: async (_parent, { ids = null, limit = DEF_LIMIT, offset = DEF_OFFSET }, { API: { Comment } }) => {
try {
const _comments = ids
? await Promise.all(ids.slice(offset, offset + limit).map((id) => Comment.findByID.loadMany([id, id])))
? await Promise.all(ids.slice(offset, offset + limit).map((id) => Comment.findByID.load(id)))
: await Comment.findAll(offset, limit);

if (!_comments || _comments.length === 0) {
throw APIError('NOT FOUND', null, { reason: 'Requested comments were not found' });
}
return _comments;
return _comments.filter((comment) => comment);
} catch (error) {
throw APIError(null, error);
}
Expand Down

0 comments on commit 3447d74

Please sign in to comment.