mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 10:12:21 +00:00
store group name on firebase
This commit is contained in:
parent
4c89538d18
commit
995e3a796d
2 changed files with 20 additions and 3 deletions
|
|
@ -192,6 +192,7 @@ api.create = function(req, res, next) {
|
|||
function(cb){user.save(cb)},
|
||||
function(saved,ct,cb){group.save(cb)},
|
||||
function(saved,ct,cb){
|
||||
firebase.updateGroupData(saved);
|
||||
firebase.addUserToGroup(saved._id, user._id);
|
||||
saved.populate('members', nameFields, cb);
|
||||
}
|
||||
|
|
@ -211,6 +212,7 @@ api.create = function(req, res, next) {
|
|||
group.save(cb);
|
||||
},
|
||||
function(saved, count, cb){
|
||||
firebase.updateGroupData(saved);
|
||||
firebase.addUserToGroup(saved._id, user._id);
|
||||
saved.populate('members', nameFields, cb);
|
||||
}
|
||||
|
|
@ -236,6 +238,8 @@ api.update = function(req, res, next) {
|
|||
|
||||
group.save(function(err, saved){
|
||||
if (err) return next(err);
|
||||
|
||||
firebase.updateGroupData(saved);
|
||||
res.send(204);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,16 @@ if(isProd){
|
|||
|
||||
var api = module.exports = {};
|
||||
|
||||
api.updateGroupData = function(group){
|
||||
if(!isProd) return;
|
||||
if(!group) throw new Error('group is required.');
|
||||
|
||||
firebaseRef.child('rooms/' + group._id)
|
||||
.set({
|
||||
name: group.name
|
||||
});
|
||||
};
|
||||
|
||||
api.addUserToGroup = function(groupId, userId){
|
||||
if(!isProd) return;
|
||||
// TODO is throw ok? we don't have callbacks
|
||||
|
|
@ -39,12 +49,15 @@ api.removeUserFromGroup = function(groupId, userId){
|
|||
.remove();
|
||||
};
|
||||
|
||||
// FIXME not really necessary as long as we only store room data,
|
||||
// as empty objects are automatically deleted (/members/... in future...)
|
||||
api.deleteGroup = function(groupId){
|
||||
if(!isProd) return;
|
||||
if(!groupId) throw new Error('groupId is required.');
|
||||
if(!groupId) throw new Error('groupId is required.');7
|
||||
|
||||
firebaseRef.child('rooms/' + groupId)
|
||||
.remove();
|
||||
|
||||
// FIXME not really necessary as long as we only store room data,
|
||||
// as empty objects are automatically deleted (/members/... in future...)
|
||||
firebaseRef.child('members/' + groupId)
|
||||
.remove();
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue