v1.2.1-beta/functions admin change source
This commit is contained in:
+26
-5
@@ -144,14 +144,14 @@ const joinRoom = async (req, res) => {
|
||||
err
|
||||
);
|
||||
});
|
||||
const userExists = await admin
|
||||
const [userExists, userAdmin] = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.roomId)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.get()
|
||||
.then((userSnap) => userSnap.exists)
|
||||
.then((userSnap) => [userSnap.exists, userSnap.exists ? userSnap.data().admin : false])
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to get user when joining room : \n\t Room: ${bodydata.roomId} \n\t User: ${bodydata.uid}`,
|
||||
@@ -216,9 +216,30 @@ const joinRoom = async (req, res) => {
|
||||
res.status(200).send({ roomId: bodydata.roomId, message: 'Joined a party' });
|
||||
} else if (!userExists && !bodydata.userName)
|
||||
res.status(400).send({ message: 'Missing user name' });
|
||||
else if (exists && roomSource !== bodydata.source)
|
||||
res.status(417).send({ message: `This party is on ${roomSource}` });
|
||||
else res.status(404).send({ message: 'Party Not Found' });
|
||||
else if (exists && roomSource !== bodydata.source) {
|
||||
if (userAdmin === true) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.roomId)
|
||||
.update({
|
||||
player: {
|
||||
showName: null,
|
||||
source: roomSource,
|
||||
status: 'NOT_PLAYING',
|
||||
time: 0,
|
||||
updatedBy: bodydata.uid,
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to update player source when admin joining party \n\t Room: ${roomId} \n\t User: ${bodydata.uid}`
|
||||
);
|
||||
res.status(500).send({ message: 'Unable to move party, please try again' });
|
||||
});
|
||||
res.status(200).send({ message: `Moved party to ${roomSource}` });
|
||||
} else res.status(417).send({ message: `This party is on ${roomSource}` });
|
||||
} else res.status(404).send({ message: 'Party Not Found' });
|
||||
};
|
||||
|
||||
const sendMessage = async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user