v1.6.0/release
This commit is contained in:
@@ -1,43 +1,48 @@
|
|||||||
const admin = require('firebase-admin');
|
const admin = require("firebase-admin");
|
||||||
|
|
||||||
module.exports = async (req, res) => {
|
module.exports = async (req, res) => {
|
||||||
const bodydata = JSON.parse(req.body);
|
const bodydata = JSON.parse(req.body);
|
||||||
console.log('Requested Create - UID - ', bodydata.uid);
|
console.log("Requested Create - UID - ", bodydata.uid);
|
||||||
if (!bodydata.userName) res.status(400).send({ message: 'Missing user name' });
|
if (!bodydata.userName)
|
||||||
if (!bodydata.partyName) res.status(400).send({ message: 'Missing party name' });
|
res.status(400).send({ message: "Missing user name" });
|
||||||
if (!bodydata.partyPin) res.status(400).send({ message: 'Missing party pin' });
|
if (!bodydata.partyName)
|
||||||
|
res.status(400).send({ message: "Missing party name" });
|
||||||
|
if (!bodydata.partyPin)
|
||||||
|
res.status(400).send({ message: "Missing party pin" });
|
||||||
const roomNameTaken = await admin
|
const roomNameTaken = await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName.replace('/', '\\'))
|
.doc(bodydata.partyName.replace("/", "\\"))
|
||||||
.get()
|
.get()
|
||||||
.then((docSnap) => docSnap.exists);
|
.then((docSnap) => docSnap.exists);
|
||||||
if (roomNameTaken) return res.status(409).send({ message: 'That party name is already taken' });
|
if (roomNameTaken)
|
||||||
|
return res
|
||||||
|
.status(409)
|
||||||
|
.send({ message: "That party name is already taken" });
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.set({
|
.set({
|
||||||
name: bodydata.partyName,
|
name: bodydata.partyName,
|
||||||
pin: bodydata.partyPin,
|
pin: bodydata.partyPin,
|
||||||
player: bodydata.player,
|
player: bodydata.player,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
|
||||||
adminUid: bodydata.uid,
|
adminUid: bodydata.uid,
|
||||||
adminOnly: bodydata.adminOnly,
|
adminOnly: bodydata.adminOnly,
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
res.status(500).send({ message: 'Unable to start party.' });
|
res.status(500).send({ message: "Unable to start party." });
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('messages')
|
.collection("messages")
|
||||||
.add({
|
.add({
|
||||||
uid: '<system>',
|
uid: "<system>",
|
||||||
name: '',
|
name: "",
|
||||||
text: `${bodydata.userName} started the party.`,
|
text: `${bodydata.userName} started the party.`,
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
})
|
})
|
||||||
@@ -49,9 +54,9 @@ module.exports = async (req, res) => {
|
|||||||
});
|
});
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('users')
|
.collection("users")
|
||||||
.doc(bodydata.uid)
|
.doc(bodydata.uid)
|
||||||
.set({
|
.set({
|
||||||
admin: true,
|
admin: true,
|
||||||
@@ -63,5 +68,7 @@ module.exports = async (req, res) => {
|
|||||||
err
|
err
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
|
res
|
||||||
|
.status(201)
|
||||||
|
.send({ roomId: bodydata.partyName, message: "Started a party!" });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
const admin = require('firebase-admin');
|
const admin = require("firebase-admin");
|
||||||
|
|
||||||
module.exports = async (req, res) => {
|
module.exports = async (req, res) => {
|
||||||
const bodydata = JSON.parse(req.body);
|
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
|
// GET ROOM EXISTS, ROOM SOURCE, & ROOM PIN
|
||||||
const [exists, roomSource, roomPin, adminUid] = await admin
|
const [exists, roomSource, roomPin, adminUid] = await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.get()
|
.get()
|
||||||
.then((roomSnap) => [
|
.then((roomSnap) => [
|
||||||
roomSnap.exists,
|
roomSnap.exists,
|
||||||
roomSnap.exists ? roomSnap.data().player.source : '',
|
roomSnap.exists ? roomSnap.data().player.source : "",
|
||||||
roomSnap.exists ? roomSnap.data().pin : '',
|
roomSnap.exists ? roomSnap.data().pin : "",
|
||||||
roomSnap.exists ? roomSnap.data().adminUid : '',
|
roomSnap.exists ? roomSnap.data().adminUid : "",
|
||||||
])
|
])
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -22,13 +27,13 @@ module.exports = async (req, res) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
if (exists && roomPin !== bodydata.partyPin)
|
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) {
|
if (adminUid === bodydata.uid) {
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('users')
|
.collection("users")
|
||||||
.doc(bodydata.uid)
|
.doc(bodydata.uid)
|
||||||
.set({
|
.set({
|
||||||
admin: true,
|
admin: true,
|
||||||
@@ -38,15 +43,15 @@ module.exports = async (req, res) => {
|
|||||||
// GET IF USER EXISTS AND IS ADMIN
|
// GET IF USER EXISTS AND IS ADMIN
|
||||||
const [userExists, userAdmin, userName] = await admin
|
const [userExists, userAdmin, userName] = await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('users')
|
.collection("users")
|
||||||
.doc(bodydata.uid)
|
.doc(bodydata.uid)
|
||||||
.get()
|
.get()
|
||||||
.then((userSnap) => [
|
.then((userSnap) => [
|
||||||
userSnap.exists,
|
userSnap.exists,
|
||||||
userSnap.exists ? userSnap.data().admin : false,
|
userSnap.exists ? userSnap.data().admin : false,
|
||||||
userSnap.exists ? userSnap.data().name : '',
|
userSnap.exists ? userSnap.data().name : "",
|
||||||
])
|
])
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -60,13 +65,15 @@ module.exports = async (req, res) => {
|
|||||||
if (userName !== bodydata.userName) {
|
if (userName !== bodydata.userName) {
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('users')
|
.collection("users")
|
||||||
.doc(bodydata.uid)
|
.doc(bodydata.uid)
|
||||||
.update({ name: bodydata.userName });
|
.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
|
// USER DOES NOT PRE-EXIST BUT SAME SOURCE AND RIGHT PIN
|
||||||
else if (
|
else if (
|
||||||
@@ -79,12 +86,12 @@ module.exports = async (req, res) => {
|
|||||||
) {
|
) {
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('messages')
|
.collection("messages")
|
||||||
.add({
|
.add({
|
||||||
uid: '<system>',
|
uid: "<system>",
|
||||||
name: '',
|
name: "",
|
||||||
text: `${bodydata.userName} joined the party.`,
|
text: `${bodydata.userName} joined the party.`,
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
})
|
})
|
||||||
@@ -96,9 +103,9 @@ module.exports = async (req, res) => {
|
|||||||
});
|
});
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.collection('users')
|
.collection("users")
|
||||||
.doc(bodydata.uid)
|
.doc(bodydata.uid)
|
||||||
.set({
|
.set({
|
||||||
admin: false,
|
admin: false,
|
||||||
@@ -110,20 +117,9 @@ module.exports = async (req, res) => {
|
|||||||
err
|
err
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
await admin
|
res
|
||||||
.firestore()
|
.status(200)
|
||||||
.collection('rooms')
|
.send({ partyName: bodydata.partyName, message: "Joined a party" });
|
||||||
.doc(bodydata.partyName)
|
|
||||||
.update({
|
|
||||||
updatedAt: new Date(),
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(
|
|
||||||
`Failed to set updated time when joining party : \n\t Room: ${partyName} \n\t User: ${bodydata.uid}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
});
|
|
||||||
res.status(200).send({ partyName: bodydata.partyName, message: 'Joined a party' });
|
|
||||||
}
|
}
|
||||||
// ONLY WRONG SOURCE
|
// ONLY WRONG SOURCE
|
||||||
else if (exists && roomSource !== bodydata.source) {
|
else if (exists && roomSource !== bodydata.source) {
|
||||||
@@ -131,13 +127,13 @@ module.exports = async (req, res) => {
|
|||||||
if (userAdmin === true) {
|
if (userAdmin === true) {
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(bodydata.partyName)
|
.doc(bodydata.partyName)
|
||||||
.update({
|
.update({
|
||||||
player: {
|
player: {
|
||||||
showName: null,
|
showName: null,
|
||||||
source: bodydata.source,
|
source: bodydata.source,
|
||||||
status: 'NOT_PLAYING',
|
status: "NOT_PLAYING",
|
||||||
time: 0,
|
time: 0,
|
||||||
updatedBy: bodydata.uid,
|
updatedBy: bodydata.uid,
|
||||||
},
|
},
|
||||||
@@ -146,9 +142,11 @@ module.exports = async (req, res) => {
|
|||||||
console.error(
|
console.error(
|
||||||
`Failed to update player source when admin joining party \n\t Room: ${partyName} \n\t User: ${bodydata.uid}`
|
`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}` });
|
res.status(200).send({ message: `Moved party to ${roomSource}` });
|
||||||
} else res.status(417).send({ message: `This party is on ${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" });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,47 +1,39 @@
|
|||||||
const admin = require('firebase-admin');
|
const admin = require("firebase-admin");
|
||||||
|
|
||||||
module.exports = async (req, res) => {
|
module.exports = async (req, res) => {
|
||||||
const { name, text, uid, roomId, type, replyTo } = JSON.parse(req.body);
|
const { name, text, uid, roomId, type, replyTo } = JSON.parse(req.body);
|
||||||
|
|
||||||
const roomExists = await admin
|
const roomExists = await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(roomId)
|
.doc(roomId)
|
||||||
.get()
|
.get()
|
||||||
.then((roomSnap) => roomSnap.exists);
|
.then((roomSnap) => roomSnap.exists);
|
||||||
if (roomExists) {
|
if (roomExists) {
|
||||||
await admin
|
await admin
|
||||||
.firestore()
|
.firestore()
|
||||||
.collection('rooms')
|
.collection("rooms")
|
||||||
.doc(roomId)
|
.doc(roomId)
|
||||||
.collection('messages')
|
.collection("messages")
|
||||||
.add({
|
.add({
|
||||||
name,
|
name,
|
||||||
text: text || '',
|
text: text || "",
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
uid,
|
uid,
|
||||||
type: type || '',
|
type: type || "",
|
||||||
replyTo: replyTo || null,
|
replyTo: replyTo || null,
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
|
||||||
console.error(`Failed to send message to party : \n\t Room: ${roomId} \n\t ${uid}`, err);
|
|
||||||
res.status(500).send({ message: "Couldn't send your message", error: messageErr });
|
|
||||||
});
|
|
||||||
await admin
|
|
||||||
.firestore()
|
|
||||||
.collection('rooms')
|
|
||||||
.doc(roomId)
|
|
||||||
.update({
|
|
||||||
updatedAt: new Date(),
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to set updated time when sending messasge to party : \n\t Room: ${roomId} \n\t User: ${uid}`,
|
`Failed to send message to party : \n\t Room: ${roomId} \n\t ${uid}`,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
|
res
|
||||||
|
.status(500)
|
||||||
|
.send({ message: "Couldn't send your message", error: messageErr });
|
||||||
});
|
});
|
||||||
res.status(200).send({ message: 'Sent a message' });
|
res.status(200).send({ message: "Sent a message" });
|
||||||
} else {
|
} else {
|
||||||
res.status(404).send({ message: 'Looks like this party is over' });
|
res.status(404).send({ message: "Looks like this party is over" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -81,20 +81,6 @@ module.exports = async (req, res) => {
|
|||||||
time: new Date(),
|
time: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (player.source === "peacocktv.") {
|
|
||||||
admin
|
|
||||||
.firestore()
|
|
||||||
.collection("rooms")
|
|
||||||
.doc(bodydata.partyName)
|
|
||||||
.collection("messages")
|
|
||||||
.add({
|
|
||||||
uid: "<system>",
|
|
||||||
name: "",
|
|
||||||
text: `Sync may not work flawlessly with PeacockTV till Monday's update. Please stick with us as we address this issue.`,
|
|
||||||
time: new Date(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
res
|
res
|
||||||
.status(201)
|
.status(201)
|
||||||
.send({ roomId: bodydata.partyName, message: "Started a party!" });
|
.send({ roomId: bodydata.partyName, message: "Started a party!" });
|
||||||
|
|||||||
Reference in New Issue
Block a user