v1.6.2/cleanup
- remove api v2 - linting
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
const admin = require("firebase-admin");
|
||||
const admin = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
console.log(
|
||||
"Requested Join - UID - ",
|
||||
bodydata.uid,
|
||||
"\n\tRoom - ",
|
||||
bodydata.partyName
|
||||
);
|
||||
console.log('Requested Join - UID - ', bodydata.uid, '\n\tRoom - ', bodydata.partyName);
|
||||
// GET ROOM EXISTS, ROOM SOURCE, & ROOM PIN
|
||||
const [exists, roomSource, roomPin, adminUid] = await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.get()
|
||||
.then((roomSnap) => [
|
||||
roomSnap.exists,
|
||||
roomSnap.exists ? roomSnap.data().player.source : "",
|
||||
roomSnap.exists ? roomSnap.data().pin : "",
|
||||
roomSnap.exists ? roomSnap.data().adminUid : "",
|
||||
roomSnap.exists ? roomSnap.data().player.source : '',
|
||||
roomSnap.exists ? roomSnap.data().pin : '',
|
||||
roomSnap.exists ? roomSnap.data().adminUid : '',
|
||||
])
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
@@ -27,13 +22,13 @@ module.exports = async (req, res) => {
|
||||
);
|
||||
});
|
||||
if (exists && roomPin !== bodydata.partyPin)
|
||||
return res.status(401).send({ message: "Incorrect party pin" });
|
||||
return res.status(401).send({ message: 'Incorrect party pin' });
|
||||
if (adminUid === bodydata.uid) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection("users")
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
admin: true,
|
||||
@@ -43,15 +38,15 @@ module.exports = async (req, res) => {
|
||||
// GET IF USER EXISTS AND IS ADMIN
|
||||
const [userExists, userAdmin, userName] = await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection("users")
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.get()
|
||||
.then((userSnap) => [
|
||||
userSnap.exists,
|
||||
userSnap.exists ? userSnap.data().admin : false,
|
||||
userSnap.exists ? userSnap.data().name : "",
|
||||
userSnap.exists ? userSnap.data().name : '',
|
||||
])
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
@@ -65,15 +60,13 @@ module.exports = async (req, res) => {
|
||||
if (userName !== bodydata.userName) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection("users")
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.update({ name: bodydata.userName });
|
||||
}
|
||||
res
|
||||
.status(200)
|
||||
.send({ partyName: bodydata.partyName, message: "Joined a party" });
|
||||
res.status(200).send({ partyName: bodydata.partyName, message: 'Joined a party' });
|
||||
}
|
||||
// USER DOES NOT PRE-EXIST BUT SAME SOURCE AND RIGHT PIN
|
||||
else if (
|
||||
@@ -86,12 +79,12 @@ module.exports = async (req, res) => {
|
||||
) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection("messages")
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: "<system>",
|
||||
name: "",
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: `${bodydata.userName} joined the party.`,
|
||||
time: new Date(),
|
||||
})
|
||||
@@ -103,9 +96,9 @@ module.exports = async (req, res) => {
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.collection("users")
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
admin: false,
|
||||
@@ -117,9 +110,7 @@ module.exports = async (req, res) => {
|
||||
err
|
||||
);
|
||||
});
|
||||
res
|
||||
.status(200)
|
||||
.send({ partyName: bodydata.partyName, message: "Joined a party" });
|
||||
res.status(200).send({ partyName: bodydata.partyName, message: 'Joined a party' });
|
||||
}
|
||||
// ONLY WRONG SOURCE
|
||||
else if (exists && roomSource !== bodydata.source) {
|
||||
@@ -127,13 +118,13 @@ module.exports = async (req, res) => {
|
||||
if (userAdmin === true) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection("rooms")
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.update({
|
||||
player: {
|
||||
showName: null,
|
||||
source: bodydata.source,
|
||||
status: "NOT_PLAYING",
|
||||
status: 'NOT_PLAYING',
|
||||
time: 0,
|
||||
updatedBy: bodydata.uid,
|
||||
},
|
||||
@@ -142,11 +133,9 @@ module.exports = async (req, res) => {
|
||||
console.error(
|
||||
`Failed to update player source when admin joining party \n\t Room: ${partyName} \n\t User: ${bodydata.uid}`
|
||||
);
|
||||
res
|
||||
.status(500)
|
||||
.send({ message: "Unable to move party, please try again" });
|
||||
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" });
|
||||
} else res.status(404).send({ message: 'Party Not Found' });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user