@openinc/parse-server-opendash 4.36.0 → 4.38.0
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 +2 -0
- package/dist/features/openservice/articles/articleEquipment.d.ts +19 -0
- package/dist/features/openservice/articles/articleEquipment.js +53 -0
- package/dist/features/openservice/articles/articleStock.d.ts +19 -0
- package/dist/features/openservice/articles/articleStock.js +31 -0
- package/dist/features/openservice/equipment/criticality.d.ts +29 -0
- package/dist/features/openservice/equipment/criticality.js +85 -0
- package/dist/features/openservice/tickets/ticketPriority.d.ts +18 -11
- package/dist/features/openservice/tickets/ticketPriority.js +54 -20
- package/dist/features/openservice/tickets/ticketRules.js +1 -1
- package/dist/features/schema/indexes.js +28 -0
- package/dist/hooks/BDE_Article.js +5 -1
- package/dist/hooks/BDE_DisruptionReason.d.ts +1 -0
- package/dist/hooks/BDE_DisruptionReason.js +70 -0
- package/dist/hooks/Service_Equipment.js +3 -0
- package/dist/scripts/backfill-stock-alert.d.ts +1 -0
- package/dist/scripts/backfill-stock-alert.js +89 -0
- package/dist/scripts/migration/lib/articleMeta.d.ts +7 -3
- package/dist/scripts/migration/lib/articleMeta.js +8 -10
- package/dist/scripts/migration/passes/05-articles.d.ts +8 -4
- package/dist/scripts/migration/passes/05-articles.js +29 -12
- package/dist/types/BDE_Article.d.ts +6 -0
- package/dist/types/BDE_Article.js +12 -0
- package/dist/types/BDE_DisruptionReason.d.ts +43 -0
- package/dist/types/BDE_DisruptionReason.js +72 -0
- package/dist/types/BDE_QAOrder.d.ts +102 -0
- package/dist/types/BDE_QAOrder.js +189 -0
- package/dist/types/BDE_QAResult.d.ts +67 -0
- package/dist/types/BDE_QAResult.js +117 -0
- package/dist/types/BDE_QAValue.d.ts +53 -0
- package/dist/types/BDE_QAValue.js +93 -0
- package/dist/types/BDE_WorkOrder.d.ts +9 -0
- package/dist/types/BDE_WorkOrder.js +18 -0
- package/dist/types/Service_Equipment.d.ts +3 -0
- package/dist/types/Service_Equipment.js +6 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +11 -3
- package/package.json +2 -1
- package/schema/BDE_Article.json +9 -0
- package/schema/BDE_DisruptionReason.json +73 -0
- package/schema/BDE_QAOrder.json +45 -0
- package/schema/BDE_QAValue.json +77 -0
- package/schema/BDE_WorkOrder.json +12 -0
- package/schema/Service_Equipment.json +3 -0
package/dist/featuremap.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"OD3_Assets": "CORE",
|
|
6
6
|
"OD3_Attachment": "CORE",
|
|
7
7
|
"OD3_BDE_Article": "CORE",
|
|
8
|
+
"OD3_BDE_DisruptionReason": "BDE",
|
|
8
9
|
"OD3_BDE_Form": "BDE",
|
|
9
10
|
"OD3_BDE_List": "BDE",
|
|
10
11
|
"OD3_BDE_ListEntry": "BDE",
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
"OD3_BDE_QAFormula": "BDE",
|
|
13
14
|
"OD3_BDE_QAOrder": "BDE",
|
|
14
15
|
"OD3_BDE_QAResult": "BDE",
|
|
16
|
+
"OD3_BDE_QAValue": "BDE",
|
|
15
17
|
"OD3_BDE_Result": "BDE",
|
|
16
18
|
"OD3_BDE_ShiftException": "BDE",
|
|
17
19
|
"OD3_BDE_ShiftModel": "BDE",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalises `equipment` and rejects equipment of another tenant.
|
|
3
|
+
*
|
|
4
|
+
* The column holds plain equipment ids, written directly: an article belongs to
|
|
5
|
+
* the equipment it is assigned to, and the frontend adds the descendants when
|
|
6
|
+
* it asks for "the parts of this machine" (a part of the gearbox is a part of
|
|
7
|
+
* the machine too). Nothing is stored for the ancestors, so moving equipment in
|
|
8
|
+
* the hierarchy needs no rewrite here.
|
|
9
|
+
*
|
|
10
|
+
* Only a changed column is judged, so an article that already carries a bad id
|
|
11
|
+
* stays saveable — the ABAS sync re-saves the whole catalogue and must not stop
|
|
12
|
+
* on it. Ids that match no equipment pass: they show as nothing and harm
|
|
13
|
+
* nothing, while refusing them would block every save after equipment is
|
|
14
|
+
* deleted for good.
|
|
15
|
+
*
|
|
16
|
+
* Articles without a tenant are shared catalogue entries; they may reference
|
|
17
|
+
* any equipment, like shared master data on a ticket.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertArticleEquipment(object: Parse.Object): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
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.assertArticleEquipment = assertArticleEquipment;
|
|
7
|
+
// The equipment an article is a spare part of (`OD3_BDE_Article.equipment`).
|
|
8
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
10
|
+
const index_js_1 = require("../../../types/index.js");
|
|
11
|
+
/**
|
|
12
|
+
* Normalises `equipment` and rejects equipment of another tenant.
|
|
13
|
+
*
|
|
14
|
+
* The column holds plain equipment ids, written directly: an article belongs to
|
|
15
|
+
* the equipment it is assigned to, and the frontend adds the descendants when
|
|
16
|
+
* it asks for "the parts of this machine" (a part of the gearbox is a part of
|
|
17
|
+
* the machine too). Nothing is stored for the ancestors, so moving equipment in
|
|
18
|
+
* the hierarchy needs no rewrite here.
|
|
19
|
+
*
|
|
20
|
+
* Only a changed column is judged, so an article that already carries a bad id
|
|
21
|
+
* stays saveable — the ABAS sync re-saves the whole catalogue and must not stop
|
|
22
|
+
* on it. Ids that match no equipment pass: they show as nothing and harm
|
|
23
|
+
* nothing, while refusing them would block every save after equipment is
|
|
24
|
+
* deleted for good.
|
|
25
|
+
*
|
|
26
|
+
* Articles without a tenant are shared catalogue entries; they may reference
|
|
27
|
+
* any equipment, like shared master data on a ticket.
|
|
28
|
+
*/
|
|
29
|
+
async function assertArticleEquipment(object) {
|
|
30
|
+
if (!object.dirty("equipment"))
|
|
31
|
+
return;
|
|
32
|
+
const ids = [...new Set((0, openservice_shared_1.refIds)(object.get("equipment")))];
|
|
33
|
+
if (ids.length === 0) {
|
|
34
|
+
object.unset("equipment");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
object.set("equipment", ids);
|
|
38
|
+
const tenantId = object.get("tenant")?.id;
|
|
39
|
+
if (!tenantId)
|
|
40
|
+
return;
|
|
41
|
+
const rows = await new node_1.default.Query(index_js_1.Service_Equipment)
|
|
42
|
+
.containedIn("objectId", ids)
|
|
43
|
+
.select("tenant")
|
|
44
|
+
.limit(ids.length)
|
|
45
|
+
.find({ useMasterKey: true });
|
|
46
|
+
for (const row of rows) {
|
|
47
|
+
const refTenantId = row.get("tenant")?.id;
|
|
48
|
+
if (!refTenantId || refTenantId === tenantId)
|
|
49
|
+
continue;
|
|
50
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `Cannot assign equipment ${row.id} of tenant ${refTenantId} to an ` +
|
|
51
|
+
`article of tenant ${tenantId}.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether stock has reached the reorder point: `stock <= minimumStock`.
|
|
3
|
+
*
|
|
4
|
+
* No reorder point (unset or 0) means no alert — every ABAS article carries
|
|
5
|
+
* `minimumStock: 0` from the schema default, and none of them is "running out".
|
|
6
|
+
* Uncounted stock reads as 0: a part with a reorder point and no count is one
|
|
7
|
+
* to look at.
|
|
8
|
+
*/
|
|
9
|
+
export declare function stockAlertOf(stock: unknown, minimumStock: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Keeps `stockAlert` in step with `stock` and `minimumStock` on every save.
|
|
12
|
+
*
|
|
13
|
+
* A stored flag because a query cannot compare two columns: the article list
|
|
14
|
+
* filters on it ("Meldebestand erreicht"), and the reorder notification of
|
|
15
|
+
* "Lager light" will need it to fire once on the edge rather than on every
|
|
16
|
+
* save. Stock is still counted by hand — nothing books consumption yet — so
|
|
17
|
+
* the flag is as good as the last count.
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyStockAlert(object: Parse.Object): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stockAlertOf = stockAlertOf;
|
|
4
|
+
exports.applyStockAlert = applyStockAlert;
|
|
5
|
+
/**
|
|
6
|
+
* Whether stock has reached the reorder point: `stock <= minimumStock`.
|
|
7
|
+
*
|
|
8
|
+
* No reorder point (unset or 0) means no alert — every ABAS article carries
|
|
9
|
+
* `minimumStock: 0` from the schema default, and none of them is "running out".
|
|
10
|
+
* Uncounted stock reads as 0: a part with a reorder point and no count is one
|
|
11
|
+
* to look at.
|
|
12
|
+
*/
|
|
13
|
+
function stockAlertOf(stock, minimumStock) {
|
|
14
|
+
if (typeof minimumStock !== "number" || minimumStock <= 0)
|
|
15
|
+
return false;
|
|
16
|
+
return (typeof stock === "number" ? stock : 0) <= minimumStock;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Keeps `stockAlert` in step with `stock` and `minimumStock` on every save.
|
|
20
|
+
*
|
|
21
|
+
* A stored flag because a query cannot compare two columns: the article list
|
|
22
|
+
* filters on it ("Meldebestand erreicht"), and the reorder notification of
|
|
23
|
+
* "Lager light" will need it to fire once on the edge rather than on every
|
|
24
|
+
* save. Stock is still counted by hand — nothing books consumption yet — so
|
|
25
|
+
* the flag is as good as the last count.
|
|
26
|
+
*/
|
|
27
|
+
function applyStockAlert(object) {
|
|
28
|
+
const alert = stockAlertOf(object.get("stock"), object.get("minimumStock"));
|
|
29
|
+
if (object.get("stockAlert") !== alert)
|
|
30
|
+
object.set("stockAlert", alert);
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The classes, most critical first. Mirrors `CRITICALITY_LEVELS` in
|
|
3
|
+
* `@opendash/plugin-openservice-core`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CRITICALITY_LEVELS: readonly ["A", "B", "C"];
|
|
6
|
+
export type Criticality = (typeof CRITICALITY_LEVELS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* What the priority formula reads under `criticality`: the classes on the
|
|
9
|
+
* 0–100 scale of the ticket's factors. Unclassified equipment, and a ticket
|
|
10
|
+
* without equipment, read 0 like class C — the factors' rule for an empty
|
|
11
|
+
* input. Mirrors `CRITICALITY_VALUES` of the core plugin.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CRITICALITY_VALUES: Record<Criticality, number>;
|
|
14
|
+
export declare function isCriticality(value: unknown): value is Criticality;
|
|
15
|
+
/**
|
|
16
|
+
* Normalises `criticality` on an equipment being saved: trimmed and
|
|
17
|
+
* upper-cased, empty unsets it (the equipment inherits again). Anything but
|
|
18
|
+
* A, B or C is refused.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeCriticality(object: Parse.Object): void;
|
|
21
|
+
/**
|
|
22
|
+
* The class an equipment counts as: its own, else the nearest ancestor's;
|
|
23
|
+
* `undefined` when nobody up the tree classified it. Reads one row per level
|
|
24
|
+
* with the master key — the caller decides whose equipment it asks about.
|
|
25
|
+
* Guarded against a cycle in `parent`, which migrated data has had.
|
|
26
|
+
*/
|
|
27
|
+
export declare function effectiveCriticality(equipment: Parse.Object | undefined): Promise<Criticality | undefined>;
|
|
28
|
+
/** The number the priority formula reads for a class. */
|
|
29
|
+
export declare function criticalityValue(criticality: Criticality | undefined): number;
|
|
@@ -0,0 +1,85 @@
|
|
|
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.CRITICALITY_VALUES = exports.CRITICALITY_LEVELS = void 0;
|
|
7
|
+
exports.isCriticality = isCriticality;
|
|
8
|
+
exports.normalizeCriticality = normalizeCriticality;
|
|
9
|
+
exports.effectiveCriticality = effectiveCriticality;
|
|
10
|
+
exports.criticalityValue = criticalityValue;
|
|
11
|
+
// How critical a piece of equipment is for production: A (stops it), B
|
|
12
|
+
// (hampers it), C (neither). Set where somebody classified it and inherited
|
|
13
|
+
// downwards: a gearbox without its own class counts as its machine does.
|
|
14
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
15
|
+
const index_js_1 = require("../../../types/index.js");
|
|
16
|
+
/**
|
|
17
|
+
* The classes, most critical first. Mirrors `CRITICALITY_LEVELS` in
|
|
18
|
+
* `@opendash/plugin-openservice-core`.
|
|
19
|
+
*/
|
|
20
|
+
exports.CRITICALITY_LEVELS = ["A", "B", "C"];
|
|
21
|
+
/**
|
|
22
|
+
* What the priority formula reads under `criticality`: the classes on the
|
|
23
|
+
* 0–100 scale of the ticket's factors. Unclassified equipment, and a ticket
|
|
24
|
+
* without equipment, read 0 like class C — the factors' rule for an empty
|
|
25
|
+
* input. Mirrors `CRITICALITY_VALUES` of the core plugin.
|
|
26
|
+
*/
|
|
27
|
+
exports.CRITICALITY_VALUES = {
|
|
28
|
+
A: 100,
|
|
29
|
+
B: 50,
|
|
30
|
+
C: 0,
|
|
31
|
+
};
|
|
32
|
+
/** Further up than any real hierarchy; stops a walk through broken data. */
|
|
33
|
+
const MAX_DEPTH = 50;
|
|
34
|
+
function isCriticality(value) {
|
|
35
|
+
return (typeof value === "string" &&
|
|
36
|
+
exports.CRITICALITY_LEVELS.includes(value));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalises `criticality` on an equipment being saved: trimmed and
|
|
40
|
+
* upper-cased, empty unsets it (the equipment inherits again). Anything but
|
|
41
|
+
* A, B or C is refused.
|
|
42
|
+
*/
|
|
43
|
+
function normalizeCriticality(object) {
|
|
44
|
+
const raw = object.get("criticality");
|
|
45
|
+
if (raw == null)
|
|
46
|
+
return;
|
|
47
|
+
const value = typeof raw === "string" ? raw.trim().toUpperCase() : raw;
|
|
48
|
+
if (value === "") {
|
|
49
|
+
object.unset("criticality");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!isCriticality(value)) {
|
|
53
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `criticality must be one of ${exports.CRITICALITY_LEVELS.join(", ")}`);
|
|
54
|
+
}
|
|
55
|
+
if (value !== raw)
|
|
56
|
+
object.set("criticality", value);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The class an equipment counts as: its own, else the nearest ancestor's;
|
|
60
|
+
* `undefined` when nobody up the tree classified it. Reads one row per level
|
|
61
|
+
* with the master key — the caller decides whose equipment it asks about.
|
|
62
|
+
* Guarded against a cycle in `parent`, which migrated data has had.
|
|
63
|
+
*/
|
|
64
|
+
async function effectiveCriticality(equipment) {
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
let id = equipment?.id;
|
|
67
|
+
while (id && !seen.has(id) && seen.size < MAX_DEPTH) {
|
|
68
|
+
seen.add(id);
|
|
69
|
+
const row = await new node_1.default.Query(index_js_1.Service_Equipment)
|
|
70
|
+
.select("criticality", "parent")
|
|
71
|
+
.equalTo("objectId", id)
|
|
72
|
+
.first({ useMasterKey: true });
|
|
73
|
+
if (!row)
|
|
74
|
+
return undefined;
|
|
75
|
+
const own = row.get("criticality");
|
|
76
|
+
if (isCriticality(own))
|
|
77
|
+
return own;
|
|
78
|
+
id = row.get("parent")?.id;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/** The number the priority formula reads for a class. */
|
|
83
|
+
function criticalityValue(criticality) {
|
|
84
|
+
return criticality ? exports.CRITICALITY_VALUES[criticality] : 0;
|
|
85
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { FormulaNode } from "@opendash/ruleset-core";
|
|
2
2
|
import type { Service_FormConfig } from "../../../types/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
4
|
+
* The names a priority formula may read, e.g.
|
|
5
5
|
* `max(downtime, restriction) * 0.7 + frequency * 0.3`. Mirrors
|
|
6
|
-
* `
|
|
6
|
+
* `PRIORITY_FORMULA_INPUTS` in `@opendash/plugin-openservice-ticket`.
|
|
7
7
|
*/
|
|
8
|
-
export declare const PRIORITY_FORMULA_INPUTS: readonly ["downtime", "restriction", "frequency"];
|
|
8
|
+
export declare const PRIORITY_FORMULA_INPUTS: readonly ["downtime", "restriction", "frequency", "criticality"];
|
|
9
9
|
interface PriorityFormula {
|
|
10
10
|
expression: FormulaNode;
|
|
11
11
|
names: string[];
|
|
@@ -21,28 +21,35 @@ export declare function priorityFormulaOf(config: Service_FormConfig | undefined
|
|
|
21
21
|
* The priority for a ticket's values, or `undefined` when there is nothing to
|
|
22
22
|
* compute from. Mirrors `computePriority` of the frontend:
|
|
23
23
|
*
|
|
24
|
-
* - None of the
|
|
25
|
-
* nobody has assessed keeps its priority.
|
|
24
|
+
* - None of the scale fields the formula reads is set: `undefined`, so a
|
|
25
|
+
* ticket nobody has assessed keeps its priority. The equipment's
|
|
26
|
+
* criticality does not count here — it is known for every ticket on
|
|
27
|
+
* classified equipment, assessed or not.
|
|
26
28
|
* - Some are set: the rest count as 0, the lowest level.
|
|
27
29
|
* - Clamped to 0–100 and rounded; no number at all (division by zero) is
|
|
28
30
|
* `undefined` as well.
|
|
29
31
|
*/
|
|
30
32
|
export declare function computePriority(formula: PriorityFormula, values: (key: string) => unknown): number | undefined;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Whether this save changes one of the inputs a priority formula reads: a
|
|
35
|
+
* scale field, or the equipment — whose class the formula reads under
|
|
36
|
+
* `criticality`. Without `formula`, whether it may: the equipment counts
|
|
37
|
+
* whenever a formula could read it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function changesPriorityInputs(object: Parse.Object, original: Parse.Object | undefined, formula?: PriorityFormula): boolean;
|
|
33
40
|
/**
|
|
34
41
|
* Sets the computed priority on a ticket being saved, under `config` — the
|
|
35
42
|
* form config that applies to the user saving (see `applicableFormConfig`).
|
|
36
43
|
*
|
|
37
44
|
* Only when this save changes one of the inputs — a ticket the save does not
|
|
38
|
-
* reassess keeps its priority, also when the formula has changed since
|
|
39
|
-
* only when the caller does not set the priority
|
|
40
|
-
* import keeps the priority its file states.
|
|
45
|
+
* reassess keeps its priority, also when the formula has changed since, or the
|
|
46
|
+
* class of its equipment — and only when the caller does not set the priority
|
|
47
|
+
* itself in the same save: an import keeps the priority its file states.
|
|
41
48
|
*
|
|
42
49
|
* "Changes" and "sets" are judged against `original`. The admin table sends
|
|
43
50
|
* every field of its form, the unchanged priority included; counting that as
|
|
44
51
|
* set by hand would leave the old priority after every factor edit there —
|
|
45
52
|
* which is the case this exists for.
|
|
46
53
|
*/
|
|
47
|
-
export declare function applyComputedPriority(object: Parse.Object, original: Parse.Object | undefined, config: Service_FormConfig | undefined): void
|
|
54
|
+
export declare function applyComputedPriority(object: Parse.Object, original: Parse.Object | undefined, config: Service_FormConfig | undefined): Promise<void>;
|
|
48
55
|
export {};
|
|
@@ -6,15 +6,26 @@ exports.computePriority = computePriority;
|
|
|
6
6
|
exports.changesPriorityInputs = changesPriorityInputs;
|
|
7
7
|
exports.applyComputedPriority = applyComputedPriority;
|
|
8
8
|
const ruleset_core_1 = require("@opendash/ruleset-core");
|
|
9
|
+
const criticality_js_1 = require("../equipment/criticality.js");
|
|
9
10
|
/**
|
|
10
|
-
* The
|
|
11
|
+
* The ticket's own assessment: the scale fields. Mirrors `SCALE_FIELD_KEYS` in
|
|
12
|
+
* `@opendash/plugin-openservice-ticket`.
|
|
13
|
+
*/
|
|
14
|
+
const ASSESSMENT_INPUTS = ["downtime", "restriction", "frequency"];
|
|
15
|
+
/**
|
|
16
|
+
* The equipment's class (A 100, B 50, C or none 0), inherited down the tree —
|
|
17
|
+
* see `criticality.ts`. Context, not an assessment: it alone never makes a
|
|
18
|
+
* ticket "assessed" (see {@link computePriority}).
|
|
19
|
+
*/
|
|
20
|
+
const CRITICALITY_INPUT = "criticality";
|
|
21
|
+
/**
|
|
22
|
+
* The names a priority formula may read, e.g.
|
|
11
23
|
* `max(downtime, restriction) * 0.7 + frequency * 0.3`. Mirrors
|
|
12
|
-
* `
|
|
24
|
+
* `PRIORITY_FORMULA_INPUTS` in `@opendash/plugin-openservice-ticket`.
|
|
13
25
|
*/
|
|
14
26
|
exports.PRIORITY_FORMULA_INPUTS = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"frequency",
|
|
27
|
+
...ASSESSMENT_INPUTS,
|
|
28
|
+
CRITICALITY_INPUT,
|
|
18
29
|
];
|
|
19
30
|
/**
|
|
20
31
|
* The formula a config's priority entry asks for, or `undefined` when the
|
|
@@ -49,8 +60,10 @@ function asNumber(value) {
|
|
|
49
60
|
* The priority for a ticket's values, or `undefined` when there is nothing to
|
|
50
61
|
* compute from. Mirrors `computePriority` of the frontend:
|
|
51
62
|
*
|
|
52
|
-
* - None of the
|
|
53
|
-
* nobody has assessed keeps its priority.
|
|
63
|
+
* - None of the scale fields the formula reads is set: `undefined`, so a
|
|
64
|
+
* ticket nobody has assessed keeps its priority. The equipment's
|
|
65
|
+
* criticality does not count here — it is known for every ticket on
|
|
66
|
+
* classified equipment, assessed or not.
|
|
54
67
|
* - Some are set: the rest count as 0, the lowest level.
|
|
55
68
|
* - Clamped to 0–100 and rounded; no number at all (division by zero) is
|
|
56
69
|
* `undefined` as well.
|
|
@@ -60,7 +73,7 @@ function computePriority(formula, values) {
|
|
|
60
73
|
let anySet = false;
|
|
61
74
|
for (const name of formula.names) {
|
|
62
75
|
const value = asNumber(values(name));
|
|
63
|
-
if (value !== undefined)
|
|
76
|
+
if (value !== undefined && name !== CRITICALITY_INPUT)
|
|
64
77
|
anySet = true;
|
|
65
78
|
scope[name] = value ?? 0;
|
|
66
79
|
}
|
|
@@ -77,33 +90,54 @@ function changes(object, original, key) {
|
|
|
77
90
|
? object.get(key) !== original.get(key)
|
|
78
91
|
: object.get(key) != null;
|
|
79
92
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Whether this save moves the ticket to other equipment. Compared by id: a
|
|
95
|
+
* pointer comes back as a new object on every read.
|
|
96
|
+
*/
|
|
97
|
+
function changesEquipment(object, original) {
|
|
98
|
+
const id = (o) => o?.get("equipment")?.id;
|
|
99
|
+
return original ? id(object) !== id(original) : id(object) != null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Whether this save changes one of the inputs a priority formula reads: a
|
|
103
|
+
* scale field, or the equipment — whose class the formula reads under
|
|
104
|
+
* `criticality`. Without `formula`, whether it may: the equipment counts
|
|
105
|
+
* whenever a formula could read it.
|
|
106
|
+
*/
|
|
107
|
+
function changesPriorityInputs(object, original, formula) {
|
|
108
|
+
if (ASSESSMENT_INPUTS.some((key) => changes(object, original, key)))
|
|
109
|
+
return true;
|
|
110
|
+
const readsCriticality = formula
|
|
111
|
+
? formula.names.includes(CRITICALITY_INPUT)
|
|
112
|
+
: true;
|
|
113
|
+
return readsCriticality && changesEquipment(object, original);
|
|
83
114
|
}
|
|
84
115
|
/**
|
|
85
116
|
* Sets the computed priority on a ticket being saved, under `config` — the
|
|
86
117
|
* form config that applies to the user saving (see `applicableFormConfig`).
|
|
87
118
|
*
|
|
88
119
|
* Only when this save changes one of the inputs — a ticket the save does not
|
|
89
|
-
* reassess keeps its priority, also when the formula has changed since
|
|
90
|
-
* only when the caller does not set the priority
|
|
91
|
-
* import keeps the priority its file states.
|
|
120
|
+
* reassess keeps its priority, also when the formula has changed since, or the
|
|
121
|
+
* class of its equipment — and only when the caller does not set the priority
|
|
122
|
+
* itself in the same save: an import keeps the priority its file states.
|
|
92
123
|
*
|
|
93
124
|
* "Changes" and "sets" are judged against `original`. The admin table sends
|
|
94
125
|
* every field of its form, the unchanged priority included; counting that as
|
|
95
126
|
* set by hand would leave the old priority after every factor edit there —
|
|
96
127
|
* which is the case this exists for.
|
|
97
128
|
*/
|
|
98
|
-
function applyComputedPriority(object, original, config) {
|
|
99
|
-
if (!changesPriorityInputs(object, original))
|
|
100
|
-
return;
|
|
101
|
-
if (changes(object, original, "priority"))
|
|
102
|
-
return;
|
|
129
|
+
async function applyComputedPriority(object, original, config) {
|
|
103
130
|
const formula = priorityFormulaOf(config);
|
|
104
131
|
if (!formula)
|
|
105
132
|
return;
|
|
106
|
-
|
|
133
|
+
if (!changesPriorityInputs(object, original, formula))
|
|
134
|
+
return;
|
|
135
|
+
if (changes(object, original, "priority"))
|
|
136
|
+
return;
|
|
137
|
+
const criticality = formula.names.includes(CRITICALITY_INPUT)
|
|
138
|
+
? (0, criticality_js_1.criticalityValue)(await (0, criticality_js_1.effectiveCriticality)(object.get("equipment")))
|
|
139
|
+
: undefined;
|
|
140
|
+
const priority = computePriority(formula, (key) => key === CRITICALITY_INPUT ? criticality : object.get(key));
|
|
107
141
|
if (priority !== undefined)
|
|
108
142
|
object.set("priority", priority);
|
|
109
143
|
}
|
|
@@ -227,7 +227,7 @@ async function applyFormConfigRules(object, original, user, { master, sessionTok
|
|
|
227
227
|
master,
|
|
228
228
|
sessionToken,
|
|
229
229
|
})) ?? (await (0, ticketFormConfig_js_1.applicableFormConfig)(tenant, user));
|
|
230
|
-
(0, ticketPriority_js_1.applyComputedPriority)(object, original, config);
|
|
230
|
+
await (0, ticketPriority_js_1.applyComputedPriority)(object, original, config);
|
|
231
231
|
if (!runRules || !config)
|
|
232
232
|
return;
|
|
233
233
|
applyValueRules(parseJson(config.fields), object, original, new Date());
|
|
@@ -189,8 +189,36 @@ exports.INDEXES = [
|
|
|
189
189
|
// Work orders of an order plan (MES order view).
|
|
190
190
|
od_orderPlan: ["orderPlan"],
|
|
191
191
|
}),
|
|
192
|
+
// Reasons of a tenant, and the unique-key check of their hook.
|
|
193
|
+
defineIndexes(index_js_1.BDE_DisruptionReason, {
|
|
194
|
+
od_tenant_key: ["tenant", "key"],
|
|
195
|
+
}),
|
|
192
196
|
defineIndexes(index_js_1.BDE_Article, {
|
|
193
197
|
od_articleNumber: ["articleNumber"],
|
|
198
|
+
// Spare parts of an equipment subtree (`equipment` contained in the ids):
|
|
199
|
+
// the material picker and the equipment page.
|
|
200
|
+
od_equipment: ["equipment"],
|
|
201
|
+
// "Meldebestand erreicht": the article list filters on it.
|
|
202
|
+
od_stockAlert: ["stockAlert"],
|
|
203
|
+
}),
|
|
204
|
+
// One inspection order per container. The inspection sheet lists the orders
|
|
205
|
+
// of a work order, the search finds one by its container number.
|
|
206
|
+
defineIndexes(index_js_1.BDE_QAOrder, {
|
|
207
|
+
od_workOrderNr: ["workOrderNr"],
|
|
208
|
+
od_containerNr: ["containerNr"],
|
|
209
|
+
}),
|
|
210
|
+
// One row per transmission to the ERP. The history of an order, and the
|
|
211
|
+
// lookup of a retried transmission by its id.
|
|
212
|
+
defineIndexes(index_js_1.BDE_QAResult, {
|
|
213
|
+
od_qaOrder_inspectedAt: ["qaOrder", "inspectedAt"],
|
|
214
|
+
od_submissionId: ["submissionId"],
|
|
215
|
+
}),
|
|
216
|
+
// Append-only: every entered value is a row, the current one is the newest
|
|
217
|
+
// per order and characteristic. Read per order (detail, saving) and per work
|
|
218
|
+
// order (the inspection sheet), always newest first.
|
|
219
|
+
defineIndexes(index_js_1.BDE_QAValue, {
|
|
220
|
+
od_qaOrder_createdAt: ["qaOrder", "createdAt"],
|
|
221
|
+
od_workOrderNr_createdAt: ["workOrderNr", "createdAt"],
|
|
194
222
|
}),
|
|
195
223
|
// --- MES ---
|
|
196
224
|
// A cron job reads the last day's orders every minute.
|
|
@@ -2,6 +2,8 @@
|
|
|
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 articleEquipment_js_1 = require("../features/openservice/articles/articleEquipment.js");
|
|
6
|
+
const articleStock_js_1 = require("../features/openservice/articles/articleStock.js");
|
|
5
7
|
const index_js_2 = require("../types/index.js");
|
|
6
8
|
async function init() {
|
|
7
9
|
// Soft delete: articles are referenced from a ticket's `material` list and
|
|
@@ -35,7 +37,9 @@ async function init() {
|
|
|
35
37
|
allowCustomACL: true,
|
|
36
38
|
allowTenantUserWrite: true,
|
|
37
39
|
});
|
|
38
|
-
//
|
|
40
|
+
// After `defaultHandler`, which settles the tenant the check compares with.
|
|
41
|
+
await (0, articleEquipment_js_1.assertArticleEquipment)(object);
|
|
42
|
+
(0, articleStock_js_1.applyStockAlert)(object);
|
|
39
43
|
});
|
|
40
44
|
(0, index_js_1.afterSaveHook)(index_js_2.BDE_Article, async (request) => {
|
|
41
45
|
const { object, original, user } = request;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
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("../types/index.js");
|
|
10
|
+
/** Longest key accepted — it is stored on every disruption booking. */
|
|
11
|
+
const MAX_KEY_LENGTH = 64;
|
|
12
|
+
async function init() {
|
|
13
|
+
// The reasons a BDE disruption is reported with. A reported disruption
|
|
14
|
+
// stores the reason's `key` in `OD3_BDE_WorkTime.comment`, and instances map
|
|
15
|
+
// it on — Künne sends `externalCode` to ABAS as `sgrund`. So the key is
|
|
16
|
+
// fixed once saved, unique per tenant, and a reason in use is deactivated
|
|
17
|
+
// (`active: false`) rather than deleted.
|
|
18
|
+
//
|
|
19
|
+
// Read by every user of the tenant (the disruption dialog offers them),
|
|
20
|
+
// written by the creator and tenant admins; further editors are granted in
|
|
21
|
+
// the BDE admin's permission dialog, so a custom ACL is kept.
|
|
22
|
+
(0, index_js_1.beforeSaveHook)(index_js_2.BDE_DisruptionReason, async (request) => {
|
|
23
|
+
const { object, original, master } = request;
|
|
24
|
+
await (0, index_js_1.defaultHandler)(request);
|
|
25
|
+
await (0, index_js_1.defaultAclHandler)(request, { allowCustomACL: true });
|
|
26
|
+
const key = String(object.get("key") ?? "").trim();
|
|
27
|
+
if (!key || key.length > MAX_KEY_LENGTH || /\s/.test(key)) {
|
|
28
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `A disruption reason needs a key of 1–${MAX_KEY_LENGTH} characters ` +
|
|
29
|
+
`without spaces.`);
|
|
30
|
+
}
|
|
31
|
+
if (original && original.get("key") !== key && !master) {
|
|
32
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "The key of a disruption reason cannot be changed: bookings store it.");
|
|
33
|
+
}
|
|
34
|
+
object.set("key", key);
|
|
35
|
+
const label = String(object.get("label") ?? "").trim();
|
|
36
|
+
if (!label) {
|
|
37
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "A disruption reason needs a label.");
|
|
38
|
+
}
|
|
39
|
+
object.set("label", label);
|
|
40
|
+
if (!object.isNew() && !object.dirty("key"))
|
|
41
|
+
return;
|
|
42
|
+
const duplicate = new node_1.default.Query(index_js_2.BDE_DisruptionReason).equalTo("key", key);
|
|
43
|
+
const tenant = object.get("tenant");
|
|
44
|
+
if (tenant)
|
|
45
|
+
duplicate.equalTo("tenant", tenant);
|
|
46
|
+
else
|
|
47
|
+
duplicate.doesNotExist("tenant");
|
|
48
|
+
if (object.id)
|
|
49
|
+
duplicate.notEqualTo("objectId", object.id);
|
|
50
|
+
if (await duplicate.first({ useMasterKey: true })) {
|
|
51
|
+
throw new node_1.default.Error(node_1.default.Error.DUPLICATE_VALUE, `There is already a disruption reason with the key "${key}".`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
(0, index_js_1.beforeDeleteHook)(index_js_2.BDE_DisruptionReason, async (request) => {
|
|
55
|
+
const { object } = request;
|
|
56
|
+
const key = object.get("key");
|
|
57
|
+
if (!key)
|
|
58
|
+
return;
|
|
59
|
+
const inUse = new node_1.default.Query(index_js_2.BDE_WorkTime)
|
|
60
|
+
.equalTo("status", "disrupted")
|
|
61
|
+
.equalTo("comment", key);
|
|
62
|
+
const tenant = object.get("tenant");
|
|
63
|
+
if (tenant)
|
|
64
|
+
inUse.equalTo("tenant", tenant);
|
|
65
|
+
if (await inUse.first({ useMasterKey: true })) {
|
|
66
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `The disruption reason "${key}" is used by bookings — deactivate it ` +
|
|
67
|
+
`instead of deleting it.`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -7,6 +7,7 @@ exports.init = init;
|
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
9
9
|
const index_js_1 = require("../features/schema/index.js");
|
|
10
|
+
const criticality_js_1 = require("../features/openservice/equipment/criticality.js");
|
|
10
11
|
const index_js_2 = require("../features/permissions/index.js");
|
|
11
12
|
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
12
13
|
const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
|
|
@@ -37,6 +38,8 @@ async function init() {
|
|
|
37
38
|
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
38
39
|
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive equipment");
|
|
39
40
|
}
|
|
41
|
+
// A, B, C or unset (inherits from the parent) — see `criticality.ts`.
|
|
42
|
+
(0, criticality_js_1.normalizeCriticality)(object);
|
|
40
43
|
await (0, index_js_1.defaultHandler)(request);
|
|
41
44
|
await (0, index_js_1.defaultAclHandler)(request);
|
|
42
45
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|