This commit is contained in:
Ayushya Amitabh
2020-04-17 14:37:39 -04:00
parent 1acbca3bf0
commit 15679cd001
12 changed files with 439 additions and 190 deletions
+27
View File
@@ -48,6 +48,7 @@ const createRoom = async (req, res) => {
.collection('rooms')
.add({
name: bodydata.roomName,
player: bodydata.player,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@@ -206,6 +207,31 @@ const deleteRoom = async (req, res) => {
res.status(200).send();
};
const updatePlayer = async (req, res) => {
const { player, roomId, uid } = JSON.parse(req.body);
const userExists = await admin
.firestore()
.collection('rooms')
.doc(roomId)
.collection('users')
.doc(uid)
.get()
.then((userSnap) => userSnap.exists);
if (userExists) {
await admin
.firestore()
.collection('rooms')
.doc(roomId)
.update({
player,
})
.catch((err) => res.status(500).send(err));
res.status(200).send();
} else {
res.status(401).send('Not in room to sync');
}
};
const app = express();
app.use(cors({ origin: true }));
app.use(authenticator);
@@ -220,5 +246,6 @@ app.post('/join', joinRoom);
app.post('/message', sendMessage);
app.delete('/leave/:rid/users/:uid', leaveRoom);
app.delete('/delete/:rid', deleteRoom);
app.post('/updatePlayer', updatePlayer);
exports.widgets = functions.https.onRequest(app);