@openinc/parse-server-opendash
Version: 
Parse Server Cloud Code for open.INC Stack.
32 lines (31 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.reassignScheduleExecutions = reassignScheduleExecutions;
const types_1 = require("../../../../types");
async function reassignScheduleExecutions() {
    const executions = await new Parse.Query(types_1.Maintenance_Schedule_Execution)
        .includeAll()
        .limit(100000000)
        .find({ useMasterKey: true });
    for (const execution of executions) {
        // Get the full execution object
        const schedule = execution.get("schedule");
        if (!schedule && execution.get("origin") && execution.get("source")) {
            const matchingSchedule = await new Parse.Query(types_1.Maintenance_Schedule)
                .equalTo("template", execution.get("origin"))
                .equalTo("source", execution.get("source"))
                .first({ useMasterKey: true });
            if (matchingSchedule) {
                await execution.save({ schedule: matchingSchedule }, { useMasterKey: true });
                console.log(`Updated execution ${execution.id} with schedule ${matchingSchedule.id}`);
            }
        }
        if (schedule && (!execution.get("origin") || !execution.get("source"))) {
            await execution.save({
                origin: schedule.get("template"),
                source: schedule.get("source"),
            }, { useMasterKey: true });
            console.log(`Updated execution ${execution.id} with origin/source from schedule`);
        }
    }
}