mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 10:35:55 +01:00
refactor(api): post move to write API
This commit is contained in:
@@ -13,6 +13,7 @@ const events = require('../events');
|
||||
const privileges = require('../privileges');
|
||||
const apiHelpers = require('./helpers');
|
||||
const websockets = require('../socket.io');
|
||||
const socketHelpers = require('../socket.io/helpers');
|
||||
|
||||
const postsAPI = module.exports;
|
||||
|
||||
@@ -195,6 +196,27 @@ async function isMainAndLastPost(pid) {
|
||||
};
|
||||
}
|
||||
|
||||
postsAPI.move = async function (caller, data) {
|
||||
const canMove = await Promise.all([
|
||||
privileges.topics.isAdminOrMod(data.tid, caller.uid),
|
||||
privileges.posts.canMove(data.pid, caller.uid),
|
||||
]);
|
||||
if (!canMove.every(Boolean)) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
await topics.movePostToTopic(caller.uid, data.pid, data.tid);
|
||||
|
||||
const [postDeleted, topicDeleted] = await Promise.all([
|
||||
posts.getPostField(data.pid, 'deleted'),
|
||||
topics.getTopicField(data.tid, 'deleted'),
|
||||
]);
|
||||
|
||||
if (!postDeleted && !topicDeleted) {
|
||||
socketHelpers.sendNotificationToPostOwner(data.pid, caller.uid, 'move', 'notifications:moved_your_post');
|
||||
}
|
||||
};
|
||||
|
||||
postsAPI.upvote = async function (caller, data) {
|
||||
return await apiHelpers.postCommand(caller, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user