@plusscommunities/pluss-maintenance-aws 2.1.44 → 2.1.46
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/createJob.js +201 -114
- package/createJobType.js +49 -49
- package/db/maintenance/addMaintenanceJob.js +100 -90
- package/db/maintenance/editMaintenanceJob.js +22 -12
- package/db/maintenance/getJobEmail.js +22 -22
- package/deleteJob.js +58 -58
- package/deleteJobType.js +40 -40
- package/editJob.js +126 -65
- package/editJobStatus.js +57 -57
- package/editJobType.js +61 -61
- package/editNote.js +117 -117
- package/feature.config.js +279 -262
- package/getData.js +48 -41
- package/getJob.js +4 -4
- package/getJobType.js +35 -35
- package/getJobTypes.js +66 -66
- package/getJobs.js +48 -48
- package/integration/IntegrationStrategy.js +52 -52
- package/integration/archibus/ArchibusStrategy.js +42 -28
- package/integration/index.js +19 -19
- package/jobChanged.js +88 -89
- package/jobTypesChanged.js +52 -39
- package/package.json +3 -3
- package/requests/assignRequest.js +81 -81
- package/requests/getAssignees.js +27 -27
- package/requests/getExternalSync.js +100 -100
- package/requests/getPropertyRequests.js +89 -0
- package/requests/getRequest.js +77 -77
- package/requests/getRequests.js +210 -144
- package/requests/helper/hasRequestPermission.js +12 -12
- package/requests/helper/isValidAssignee.js +10 -10
- package/requests/retrySync.js +90 -90
- package/requests/setExternalJobId.js +113 -113
- package/requests/updatePriority.js +33 -33
- package/scheduleJobImport.js +63 -63
- package/sendJobEmail.js +105 -104
- package/updateData.js +34 -34
- package/values.config.a.js +26 -25
- package/values.config.default.js +30 -28
- package/values.config.enquiry.js +222 -221
- package/values.config.feedback.js +194 -193
- package/values.config.food.js +29 -28
- package/values.config.forms.js +29 -28
- package/values.config.js +30 -28
- package/watchJobs.js +154 -154
|
@@ -8,117 +8,117 @@ const { values } = require("../values.config");
|
|
|
8
8
|
const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
9
9
|
|
|
10
10
|
module.exports = async (event, data) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
11
|
+
const action = "setExternalJobId";
|
|
12
|
+
const logId = log(action, "Input", data);
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
// 1. Validate required fields
|
|
16
|
+
if (!data.id || !data.externalId || !data.systemType) {
|
|
17
|
+
return {
|
|
18
|
+
status: 422,
|
|
19
|
+
data: {
|
|
20
|
+
error: "Missing required fields: id, externalId, systemType",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 2. Find the job by ID (UUID)
|
|
26
|
+
let job;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
job = await getRef(values.tableNameMaintenance, "id", data.id);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
log(action, "Error:JobNotFound", { error: error.message }, logId);
|
|
32
|
+
return { status: 404, data: { error: "Job not found" } };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!job) {
|
|
36
|
+
log(action, "JobNotFound", { id: data.id }, logId);
|
|
37
|
+
return { status: 404, data: { error: "Job not found" } };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 3. Validate authorization using the job's site
|
|
41
|
+
const authorised = await validateMasterAuth(
|
|
42
|
+
event,
|
|
43
|
+
values.permissionMaintenanceTracking,
|
|
44
|
+
job.site,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (!authorised) {
|
|
48
|
+
log(action, "NotAuthorised", { site: job.site }, logId);
|
|
49
|
+
return { status: 403, data: { error: "Not authorised" } };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 4. Get user preview for history tracking
|
|
53
|
+
const user = await getUserPreviewFromReq(event);
|
|
54
|
+
|
|
55
|
+
// 5. Create entity type identifier
|
|
56
|
+
const entityType = `${values.serviceKey}_${data.systemType}`;
|
|
57
|
+
const rowId = `${entityType}_${data.externalId}`;
|
|
58
|
+
|
|
59
|
+
log(action, "CreatingExternalEntity", { entityType, rowId }, logId);
|
|
60
|
+
|
|
61
|
+
// 6. Create/update external entity mapping
|
|
62
|
+
const externalEntity = await updateRef("externalentities", {
|
|
63
|
+
RowId: rowId,
|
|
64
|
+
EntityType: entityType,
|
|
65
|
+
ActiveEntityType: entityType,
|
|
66
|
+
InternalId: job.id,
|
|
67
|
+
ExternalId: data.externalId,
|
|
68
|
+
LastUpdated: moment().valueOf(),
|
|
69
|
+
TrackedData: data.trackedData || {},
|
|
70
|
+
Site: job.site, // Store for site-specific queries
|
|
71
|
+
SystemType: data.systemType,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
log(action, "ExternalEntityCreated", externalEntity, logId);
|
|
75
|
+
|
|
76
|
+
// 7. Add history entry
|
|
77
|
+
if (!job.history) job.history = [];
|
|
78
|
+
job.history.push({
|
|
79
|
+
timestamp: moment.utc().valueOf(),
|
|
80
|
+
EntryType: "ExternalIDSet",
|
|
81
|
+
externalId: data.externalId,
|
|
82
|
+
user,
|
|
83
|
+
systemType: data.systemType,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// 8. Update job with history and optionally update job number for system parity
|
|
87
|
+
let updatedJob = job;
|
|
88
|
+
|
|
89
|
+
if (!isNaN(data.externalId)) {
|
|
90
|
+
log(
|
|
91
|
+
action,
|
|
92
|
+
"UpdatingJobNumber",
|
|
93
|
+
{
|
|
94
|
+
oldJobNo: job.jobNo,
|
|
95
|
+
newJobNo: data.externalId,
|
|
96
|
+
},
|
|
97
|
+
logId,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
updatedJob = await editRef(values.tableNameMaintenance, "id", job.id, {
|
|
101
|
+
jobNo: Number(data.externalId),
|
|
102
|
+
jobId: Number(data.externalId) + "",
|
|
103
|
+
history: job.history,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
log(action, "JobNumberUpdated", updatedJob, logId);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
status: 200,
|
|
111
|
+
data: {
|
|
112
|
+
success: true,
|
|
113
|
+
job: updatedJob,
|
|
114
|
+
externalEntity: externalEntity,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
log(action, "InternalError", error, logId);
|
|
119
|
+
return {
|
|
120
|
+
status: 500,
|
|
121
|
+
data: { error: "Internal error", message: error.message },
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
124
|
};
|
|
@@ -6,41 +6,41 @@ const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
|
6
6
|
const { values } = require("../values.config");
|
|
7
7
|
|
|
8
8
|
module.exports = async (event, data) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const logId = log("updatePriority", "data", data);
|
|
10
|
+
// check required data
|
|
11
|
+
const requiredKeys = ["id", "priority"];
|
|
12
|
+
if (!data || requiredKeys.some((prop) => !data.hasOwnProperty(prop))) {
|
|
13
|
+
log("updatePriority", "InsufficientInput", 422, logId);
|
|
14
|
+
return { status: 422, data: { error: "Insufficient input" } };
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const job = await getRef(values.tableNameMaintenance, "id", data.id);
|
|
18
|
+
log("updatePriority", "job", job, logId);
|
|
19
|
+
log("updatePriority", "site", job.site, logId);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
// validate authorisation
|
|
22
|
+
const valid = await validateMasterAuth(
|
|
23
|
+
event,
|
|
24
|
+
values.permissionMaintenanceTracking,
|
|
25
|
+
job.site,
|
|
26
|
+
);
|
|
27
|
+
log("updatePriority", "valid", valid, logId);
|
|
28
|
+
if (!valid) {
|
|
29
|
+
const validAssignee = await isValidAssignee(
|
|
30
|
+
event,
|
|
31
|
+
job.site,
|
|
32
|
+
job.AssigneeId,
|
|
33
|
+
);
|
|
34
|
+
log("updatePriority", "validAssignee", validAssignee, logId);
|
|
35
|
+
if (!validAssignee) {
|
|
36
|
+
log("updatePriority", "NotAuthorised", 403, logId);
|
|
37
|
+
return { status: 403, data: { error: "Not authorised" } };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
job.priority = data.priority;
|
|
42
|
+
const result = await editMaintenanceJob(job);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
log("updatePriority", "result", result, logId);
|
|
45
|
+
return { status: 200, data: { job: result } };
|
|
46
46
|
};
|
package/scheduleJobImport.js
CHANGED
|
@@ -5,83 +5,83 @@ const { getStrategy } = require("./integration");
|
|
|
5
5
|
const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
6
6
|
|
|
7
7
|
const processSingle = async (strategy, item) => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// use IDs to refresh request data
|
|
9
|
+
const logId = log("processSingle", "RefreshFromSource", item.ExternalId);
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
// refresh from external source
|
|
12
|
+
await strategy.refreshFromSource(
|
|
13
|
+
item.InternalId,
|
|
14
|
+
item.ExternalId,
|
|
15
|
+
item.TrackedData,
|
|
16
|
+
);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
// save updated timestamp
|
|
19
|
+
await editRef("externalentities", "RowId", item.RowId, {
|
|
20
|
+
LastUpdated: moment().valueOf(),
|
|
21
|
+
});
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
log("processBatch", "Refreshed", item.ExternalId, logId);
|
|
24
|
+
return true;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const processBatch = async (strategy, startTime) => {
|
|
28
|
-
|
|
28
|
+
const logId = log("processBatch", "StartTime", moment().valueOf());
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
// use index query to fetch IDs of requests
|
|
31
|
+
const query = {
|
|
32
|
+
IndexName: "ActiveEntityTypeIndex",
|
|
33
|
+
KeyConditionExpression:
|
|
34
|
+
"ActiveEntityType = :activeEntityType AND LastUpdated < :lastUpdate", // only fetch items that haven't been updated in this scan
|
|
35
|
+
ExpressionAttributeValues: {
|
|
36
|
+
":activeEntityType": strategy.getEntityType(),
|
|
37
|
+
":lastUpdate": startTime - strategy.getRefreshInterval(),
|
|
38
|
+
},
|
|
39
|
+
Limit: 10,
|
|
40
|
+
ScanIndexForward: false,
|
|
41
|
+
};
|
|
42
|
+
const { Items } = await indexQuery("externalentities", query);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
const promises = [];
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
Items.forEach((item) => {
|
|
47
|
+
log("processBatch", "ProcessSingle", JSON.stringify(item), logId);
|
|
48
|
+
promises.push(processSingle(strategy, JSON.parse(JSON.stringify(item))));
|
|
49
|
+
});
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
await Promise.all(promises);
|
|
52
|
+
log("processBatch", "EndOfBatch", Items.length, logId);
|
|
53
|
+
return Items.length;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
module.exports.scheduleJobImport = async (event, context, callback) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
const logId = log("scheduleJobImport", "Start", true);
|
|
58
|
+
// get active integration
|
|
59
|
+
const integrationStrategy = await getStrategy("plussSpace");
|
|
60
|
+
if (!integrationStrategy.isValidIntegration()) {
|
|
61
|
+
log("scheduleJobImport", "Exit", "No valid integration", logId);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const startTime = moment().valueOf();
|
|
66
|
+
const timeout = 3 * 60 * 1000; // 3 minutes
|
|
67
|
+
let noneToProcess = false;
|
|
68
|
+
log("scheduleJobImport", "StartTime", startTime, logId);
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
while (!noneToProcess && moment().valueOf() < startTime + timeout) {
|
|
71
|
+
const logId = log("scheduleJobImport", "StartLoop", moment().valueOf());
|
|
72
|
+
const count = await processBatch(integrationStrategy, startTime);
|
|
73
|
+
log("scheduleJobImport", "Count", count, logId);
|
|
74
|
+
if (!count) {
|
|
75
|
+
log("scheduleJobImport", "noneToProcess", true, logId);
|
|
76
|
+
noneToProcess = true;
|
|
77
|
+
}
|
|
78
|
+
log("scheduleJobImport", "EndLoop", moment().valueOf(), logId);
|
|
79
|
+
}
|
|
80
|
+
// TODO: Remove this call once all existing records have ActiveEntityType (PC-1382)
|
|
81
|
+
const remainingTime = startTime + timeout - moment().valueOf();
|
|
82
|
+
if (remainingTime > 0) {
|
|
83
|
+
await integrationStrategy.backfillActiveEntityType(remainingTime);
|
|
84
|
+
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
log("scheduleJobImport", "End", moment().valueOf(), logId);
|
|
87
87
|
};
|