v1.3.0-beta/UI redone
This commit is contained in:
@@ -4,20 +4,22 @@ 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.roomName) res.status(400).send({ message: 'Missing party 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
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.roomName)
|
||||
.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.roomName)
|
||||
.doc(bodydata.partyName)
|
||||
.set({
|
||||
name: bodydata.roomName,
|
||||
name: bodydata.partyName,
|
||||
pin: bodydata.partyPin,
|
||||
player: bodydata.player,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
@@ -29,7 +31,7 @@ module.exports = async (req, res) => {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.roomName)
|
||||
.doc(bodydata.partyName)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
@@ -39,14 +41,14 @@ module.exports = async (req, res) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to add system create party message : \n\t Room: ${bodydata.roomName}`,
|
||||
`Failed to add system create party message : \n\t Room: ${bodydata.partyName}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(bodydata.roomName)
|
||||
.doc(bodydata.partyName)
|
||||
.collection('users')
|
||||
.doc(bodydata.uid)
|
||||
.set({
|
||||
@@ -55,9 +57,9 @@ module.exports = async (req, res) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(
|
||||
`Failed to set admin when creating party : \n\t Room: ${bodydata.roomName} \n\t User: ${bodydata.uid}`,
|
||||
`Failed to set admin when creating party : \n\t Room: ${bodydata.partyName} \n\t User: ${bodydata.uid}`,
|
||||
err
|
||||
);
|
||||
});
|
||||
res.status(201).send({ roomId: bodydata.roomName, message: 'Started a party!' });
|
||||
res.status(201).send({ roomId: bodydata.partyName, message: 'Started a party!' });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user