misskey/src/server/api/endpoints/notes/show.ts
2018-05-02 18:06:16 +09:00

33 lines
646 B
TypeScript

/**
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Note, { pack } from '../../../../models/note';
/**
* Show a note
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get note
const note = await Note.findOne({
_id: noteId
});
if (note === null) {
return rej('note not found');
}
// Serialize
res(await pack(note, user, {
detail: true
}));
});