all files / src/socket.io/posts/ move.js

35.29% Statements 6/17
0% Branches 0/9
20% Functions 1/5
35.29% Lines 6/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                             
'use strict';
 
var async = require('async');
var privileges = require('../../privileges');
var topics = require('../../topics');
var socketHelpers = require('../helpers');
 
module.exports = function(SocketPosts) {
 
	SocketPosts.movePost = function(socket, data, callback) {
		if (!socket.uid) {
			return callback(new Error('[[error:not-logged-in]]'));
		}
 
		if (!data || !data.pid || !data.tid) {
			return callback(new Error('[[error:invalid-data]]'));
		}
 
		async.waterfall([
			function (next) {
				privileges.posts.canMove(data.pid, socket.uid, next);
			},
			function (canMove, next) {
				if (!canMove){
					return next(new Error('[[error:no-privileges]]'));
				}
 
				topics.movePostToTopic(data.pid, data.tid, next);
			},
			function (next) {
				socketHelpers.sendNotificationToPostOwner(data.pid, socket.uid, 'notifications:moved_your_post');
				next();
			}
		], callback);
	};
 
};