sharkey/src/server/api/endpoints/notes/reactions/delete.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

import * as mongo from 'mongodb';
2018-11-02 03:32:24 +09:00
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
2018-11-02 13:47:44 +09:00
import define from '../../../define';
const ms = require('ms');
import deleteReaction from '../../../../../services/note/reaction/delete';
import { IUser } from '../../../../../models/user';
import { getValiedNote } from '../../../common/getters';
2016-12-29 07:49:51 +09:00
2018-07-17 04:36:44 +09:00
export const meta = {
desc: {
2018-08-29 06:59:43 +09:00
'ja-JP': '指定した投稿へのリアクションを取り消します。',
'en-US': 'Unreact to a note.'
2018-07-17 04:36:44 +09:00
},
requireCredential: true,
2018-11-02 03:32:24 +09:00
kind: 'reaction-write',
limit: {
duration: ms('1hour'),
max: 5,
minInterval: ms('3sec')
},
2018-11-02 03:32:24 +09:00
params: {
noteId: {
validator: $.type(ID),
transform: transform,
2018-11-03 22:49:36 +09:00
desc: {
'ja-JP': '対象の投稿のID',
'en-US': 'Target note ID'
}
2018-11-02 03:32:24 +09:00
},
}
2018-07-17 04:36:44 +09:00
};
export default define(meta, (ps, user) => new Promise((res, rej) => {
deleteReactionById(user, ps.noteId)
.then(r => res(r)).catch(e => rej(e));
2018-11-02 13:47:44 +09:00
}));
async function deleteReactionById(user: IUser, noteId: mongo.ObjectID) {
const note = await getValiedNote(noteId);
await deleteReaction(user, note);
}