paricafe/src/server/api/endpoints/notes/reactions/delete.ts
Acid Chicken (硫酸鶏) bcc549fd8e
Fix style
2019-02-05 11:48:08 +09:00

46 lines
1.1 KiB
TypeScript

import * as mongo from 'mongodb';
import $ from 'cafy';
import ID, { transform } from '../../../../../misc/cafy-id';
import define from '../../../define';
import * as ms from 'ms';
import deleteReaction from '../../../../../services/note/reaction/delete';
import { IUser } from '../../../../../models/user';
import { getValiedNote } from '../../../common/getters';
export const meta = {
desc: {
'ja-JP': '指定した投稿へのリアクションを取り消します。',
'en-US': 'Unreact to a note.'
},
requireCredential: true,
kind: 'reaction-write',
limit: {
duration: ms('1hour'),
max: 5,
minInterval: ms('3sec')
},
params: {
noteId: {
validator: $.type(ID),
transform: transform,
desc: {
'ja-JP': '対象の投稿のID',
'en-US': 'Target note ID'
}
},
}
};
export default define(meta, (ps, user) => new Promise((res, rej) => {
deleteReactionById(user, ps.noteId)
.then(r => res(r)).catch(e => rej(e));
}));
async function deleteReactionById(user: IUser, noteId: mongo.ObjectID) {
const note = await getValiedNote(noteId);
await deleteReaction(user, note);
}