v1.6.0/admin only mode
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user