@openinc/parse-server-opendash
Version:
Parse Server Cloud Code for open.INC Stack.
36 lines (35 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = init;
const __1 = require("..");
const config_1 = require("../features/config");
const types_1 = require("../types");
async function init() {
(0, __1.beforeSaveHook)(types_1.Alarm, async (request) => {
const { object, original, user } = request;
await (0, __1.defaultHandler)(request);
// TODO
});
(0, __1.afterSaveHook)(types_1.Alarm, async ({ object, original, user }) => {
if (config_1.ConfigInstance.getInstance().getBoolean("OPENWARE")) {
const username = user?.get("username");
const baseurl = config_1.ConfigInstance.getInstance().get("OPENWARE_BASEURL");
const headers = {
"content-type": "application/json",
"od-session": user?.getSessionToken() || "",
};
const body = JSON.stringify({
...object.toJSON(),
owner: object.get("user"),
createdAt: undefined,
updatedAt: undefined,
ACL: undefined,
});
await fetch(`${baseurl}/api/alarmsV2/${username}`, {
method: "POST",
headers,
body,
});
}
});
}