v1.6.0/admin only mode

This commit is contained in:
2020-08-01 13:53:58 -04:00
parent 8d8cf6d276
commit 9c600f383d
15 changed files with 197 additions and 88 deletions
+36
View File
@@ -0,0 +1,36 @@
const admin = require('firebase-admin');
module.exports = async (req, res) => {
const bodydata = JSON.parse(req.body);
const isAdmin = await admin
.firestore()
.collection('rooms')
.doc(req.params.rid)
.collection('users')
.doc(bodydata.uid)
.get()
.then((v) => {
if (v.exists) {
return v.data().admin;
}
return false;
})
.catch((err) => {
console.err('Failed to get party to update adminOnly', err);
return res.status(404).send({ message: 'Failed to get party.' });
});
if (!isAdmin) {
console.log('[UNAUTHORIZED] Requested Admin Mode Update - Room - ', req.params.rid);
res.status(401).send({ message: 'Not authorized to update admin only mode for this party.' });
return;
}
const adminOnly = req.params.adminOnly === 'true';
await admin.firestore().collection('rooms').doc(req.params.rid).update({
adminOnly
}).catch((err) => {
console.err('Failed to update adminOnly for party', err);
res.status(409).send({ message: 'Failed to update party.' });
});
res.status(200).send({ message: 'Updated admin only mode for party' });
return;
};