v1.3.0-beta/release
This commit is contained in:
@@ -4,26 +4,16 @@ module.exports = async (req, res) => {
|
||||
const bodydata = JSON.parse(req.body);
|
||||
console.log('Requested Create - UID - ', bodydata.uid);
|
||||
if (!bodydata.userName) res.status(400).send({ message: 'Missing user name' });
|
||||
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 roomId = await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.get()
|
||||
.then((docSnap) => docSnap.exists);
|
||||
if (roomNameTaken) return res.status(409).send({ message: 'That party name is already taken' });
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.set({
|
||||
name: bodydata.partyName,
|
||||
pin: bodydata.partyPin,
|
||||
.add({
|
||||
name: bodydata.roomName,
|
||||
player: bodydata.player,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.then((ref) => ref.id)
|
||||
.catch((err) => {
|
||||
res.status(500).send({ message: 'Unable to start party.' });
|
||||
console.error(err);
|
||||
@@ -31,7 +21,7 @@ module.exports = async (req, res) => {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.doc(roomId)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
@@ -40,15 +30,12 @@ module.exports = async (req, res) => {
|
||||
time: new Date(),
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to add system create party message : \n\t Room: ${bodydata.partyName}`,
|
||||
err
|
||||
);
|
||||
console.error(`Failed to add system create party message : \n\t Room: ${roomId}`, err);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.partyName)
|
||||
.doc(roomId)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
@@ -57,9 +44,9 @@ module.exports = async (req, res) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to set admin when creating party : \n\t Room: ${bodydata.partyName} \n\t User: ${bodydata.uid}`,
|
||||
`Failed to set admin when creating party : \n\t Room: ${roomId} \n\t User: ${bodydata.uid}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
|
||||
res.status(201).send({ roomId, message: 'Started a party!' });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user