@openinc/parse-server-opendash
Version:
Parse Server Cloud Code for open.INC Stack.
33 lines (32 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = init;
const __1 = require("..");
const types_1 = require("../types");
async function init() {
(0, __1.beforeSaveHook)(types_1.Dashboard, async (request) => {
const { object, original, user } = request;
await (0, __1.defaultHandler)(request);
// TODO
});
(0, __1.afterSaveHook)(types_1.Dashboard, async ({ object, original, user }) => {
// TODO
const acl = object.getACL();
const widgetIds = object.get("widgets");
if (acl && Array.isArray(widgetIds) && widgetIds.length > 0) {
for (const widgetId of widgetIds) {
try {
const widget = new types_1.Widget({
objectId: widgetId,
});
await widget.fetch({ useMasterKey: true });
widget.setACL(acl);
await widget.save(null, { useMasterKey: true });
}
catch (error) {
console.error("Error: Update widget permission from dashboard:", object.id, widgetId, error);
}
}
}
});
}