v1.2.1-beta/functions refactor

This commit is contained in:
Ayushya Amitabh
2020-05-26 14:04:04 -04:00
parent 0184c01504
commit ab13a67d08
15 changed files with 561 additions and 492 deletions
+36
View File
@@ -0,0 +1,36 @@
const admin = require('firebase-admin');
const FunctionModules = require('./index');
module.exports = async () => {
const startedTime = new Date();
const roomList = await admin
.firestore()
.collection('rooms')
.listDocuments()
.then((rL) => rL)
.catch((err) => {
console.error(
`Failed to run auto clean up (get room list) @ ${new Date().toLocaleTimeString()}`,
err
);
});
roomList.forEach((roomRef) => {
roomRef
.get()
.then(async (roomSnap) => {
if (
FunctionModules.timeDiff(roomSnap.createTime.toDate(), startedTime) >= 24 ||
FunctionModules.timeDiff(roomSnap.updateTime.toDate(), startedTime) >= 12
)
await FunctionModules.cleanUpRoom(roomSnap.id);
console.info(`Deleted room ${roomSnap.id} from auto cleanup`);
return;
})
.catch((err) => {
console.error(
`Failed to run auto clean up (get room snap) @ ${new Date().toLocaleTimeString()}`,
err
);
});
});
};