UNPKG

@openinc/parse-server-opendash

Version:
32 lines (31 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkStatus = checkStatus; const catchError_1 = require("../../../../helper/catchError"); const types_1 = require("../../../../types"); /** * Checks the status field of each Maintenance_Schedule_Execution and updates it accordingly. * Ensures that if the status is not set, it defaults to "default", and if finishedAt is set, the status is "finished". * @returns */ async function checkStatus() { // Maintenance_Schedule_Execution: For every entry: check the field "status" and set it to "default" if not set/undefined or set to "finished" if field "finishedAt" is set const [error, executions] = await (0, catchError_1.catchError)(new Parse.Query(types_1.Maintenance_Schedule_Execution).findAll({ useMasterKey: true, })); if (error) { console.error("Error fetching Maintenance_Schedule_Execution:", error); return; } for (const execution of executions) { const status = execution.get("status"); const finishedAt = execution.get("finishedAt"); if (!status) { execution.set("status", "default"); } else if (finishedAt) { execution.set("status", "finished"); } await execution.save(null, { useMasterKey: true }); } }