v.1.4.3/api update

This commit is contained in:
2020-07-16 16:13:22 -04:00
parent a80a8673ff
commit 19a7adf62c
29 changed files with 176 additions and 695 deletions
+29 -29
View File
@@ -2,18 +2,18 @@ const admin = require('firebase-admin');
module.exports = async (req, res) => {
const { player, roomId, uid, showChanged, userName } = JSON.parse(req.body);
const statusString =
player.status === 'PLAYING'
? 'started playing from'
: player.status === 'PAUSED'
? 'paused at'
: player.status === 'NOT_PLAYING'
? 'stopped at'
: 'is at';
const timeString =
player.time > 3600
? new Date(player.time * 1000).toISOString().substr(11, 8)
: new Date(player.time * 1000).toISOString().substr(14, 5);
// const statusString =
// player.status === 'PLAYING'
// ? 'started playing from'
// : player.status === 'PAUSED'
// ? 'paused at'
// : player.status === 'NOT_PLAYING'
// ? 'stopped at'
// : 'is at';
// const timeString =
// player.time > 3600
// ? new Date(player.time * 1000).toISOString().substr(11, 8)
// : new Date(player.time * 1000).toISOString().substr(14, 5);
const [roomExists, roomData] = await admin
.firestore()
.collection('rooms')
@@ -55,23 +55,23 @@ module.exports = async (req, res) => {
console.error(`Failed to update player : \n\t Room: ${roomId} \n\t ${uid}`, err);
res.status(500).send({ message: "Uh oh party could't be synced", err });
});
await admin
.firestore()
.collection('rooms')
.doc(roomId)
.collection('messages')
.add({
uid: '<system>',
name: '',
text: `${userName} ${statusString} ${timeString}`,
time: new Date(),
})
.catch((err) => {
console.error(
`Failed to add system update player message : \n\t Room: ${roomId} \n\t ${uid}`,
err
);
});
// await admin
// .firestore()
// .collection('rooms')
// .doc(roomId)
// .collection('messages')
// .add({
// uid: '<system>',
// name: '',
// text: `${userName} ${statusString} ${timeString}`,
// time: new Date(),
// })
// .catch((err) => {
// console.error(
// `Failed to add system update player message : \n\t Room: ${roomId} \n\t ${uid}`,
// err
// );
// });
return res.status(200).send({ message: 'Synced party player' });
} else {
return res.status(208).send({ message: 'Player already up to date' });