Files
watchparty/functions/admin/updateVersionActive.js
ayushya fef3263bad v1.7.10/release:
-abandon Google Drive,
-fix video listeners,
-add backup webhook,
-complete admin dashboard
2021-03-08 16:41:56 -05:00

50 lines
1.5 KiB
JavaScript

const admin = require("firebase-admin");
const Logger = require("../Logger");
const mLogger = new Logger("admin", "updateVersionActive");
module.exports = async (req, res) => {
mLogger.start();
const { version, versionData } = JSON.parse(req.body);
if (version && versionData) {
delete versionData.version;
if (
versionData.importantAlert === null ||
versionData.importantAlert === undefined
) {
await admin
.firestore()
.collection("server")
.doc("status")
.update({
[`${version}.importantUpdate`]: admin.firestore.FieldValue.delete(),
})
.catch((err) => {
mLogger.error("FAILED TO DELETE IMPORTANT ALERT", err);
res
.status(500)
.send({ message: "FAILED TO DELETE IMPORTANT ALERT", error: err });
});
delete versionData.importantAlert;
}
await admin
.firestore()
.collection("server")
.doc("status")
.update({
[version]: versionData,
})
.catch((err) => {
mLogger.error("FAILED TO UPDATE", err);
res.status(500).send({ message: "FAILED TO UPDATE", error: err });
});
mLogger.success(
"UPDATE VERSION ACTIVE STATUS",
Object.assign(versionData, versionData)
);
res.status(200).send({ message: "Updated version active" });
} else {
mLogger.error("VALUES NOT RECEIVED");
res.status(500).send({ message: "Values not received" });
}
};