set memberCount with groupData

v1.18.x
Barış Soner Uşaklı 10 years ago
parent a94e676043
commit 64359f4655

@ -4,7 +4,7 @@ var async = require('async'),
meta = require('../meta'),
plugins = require('../plugins'),
utils = require('../../public/src/utils'),
db = require('./../database');
db = require('../database');
module.exports = function(Groups) {
Groups.create = function(data, callback) {
@ -23,29 +23,28 @@ module.exports = function(Groups) {
return callback(new Error('[[error:group-already-exists]]'));
}
var timestamp = data.timestamp || Date.now();
var slug = utils.slugify(data.name),
groupData = {
name: data.name,
slug: slug,
createtime: timestamp,
userTitle: data.name,
description: data.description || '',
memberCount: 0,
deleted: '0',
hidden: data.hidden || '0',
system: system ? '1' : '0',
private: data.private || '1'
},
tasks = [
async.apply(db.sortedSetAdd, 'groups:createtime', timestamp, data.name),
async.apply(db.setObject, 'group:' + data.name, groupData)
];
var memberCount = data.hasOwnProperty('ownerUid') ? 1 : 0;
var slug = utils.slugify(data.name);
var groupData = {
name: data.name,
slug: slug,
createtime: timestamp,
userTitle: data.name,
description: data.description || '',
memberCount: memberCount,
deleted: '0',
hidden: data.hidden || '0',
system: system ? '1' : '0',
private: data.private || '1'
};
var tasks = [
async.apply(db.sortedSetAdd, 'groups:createtime', timestamp, data.name),
async.apply(db.setObject, 'group:' + data.name, groupData)
];
if (data.hasOwnProperty('ownerUid')) {
tasks.push(async.apply(db.setAdd, 'group:' + data.name + ':owners', data.ownerUid));
tasks.push(async.apply(db.sortedSetAdd, 'group:' + data.name + ':members', timestamp, data.ownerUid));
tasks.push(async.apply(db.setObjectField, 'group:' + data.name, 'memberCount', 1));
groupData.ownerUid = data.ownerUid;
}

Loading…
Cancel
Save