v0.9
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user