diff options
Diffstat (limited to 'src/server/api/endpoints/notes/reactions.ts')
| -rw-r--r-- | src/server/api/endpoints/notes/reactions.ts | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/server/api/endpoints/notes/reactions.ts b/src/server/api/endpoints/notes/reactions.ts index 54cbd23379..3e0656c4f8 100644 --- a/src/server/api/endpoints/notes/reactions.ts +++ b/src/server/api/endpoints/notes/reactions.ts @@ -1,8 +1,9 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; -import Note from '../../../../models/note'; import Reaction, { pack } from '../../../../models/note-reaction'; import define from '../../define'; +import { getValiedNote } from '../../common/getters'; +import { ApiError } from '../../error'; export const meta = { desc: { @@ -41,24 +42,23 @@ export const meta = { validator: $.optional.type(ID), transform: transform, }, - } -}; + }, -export default define(meta, (ps, user) => new Promise(async (res, rej) => { - // Check if both of sinceId and untilId is specified - if (ps.sinceId && ps.untilId) { - return rej('cannot set sinceId and untilId'); + errors: { + noSuchNote: { + message: 'No such note.', + code: 'NO_SUCH_NOTE', + id: '263fff3d-d0e1-4af4-bea7-8408059b451a' + } } +}; - // Lookup note - const note = await Note.findOne({ - _id: ps.noteId +export default define(meta, async (ps, user) => { + const note = await getValiedNote(ps.noteId).catch(e => { + if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); + throw e; }); - if (note === null) { - return rej('note not found'); - } - const query = { noteId: note._id } as any; @@ -78,13 +78,11 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => { }; } - const reactions = await Reaction - .find(query, { - limit: ps.limit, - skip: ps.offset, - sort: sort - }); + const reactions = await Reaction.find(query, { + limit: ps.limit, + skip: ps.offset, + sort: sort + }); - // Serialize - res(await Promise.all(reactions.map(reaction => pack(reaction, user)))); -})); + return await Promise.all(reactions.map(reaction => pack(reaction, user))); +}); |