mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-30 13:23:09 +02:00
移行
This commit is contained in:
parent
4179685bb6
commit
42d4e6610f
1 changed files with 27 additions and 9 deletions
|
@ -3,22 +3,40 @@ import Note from '../../../../../models/note';
|
|||
import create from '../../../../../services/note/reaction/create';
|
||||
import { validateReaction } from '../../../../../models/note-reaction';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
|
||||
export const meta = {
|
||||
name: 'notes/reactions/create',
|
||||
|
||||
desc: {
|
||||
ja: '投稿にリアクションします。'
|
||||
},
|
||||
|
||||
params: {
|
||||
noteId: $.type(ID).note({
|
||||
desc: {
|
||||
ja: '対象の投稿'
|
||||
}
|
||||
}),
|
||||
|
||||
reaction: $.str.pipe(validateReaction.ok).note({
|
||||
desc: {
|
||||
ja: 'リアクションの種類'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* React to a note
|
||||
*/
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'reaction' parameter
|
||||
const [reaction, reactionErr] = $.str.pipe(validateReaction.ok).get(params.reaction);
|
||||
if (reactionErr) return rej('invalid reaction param');
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
// Fetch reactee
|
||||
const note = await Note.findOne({
|
||||
_id: noteId
|
||||
_id: ps.noteId
|
||||
});
|
||||
|
||||
if (note === null) {
|
||||
|
@ -26,7 +44,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
|||
}
|
||||
|
||||
try {
|
||||
await create(user, note, reaction);
|
||||
await create(user, note, ps.reaction);
|
||||
} catch (e) {
|
||||
rej(e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue