@openinc/parse-server-opendash 4.31.5 → 4.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/featuremap.json +4 -0
- package/dist/features/bde/shifts/shiftValidation.d.ts +13 -0
- package/dist/features/bde/shifts/shiftValidation.js +96 -0
- package/dist/features/openservice/alarms/index.d.ts +0 -2
- package/dist/features/openservice/alarms/index.js +1 -3
- package/dist/features/openservice/init.js +2 -0
- package/dist/features/openservice/kpis/initKpiFeature.d.ts +13 -0
- package/dist/features/openservice/kpis/initKpiFeature.js +41 -0
- package/dist/features/openservice/kpis/kpiJob.d.ts +46 -0
- package/dist/features/openservice/kpis/kpiJob.js +273 -0
- package/dist/features/openservice/kpis/kpiMaths.d.ts +51 -0
- package/dist/features/openservice/kpis/kpiMaths.js +62 -0
- package/dist/features/openservice/tickets/ticketFailure.d.ts +37 -0
- package/dist/features/openservice/tickets/ticketFailure.js +99 -0
- package/dist/features/openservice/tickets/ticketRules.d.ts +8 -0
- package/dist/features/openservice/tickets/ticketRules.js +10 -0
- package/dist/features/permissions/types/Permissions.d.ts +3 -1
- package/dist/features/permissions/types/Permissions.js +5 -0
- package/dist/functions/openinc-openservice-kpi-recompute.d.ts +16 -0
- package/dist/functions/openinc-openservice-kpi-recompute.js +44 -0
- package/dist/hooks/BDE_ShiftException.d.ts +1 -0
- package/dist/hooks/BDE_ShiftException.js +22 -0
- package/dist/hooks/BDE_ShiftModel.d.ts +1 -0
- package/dist/hooks/BDE_ShiftModel.js +24 -0
- package/dist/hooks/BDE_WorkTime.js +4 -1
- package/dist/hooks/Service_EquipmentAnnotation.d.ts +1 -0
- package/dist/hooks/Service_EquipmentAnnotation.js +15 -0
- package/dist/hooks/Service_KpiDefinition.d.ts +1 -0
- package/dist/hooks/Service_KpiDefinition.js +65 -0
- package/dist/hooks/Service_Ticket.js +8 -0
- package/dist/types/BDE_ShiftException.d.ts +34 -0
- package/dist/types/BDE_ShiftException.js +57 -0
- package/dist/types/BDE_ShiftModel.d.ts +34 -0
- package/dist/types/BDE_ShiftModel.js +57 -0
- package/dist/types/Service_EquipmentAnnotation.d.ts +35 -0
- package/dist/types/Service_EquipmentAnnotation.js +57 -0
- package/dist/types/Service_KpiDefinition.d.ts +34 -0
- package/dist/types/Service_KpiDefinition.js +57 -0
- package/dist/types/Service_Ticket.d.ts +9 -0
- package/dist/types/Service_Ticket.js +18 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +11 -3
- package/package.json +15 -14
- package/pnpm-workspace.yaml +3 -0
- package/schema/BDE_ShiftException.json +57 -0
- package/schema/BDE_ShiftModel.json +58 -0
- package/schema/Service_EquipmentAnnotation.json +57 -0
- package/schema/Service_KpiDefinition.json +56 -0
- package/schema/Service_Ticket.json +9 -0
- package/dist/features/openservice/alarms/schedule/listAlarmTriggers.d.ts +0 -41
- package/dist/features/openservice/alarms/schedule/listAlarmTriggers.js +0 -159
- package/dist/functions/openinc-openservice-alarm-triggers.d.ts +0 -13
- package/dist/functions/openinc-openservice-alarm-triggers.js +0 -29
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BDE_WorkTime } from "../../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Rejects a save whose failure window ends before it starts.
|
|
4
|
+
*
|
|
5
|
+
* `failureStart` and `failureEnd` are optional: left empty, a failure runs from
|
|
6
|
+
* the ticket's creation to its `closedAt` (`@opendash/plugin-openservice-analytics`
|
|
7
|
+
* reads them that way, and so will the KPI series computed here). They exist
|
|
8
|
+
* for the cases where those two stamps are wrong — the ticket was written an
|
|
9
|
+
* hour after the press stopped, or closed a day after it ran again — and for
|
|
10
|
+
* the BDE, which knows the disruption to the minute.
|
|
11
|
+
*
|
|
12
|
+
* **Judged against what is in effect, not only against what was sent.** An end
|
|
13
|
+
* with no start of its own ends a window that opened when the ticket was
|
|
14
|
+
* created; an end before that is the same contradiction and would count as a
|
|
15
|
+
* negative downtime just the same. Nothing downstream could tell which of the
|
|
16
|
+
* two dates is the typo, so the save is refused instead of guessed.
|
|
17
|
+
*
|
|
18
|
+
* Not stamped by the server, unlike `closedAt`: the fallback does what a stamp
|
|
19
|
+
* would, and an empty field keeps saying "nobody corrected this".
|
|
20
|
+
*/
|
|
21
|
+
export declare function assertFailureWindow(object: Parse.Object): void;
|
|
22
|
+
/**
|
|
23
|
+
* Carries a corrected BDE disruption over to the tickets raised from it.
|
|
24
|
+
*
|
|
25
|
+
* A worker reports a disruption while the machine is still down; its end is
|
|
26
|
+
* entered later, when it runs again — and the ticket was written in between,
|
|
27
|
+
* with the end unknown. Without this the ticket's failure would last until the
|
|
28
|
+
* ticket is closed, which can be days after the machine was running.
|
|
29
|
+
*
|
|
30
|
+
* **A ticket's own correction wins.** A failure date is only moved where it is
|
|
31
|
+
* still what the disruption said before (or empty): somebody who corrected it
|
|
32
|
+
* on the ticket knew better than the shop floor did.
|
|
33
|
+
*
|
|
34
|
+
* Only edits: a new disruption has no ticket yet — the frontend creates it
|
|
35
|
+
* right after, with the window it knows.
|
|
36
|
+
*/
|
|
37
|
+
export declare function syncFailureFromDisruption(workTime: BDE_WorkTime, original: BDE_WorkTime | undefined): Promise<void>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertFailureWindow = assertFailureWindow;
|
|
7
|
+
exports.syncFailureFromDisruption = syncFailureFromDisruption;
|
|
8
|
+
// The failure window of a ticket: when the machine stopped and when it ran
|
|
9
|
+
// again, as the maintenance KPIs read it.
|
|
10
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
11
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
12
|
+
const index_js_1 = require("../../../types/index.js");
|
|
13
|
+
/**
|
|
14
|
+
* Rejects a save whose failure window ends before it starts.
|
|
15
|
+
*
|
|
16
|
+
* `failureStart` and `failureEnd` are optional: left empty, a failure runs from
|
|
17
|
+
* the ticket's creation to its `closedAt` (`@opendash/plugin-openservice-analytics`
|
|
18
|
+
* reads them that way, and so will the KPI series computed here). They exist
|
|
19
|
+
* for the cases where those two stamps are wrong — the ticket was written an
|
|
20
|
+
* hour after the press stopped, or closed a day after it ran again — and for
|
|
21
|
+
* the BDE, which knows the disruption to the minute.
|
|
22
|
+
*
|
|
23
|
+
* **Judged against what is in effect, not only against what was sent.** An end
|
|
24
|
+
* with no start of its own ends a window that opened when the ticket was
|
|
25
|
+
* created; an end before that is the same contradiction and would count as a
|
|
26
|
+
* negative downtime just the same. Nothing downstream could tell which of the
|
|
27
|
+
* two dates is the typo, so the save is refused instead of guessed.
|
|
28
|
+
*
|
|
29
|
+
* Not stamped by the server, unlike `closedAt`: the fallback does what a stamp
|
|
30
|
+
* would, and an empty field keeps saying "nobody corrected this".
|
|
31
|
+
*/
|
|
32
|
+
function assertFailureWindow(object) {
|
|
33
|
+
const end = object.get("failureEnd");
|
|
34
|
+
if (!end)
|
|
35
|
+
return;
|
|
36
|
+
const start = object.get("failureStart") ??
|
|
37
|
+
object.createdAt ??
|
|
38
|
+
// A new ticket has no `createdAt` before the save; it gets about now.
|
|
39
|
+
new Date();
|
|
40
|
+
if (end.getTime() >= start.getTime())
|
|
41
|
+
return;
|
|
42
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `The failure of a ticket cannot end (${end.toISOString()}) before it ` +
|
|
43
|
+
`started (${start.toISOString()}).`);
|
|
44
|
+
}
|
|
45
|
+
const time = (date) => date?.getTime();
|
|
46
|
+
/**
|
|
47
|
+
* Carries a corrected BDE disruption over to the tickets raised from it.
|
|
48
|
+
*
|
|
49
|
+
* A worker reports a disruption while the machine is still down; its end is
|
|
50
|
+
* entered later, when it runs again — and the ticket was written in between,
|
|
51
|
+
* with the end unknown. Without this the ticket's failure would last until the
|
|
52
|
+
* ticket is closed, which can be days after the machine was running.
|
|
53
|
+
*
|
|
54
|
+
* **A ticket's own correction wins.** A failure date is only moved where it is
|
|
55
|
+
* still what the disruption said before (or empty): somebody who corrected it
|
|
56
|
+
* on the ticket knew better than the shop floor did.
|
|
57
|
+
*
|
|
58
|
+
* Only edits: a new disruption has no ticket yet — the frontend creates it
|
|
59
|
+
* right after, with the window it knows.
|
|
60
|
+
*/
|
|
61
|
+
async function syncFailureFromDisruption(workTime, original) {
|
|
62
|
+
if (!original || !workTime.id)
|
|
63
|
+
return;
|
|
64
|
+
const startChanged = time(workTime.start) !== time(original.start);
|
|
65
|
+
const endChanged = time(workTime.end) !== time(original.end);
|
|
66
|
+
if (!startChanged && !endChanged)
|
|
67
|
+
return;
|
|
68
|
+
const tickets = await new node_1.default.Query(index_js_1.Service_Ticket)
|
|
69
|
+
.equalTo("origin", (0, openservice_shared_1.bdeDisruptionOrigin)(workTime.id))
|
|
70
|
+
.find({ useMasterKey: true });
|
|
71
|
+
for (const ticket of tickets) {
|
|
72
|
+
const follows = (field, previous) => {
|
|
73
|
+
const current = ticket.get(field);
|
|
74
|
+
return !current || time(current) === time(previous);
|
|
75
|
+
};
|
|
76
|
+
if (startChanged && follows("failureStart", original.start)) {
|
|
77
|
+
if (workTime.start)
|
|
78
|
+
ticket.set("failureStart", workTime.start);
|
|
79
|
+
else
|
|
80
|
+
ticket.unset("failureStart");
|
|
81
|
+
}
|
|
82
|
+
if (endChanged && follows("failureEnd", original.end)) {
|
|
83
|
+
if (workTime.end)
|
|
84
|
+
ticket.set("failureEnd", workTime.end);
|
|
85
|
+
else
|
|
86
|
+
ticket.unset("failureEnd");
|
|
87
|
+
}
|
|
88
|
+
if (!ticket.dirtyKeys().length)
|
|
89
|
+
continue;
|
|
90
|
+
try {
|
|
91
|
+
await ticket.save(null, { useMasterKey: true });
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// A window the ticket's own dates contradict is refused by
|
|
95
|
+
// assertFailureWindow; the disruption is saved either way.
|
|
96
|
+
console.error(`[openservice] Could not carry disruption ${workTime.id} over to ticket ${ticket.id}:`, error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RuleSetValue } from "@opendash/ruleset-core";
|
|
1
2
|
/**
|
|
2
3
|
* When a rule acts. Mirrors `RuleTrigger` of the frontend.
|
|
3
4
|
*
|
|
@@ -8,6 +9,13 @@
|
|
|
8
9
|
* a trigger predates the choice and keeps this behaviour.
|
|
9
10
|
*/
|
|
10
11
|
export type RuleTrigger = "create" | "becomes" | "always";
|
|
12
|
+
/**
|
|
13
|
+
* Whether a stored ticket meets a condition, read exactly as the form config
|
|
14
|
+
* rules read it — so a KPI definition ("what counts as a failure") written in
|
|
15
|
+
* the same editor means the same thing. No condition, or one without rules,
|
|
16
|
+
* always holds.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ticketMeetsCondition(ticket: Parse.Object, condition: RuleSetValue | undefined): boolean;
|
|
11
19
|
/**
|
|
12
20
|
* What a form config does to a ticket on save, in the order the frontend used
|
|
13
21
|
* to apply it: the computed priority, the field value rules, the action rules
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ticketMeetsCondition = ticketMeetsCondition;
|
|
3
4
|
exports.applyFormConfigRules = applyFormConfigRules;
|
|
4
5
|
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
5
6
|
const ruleset_core_1 = require("@opendash/ruleset-core");
|
|
@@ -64,6 +65,15 @@ function readerOf(object) {
|
|
|
64
65
|
return value instanceof Date ? (0, ticketRuleTime_js_1.inRuleZone)(value) : value;
|
|
65
66
|
};
|
|
66
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Whether a stored ticket meets a condition, read exactly as the form config
|
|
70
|
+
* rules read it — so a KPI definition ("what counts as a failure") written in
|
|
71
|
+
* the same editor means the same thing. No condition, or one without rules,
|
|
72
|
+
* always holds.
|
|
73
|
+
*/
|
|
74
|
+
function ticketMeetsCondition(ticket, condition) {
|
|
75
|
+
return holds(condition, readerOf(ticket));
|
|
76
|
+
}
|
|
67
77
|
function isEmpty(value) {
|
|
68
78
|
if (value == null || value === "")
|
|
69
79
|
return true;
|
|
@@ -33,7 +33,9 @@ export declare namespace Permissions {
|
|
|
33
33
|
schedule_delete = "openservice-schedule:can-delete-schedule",
|
|
34
34
|
execution_perform = "openservice-schedule:can-perform-execution",
|
|
35
35
|
template_manage = "openservice-schedule:can-manage-template",
|
|
36
|
-
analytics_view = "openservice-schedule:can-view-analytics"
|
|
36
|
+
analytics_view = "openservice-schedule:can-view-analytics",
|
|
37
|
+
production_view = "openservice-analytics:can-view-production",
|
|
38
|
+
kpi_view = "openservice-analytics:can-view-kpis"
|
|
37
39
|
}
|
|
38
40
|
enum CORE {
|
|
39
41
|
adminoverview = "opendash:can-access-admin-overview",
|
|
@@ -77,6 +77,11 @@ var Permissions;
|
|
|
77
77
|
SERVICE["execution_perform"] = "openservice-schedule:can-perform-execution";
|
|
78
78
|
SERVICE["template_manage"] = "openservice-schedule:can-manage-template";
|
|
79
79
|
SERVICE["analytics_view"] = "openservice-schedule:can-view-analytics";
|
|
80
|
+
// Analytics plugin, one key per audience: the production dashboard is
|
|
81
|
+
// for the floor, the KPIs for whoever steers maintenance. Its other pages
|
|
82
|
+
// keep the key of the plugin they come from.
|
|
83
|
+
SERVICE["production_view"] = "openservice-analytics:can-view-production";
|
|
84
|
+
SERVICE["kpi_view"] = "openservice-analytics:can-view-kpis";
|
|
80
85
|
})(SERVICE = Permissions.SERVICE || (Permissions.SERVICE = {}));
|
|
81
86
|
let CORE;
|
|
82
87
|
(function (CORE) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recomputes the maintenance KPI series of a tenant now — for the history
|
|
3
|
+
* after the analytics plugin was switched on (`days: 730`), or after a change
|
|
4
|
+
* the nightly run would only pick up tomorrow.
|
|
5
|
+
*
|
|
6
|
+
* Params: `{ days?: number, tenant?: string, dryRun?: boolean }`. Without
|
|
7
|
+
* `tenant` the caller's own; with the master key and without `tenant`, every
|
|
8
|
+
* tenant. `dryRun` computes without writing and answers with the sums of each
|
|
9
|
+
* series — to check a definition or a shift model before openware sees it.
|
|
10
|
+
*
|
|
11
|
+
* Gated on the service admin capability (`openservice-core:can-access-admin`)
|
|
12
|
+
* of that tenant — the same one that edits the KPI definitions.
|
|
13
|
+
*
|
|
14
|
+
* @param name The function name, derived from the file name.
|
|
15
|
+
*/
|
|
16
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const kpiJob_js_1 = require("../features/openservice/kpis/kpiJob.js");
|
|
9
|
+
const index_js_1 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
11
|
+
const index_js_2 = require("../types/index.js");
|
|
12
|
+
/** At most ten years in one call; openware takes the values day by day. */
|
|
13
|
+
const MAX_DAYS = 3650;
|
|
14
|
+
/**
|
|
15
|
+
* Recomputes the maintenance KPI series of a tenant now — for the history
|
|
16
|
+
* after the analytics plugin was switched on (`days: 730`), or after a change
|
|
17
|
+
* the nightly run would only pick up tomorrow.
|
|
18
|
+
*
|
|
19
|
+
* Params: `{ days?: number, tenant?: string, dryRun?: boolean }`. Without
|
|
20
|
+
* `tenant` the caller's own; with the master key and without `tenant`, every
|
|
21
|
+
* tenant. `dryRun` computes without writing and answers with the sums of each
|
|
22
|
+
* series — to check a definition or a shift model before openware sees it.
|
|
23
|
+
*
|
|
24
|
+
* Gated on the service admin capability (`openservice-core:can-access-admin`)
|
|
25
|
+
* of that tenant — the same one that edits the KPI definitions.
|
|
26
|
+
*
|
|
27
|
+
* @param name The function name, derived from the file name.
|
|
28
|
+
*/
|
|
29
|
+
async function init(name) {
|
|
30
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
31
|
+
const days = Math.min(MAX_DAYS, Math.max(1, Number(request.params.days) || 35));
|
|
32
|
+
const tenantId = request.params.tenant ??
|
|
33
|
+
request.user?.get("tenant")?.id;
|
|
34
|
+
await (0, index_js_1.requirePermission)({
|
|
35
|
+
sessionToken: request.user?.getSessionToken() ?? undefined,
|
|
36
|
+
master: request.master,
|
|
37
|
+
}, Permissions_js_1.Permissions.SERVICE.admin_access, "recompute the maintenance KPIs", tenantId ? index_js_2.Tenant.createWithoutData(tenantId) : null);
|
|
38
|
+
return (0, kpiJob_js_1.recomputeKpis)({
|
|
39
|
+
days,
|
|
40
|
+
tenantId: request.master ? request.params.tenant : tenantId,
|
|
41
|
+
dryRun: request.params.dryRun === true,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
+
const shiftValidation_js_1 = require("../features/bde/shifts/shiftValidation.js");
|
|
6
|
+
const initKpiFeature_js_1 = require("../features/openservice/kpis/initKpiFeature.js");
|
|
7
|
+
const index_js_2 = require("../types/index.js");
|
|
8
|
+
async function init() {
|
|
9
|
+
// Departures from the shift models: holidays, company holidays, planned
|
|
10
|
+
// shutdowns, special shifts. Same access as the models themselves.
|
|
11
|
+
(0, index_js_1.beforeSaveHook)(index_js_2.BDE_ShiftException, async (request) => {
|
|
12
|
+
const { object } = request;
|
|
13
|
+
await (0, index_js_1.defaultHandler)(request);
|
|
14
|
+
await (0, index_js_1.defaultAclHandler)(request);
|
|
15
|
+
(0, shiftValidation_js_1.assertShiftException)(object);
|
|
16
|
+
(0, shiftValidation_js_1.assertSourcePointers)(object.get("sources"));
|
|
17
|
+
});
|
|
18
|
+
// Operating time is what MTBF and availability are measured against.
|
|
19
|
+
(0, index_js_1.afterSaveHook)(index_js_2.BDE_ShiftException, async ({ object }) => {
|
|
20
|
+
(0, initKpiFeature_js_1.scheduleKpiRecompute)(object.get("tenant")?.id);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
+
const shiftValidation_js_1 = require("../features/bde/shifts/shiftValidation.js");
|
|
6
|
+
const initKpiFeature_js_1 = require("../features/openservice/kpis/initKpiFeature.js");
|
|
7
|
+
const index_js_2 = require("../types/index.js");
|
|
8
|
+
async function init() {
|
|
9
|
+
// The week a machine is planned to run — what the maintenance KPIs measure
|
|
10
|
+
// operating time against. Read by every user of the tenant, written by the
|
|
11
|
+
// creator and tenant admins (the BDE admin page).
|
|
12
|
+
(0, index_js_1.beforeSaveHook)(index_js_2.BDE_ShiftModel, async (request) => {
|
|
13
|
+
const { object } = request;
|
|
14
|
+
await (0, index_js_1.defaultHandler)(request);
|
|
15
|
+
await (0, index_js_1.defaultAclHandler)(request);
|
|
16
|
+
(0, shiftValidation_js_1.assertShifts)(object.get("shifts") ?? []);
|
|
17
|
+
(0, shiftValidation_js_1.assertSourcePointers)(object.get("sources"));
|
|
18
|
+
(0, shiftValidation_js_1.assertTimezone)(object.get("timezone"));
|
|
19
|
+
});
|
|
20
|
+
// Operating time is what MTBF and availability are measured against.
|
|
21
|
+
(0, index_js_1.afterSaveHook)(index_js_2.BDE_ShiftModel, async ({ object }) => {
|
|
22
|
+
(0, initKpiFeature_js_1.scheduleKpiRecompute)(object.get("tenant")?.id);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
4
|
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
+
const ticketFailure_js_1 = require("../features/openservice/tickets/ticketFailure.js");
|
|
5
6
|
const index_js_2 = require("../types/index.js");
|
|
6
7
|
async function init() {
|
|
7
8
|
(0, index_js_1.beforeSaveHook)(index_js_2.BDE_WorkTime, async (request) => {
|
|
@@ -12,8 +13,10 @@ async function init() {
|
|
|
12
13
|
});
|
|
13
14
|
(0, index_js_1.afterSaveHook)(index_js_2.BDE_WorkTime, async (request) => {
|
|
14
15
|
const { object, original, user } = request;
|
|
15
|
-
if (object.get("status") === "disrupted")
|
|
16
|
+
if (object.get("status") === "disrupted") {
|
|
17
|
+
await (0, ticketFailure_js_1.syncFailureFromDisruption)(object, original);
|
|
16
18
|
return;
|
|
19
|
+
}
|
|
17
20
|
await addToWorkOrder(object, original);
|
|
18
21
|
});
|
|
19
22
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
+
const index_js_2 = require("../types/index.js");
|
|
6
|
+
async function init() {
|
|
7
|
+
// A note on a machine at a point in time — a conversion, a new control
|
|
8
|
+
// program — so the reporting can compare its KPIs before and after. Anyone
|
|
9
|
+
// of the tenant may write one, like a ticket; required fields come from the
|
|
10
|
+
// schema.
|
|
11
|
+
(0, index_js_1.beforeSaveHook)(index_js_2.Service_EquipmentAnnotation, async (request) => {
|
|
12
|
+
await (0, index_js_1.defaultHandler)(request);
|
|
13
|
+
await (0, index_js_1.defaultAclHandler)(request);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../features/schema/index.js");
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
11
|
+
const initKpiFeature_js_1 = require("../features/openservice/kpis/initKpiFeature.js");
|
|
12
|
+
const index_js_3 = require("../types/index.js");
|
|
13
|
+
/**
|
|
14
|
+
* Refuses a `condition` the KPI job could not evaluate: it has to be a rule
|
|
15
|
+
* group of `@opendash/ruleset-core` as JSON, or empty ("every ticket on a
|
|
16
|
+
* machine").
|
|
17
|
+
*/
|
|
18
|
+
function assertCondition(raw) {
|
|
19
|
+
if (raw === undefined || raw === null || raw === "")
|
|
20
|
+
return;
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = JSON.parse(String(raw));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "The condition of a KPI definition is not valid JSON.");
|
|
27
|
+
}
|
|
28
|
+
const group = parsed;
|
|
29
|
+
if (group?.kind !== "group" || !Array.isArray(group.rules)) {
|
|
30
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "The condition of a KPI definition has to be a rule group.");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function init() {
|
|
34
|
+
// What counts as a failure for the maintenance KPIs, per tenant: a named
|
|
35
|
+
// condition over the ticket fields. Read tenant-wide (the KPI widgets name
|
|
36
|
+
// their series by it), written by whoever may open the service admin — the
|
|
37
|
+
// same capability as the ticket form configs, whose fields the conditions
|
|
38
|
+
// test.
|
|
39
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Service_KpiDefinition, async (request) => {
|
|
40
|
+
const { object } = request;
|
|
41
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.admin_access, "change a KPI definition", request.original?.get("tenant") ?? object.get("tenant"));
|
|
42
|
+
await (0, index_js_1.defaultHandler)(request);
|
|
43
|
+
await (0, index_js_1.defaultAclHandler)(request);
|
|
44
|
+
assertCondition(object.get("condition"));
|
|
45
|
+
});
|
|
46
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Service_KpiDefinition, async (request) => {
|
|
47
|
+
const { object } = request;
|
|
48
|
+
// A changed condition changes every series of the definition.
|
|
49
|
+
(0, initKpiFeature_js_1.scheduleKpiRecompute)(object.get("tenant")?.id);
|
|
50
|
+
// One default per tenant: the definition a KPI page shows first. Marking
|
|
51
|
+
// another one takes the mark away from the old one.
|
|
52
|
+
if (!object.get("isDefault") || !object.id)
|
|
53
|
+
return;
|
|
54
|
+
const others = await new node_1.default.Query(index_js_3.Service_KpiDefinition)
|
|
55
|
+
.equalTo("tenant", object.get("tenant"))
|
|
56
|
+
.equalTo("isDefault", true)
|
|
57
|
+
.notEqualTo("objectId", object.id)
|
|
58
|
+
.find({ useMasterKey: true });
|
|
59
|
+
for (const other of others)
|
|
60
|
+
other.set("isDefault", false);
|
|
61
|
+
if (others.length > 0) {
|
|
62
|
+
await node_1.default.Object.saveAll(others, { useMasterKey: true });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -12,6 +12,8 @@ const ticketAccess_js_1 = require("../features/openservice/tickets/ticketAccess.
|
|
|
12
12
|
const ticketNotifications_js_1 = require("../features/openservice/tickets/ticketNotifications.js");
|
|
13
13
|
const ticketArchive_js_1 = require("../features/openservice/tickets/ticketArchive.js");
|
|
14
14
|
const ticketRules_js_1 = require("../features/openservice/tickets/ticketRules.js");
|
|
15
|
+
const ticketFailure_js_1 = require("../features/openservice/tickets/ticketFailure.js");
|
|
16
|
+
const initKpiFeature_js_1 = require("../features/openservice/kpis/initKpiFeature.js");
|
|
15
17
|
async function init() {
|
|
16
18
|
// Soft delete: a ticket is referenced by chat messages, meta entries,
|
|
17
19
|
// notifications and child tickets, so the frontend archives instead of
|
|
@@ -93,6 +95,7 @@ async function init() {
|
|
|
93
95
|
(0, ticketReferences_js_1.assertSameTenantReferences)(object, referenced);
|
|
94
96
|
(0, ticketReferences_js_1.applySortKeys)(object, referenced, restored);
|
|
95
97
|
(0, ticketReferences_js_1.applyClosedAt)(object, referenced);
|
|
98
|
+
(0, ticketFailure_js_1.assertFailureWindow)(object);
|
|
96
99
|
(0, ticketArchive_js_1.applyArchiveReason)(object, original, !!request.master);
|
|
97
100
|
(0, ticketArchive_js_1.applySimilarCaseUse)(object, original);
|
|
98
101
|
// Assign a sequential ticket number on creation. Done here (backend) rather
|
|
@@ -148,5 +151,10 @@ async function init() {
|
|
|
148
151
|
// and assigning a role means one notification — mail and push included —
|
|
149
152
|
// per member. With 200 members the person saving waited for 200 of them.
|
|
150
153
|
void (0, ticketNotifications_js_1.notifyAboutSave)(object, original, user);
|
|
154
|
+
// A ticket on a machine changes that machine's maintenance KPIs (so does
|
|
155
|
+
// one that just left it).
|
|
156
|
+
if (object.get("equipment") || original?.get("equipment")) {
|
|
157
|
+
(0, initKpiFeature_js_1.scheduleKpiRecompute)(object.get("tenant")?.id);
|
|
158
|
+
}
|
|
151
159
|
});
|
|
152
160
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Parse from "parse/node";
|
|
2
|
+
import type { Tenant } from "./Tenant";
|
|
3
|
+
import type { _User } from "./_User";
|
|
4
|
+
export interface BDE_ShiftExceptionAttributes {
|
|
5
|
+
id: string;
|
|
6
|
+
objectId: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
end: Date;
|
|
10
|
+
kind: string;
|
|
11
|
+
label?: string | undefined;
|
|
12
|
+
sources: any[];
|
|
13
|
+
start: Date;
|
|
14
|
+
tenant?: Tenant | undefined;
|
|
15
|
+
user?: _User | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare class BDE_ShiftException extends Parse.Object<BDE_ShiftExceptionAttributes> {
|
|
18
|
+
static className: string;
|
|
19
|
+
constructor(data?: Partial<BDE_ShiftExceptionAttributes>);
|
|
20
|
+
get end(): Date;
|
|
21
|
+
set end(value: Date);
|
|
22
|
+
get kind(): string;
|
|
23
|
+
set kind(value: string);
|
|
24
|
+
get label(): string | undefined;
|
|
25
|
+
set label(value: string | undefined);
|
|
26
|
+
get sources(): any[];
|
|
27
|
+
set sources(value: any[]);
|
|
28
|
+
get start(): Date;
|
|
29
|
+
set start(value: Date);
|
|
30
|
+
get tenant(): Tenant | undefined;
|
|
31
|
+
set tenant(value: Tenant | undefined);
|
|
32
|
+
get user(): _User | undefined;
|
|
33
|
+
set user(value: _User | undefined);
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BDE_ShiftException = void 0;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
class BDE_ShiftException extends node_1.default.Object {
|
|
9
|
+
static className = "OD3_BDE_ShiftException";
|
|
10
|
+
constructor(data) {
|
|
11
|
+
super("OD3_BDE_ShiftException", data);
|
|
12
|
+
}
|
|
13
|
+
get end() {
|
|
14
|
+
return super.get("end");
|
|
15
|
+
}
|
|
16
|
+
set end(value) {
|
|
17
|
+
super.set("end", value);
|
|
18
|
+
}
|
|
19
|
+
get kind() {
|
|
20
|
+
return super.get("kind");
|
|
21
|
+
}
|
|
22
|
+
set kind(value) {
|
|
23
|
+
super.set("kind", value);
|
|
24
|
+
}
|
|
25
|
+
get label() {
|
|
26
|
+
return super.get("label");
|
|
27
|
+
}
|
|
28
|
+
set label(value) {
|
|
29
|
+
super.set("label", value);
|
|
30
|
+
}
|
|
31
|
+
get sources() {
|
|
32
|
+
return super.get("sources");
|
|
33
|
+
}
|
|
34
|
+
set sources(value) {
|
|
35
|
+
super.set("sources", value);
|
|
36
|
+
}
|
|
37
|
+
get start() {
|
|
38
|
+
return super.get("start");
|
|
39
|
+
}
|
|
40
|
+
set start(value) {
|
|
41
|
+
super.set("start", value);
|
|
42
|
+
}
|
|
43
|
+
get tenant() {
|
|
44
|
+
return super.get("tenant");
|
|
45
|
+
}
|
|
46
|
+
set tenant(value) {
|
|
47
|
+
super.set("tenant", value);
|
|
48
|
+
}
|
|
49
|
+
get user() {
|
|
50
|
+
return super.get("user");
|
|
51
|
+
}
|
|
52
|
+
set user(value) {
|
|
53
|
+
super.set("user", value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.BDE_ShiftException = BDE_ShiftException;
|
|
57
|
+
node_1.default.Object.registerSubclass("OD3_BDE_ShiftException", BDE_ShiftException);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Parse from "parse/node";
|
|
2
|
+
import type { Tenant } from "./Tenant";
|
|
3
|
+
import type { _User } from "./_User";
|
|
4
|
+
export interface BDE_ShiftModelAttributes {
|
|
5
|
+
id: string;
|
|
6
|
+
objectId: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
name: string;
|
|
10
|
+
shifts: any[];
|
|
11
|
+
sources: any[];
|
|
12
|
+
tenant?: Tenant | undefined;
|
|
13
|
+
timezone?: string | undefined;
|
|
14
|
+
user?: _User | undefined;
|
|
15
|
+
validFrom?: Date | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare class BDE_ShiftModel extends Parse.Object<BDE_ShiftModelAttributes> {
|
|
18
|
+
static className: string;
|
|
19
|
+
constructor(data?: Partial<BDE_ShiftModelAttributes>);
|
|
20
|
+
get name(): string;
|
|
21
|
+
set name(value: string);
|
|
22
|
+
get shifts(): any[];
|
|
23
|
+
set shifts(value: any[]);
|
|
24
|
+
get sources(): any[];
|
|
25
|
+
set sources(value: any[]);
|
|
26
|
+
get tenant(): Tenant | undefined;
|
|
27
|
+
set tenant(value: Tenant | undefined);
|
|
28
|
+
get timezone(): string | undefined;
|
|
29
|
+
set timezone(value: string | undefined);
|
|
30
|
+
get user(): _User | undefined;
|
|
31
|
+
set user(value: _User | undefined);
|
|
32
|
+
get validFrom(): Date | undefined;
|
|
33
|
+
set validFrom(value: Date | undefined);
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BDE_ShiftModel = void 0;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
class BDE_ShiftModel extends node_1.default.Object {
|
|
9
|
+
static className = "OD3_BDE_ShiftModel";
|
|
10
|
+
constructor(data) {
|
|
11
|
+
super("OD3_BDE_ShiftModel", data);
|
|
12
|
+
}
|
|
13
|
+
get name() {
|
|
14
|
+
return super.get("name");
|
|
15
|
+
}
|
|
16
|
+
set name(value) {
|
|
17
|
+
super.set("name", value);
|
|
18
|
+
}
|
|
19
|
+
get shifts() {
|
|
20
|
+
return super.get("shifts");
|
|
21
|
+
}
|
|
22
|
+
set shifts(value) {
|
|
23
|
+
super.set("shifts", value);
|
|
24
|
+
}
|
|
25
|
+
get sources() {
|
|
26
|
+
return super.get("sources");
|
|
27
|
+
}
|
|
28
|
+
set sources(value) {
|
|
29
|
+
super.set("sources", value);
|
|
30
|
+
}
|
|
31
|
+
get tenant() {
|
|
32
|
+
return super.get("tenant");
|
|
33
|
+
}
|
|
34
|
+
set tenant(value) {
|
|
35
|
+
super.set("tenant", value);
|
|
36
|
+
}
|
|
37
|
+
get timezone() {
|
|
38
|
+
return super.get("timezone");
|
|
39
|
+
}
|
|
40
|
+
set timezone(value) {
|
|
41
|
+
super.set("timezone", value);
|
|
42
|
+
}
|
|
43
|
+
get user() {
|
|
44
|
+
return super.get("user");
|
|
45
|
+
}
|
|
46
|
+
set user(value) {
|
|
47
|
+
super.set("user", value);
|
|
48
|
+
}
|
|
49
|
+
get validFrom() {
|
|
50
|
+
return super.get("validFrom");
|
|
51
|
+
}
|
|
52
|
+
set validFrom(value) {
|
|
53
|
+
super.set("validFrom", value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.BDE_ShiftModel = BDE_ShiftModel;
|
|
57
|
+
node_1.default.Object.registerSubclass("OD3_BDE_ShiftModel", BDE_ShiftModel);
|