@plusscommunities/pluss-maintenance-aws-forms 2.1.22 → 2.1.24
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/getData.js
CHANGED
|
@@ -5,6 +5,7 @@ const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/ge
|
|
|
5
5
|
const getAssignees = require("./requests/getAssignees");
|
|
6
6
|
const getRequests = require("./requests/getRequests");
|
|
7
7
|
const getRequest = require("./requests/getRequest");
|
|
8
|
+
const getExternalSync = require("./requests/getExternalSync");
|
|
8
9
|
|
|
9
10
|
module.exports.getData = async (event, context, callback) => {
|
|
10
11
|
init(config);
|
|
@@ -34,6 +35,12 @@ module.exports.getData = async (event, context, callback) => {
|
|
|
34
35
|
log(action, "ResponseLength", response.data.Users.length, logId);
|
|
35
36
|
}
|
|
36
37
|
break;
|
|
38
|
+
case "externalsync":
|
|
39
|
+
response = await getExternalSync(event);
|
|
40
|
+
if (response.status === 200) {
|
|
41
|
+
log(action, "ExternalSystem", response.data.externalSystem, logId);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
37
44
|
default:
|
|
38
45
|
break;
|
|
39
46
|
}
|
|
@@ -128,6 +128,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
128
128
|
InternalId: request.id,
|
|
129
129
|
ExternalId: response.data.wrId,
|
|
130
130
|
TrackedData: {},
|
|
131
|
+
SystemType: "Archibus",
|
|
131
132
|
});
|
|
132
133
|
|
|
133
134
|
// Save the Archibus ID as the job number and add history entry
|
|
@@ -139,12 +140,13 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
139
140
|
if (!updatedJob.history) updatedJob.history = [];
|
|
140
141
|
updatedJob.history.push({
|
|
141
142
|
timestamp: moment.utc().valueOf(),
|
|
142
|
-
|
|
143
|
+
EntryType: "ExternalIDSet",
|
|
143
144
|
externalId: response.data.wrId,
|
|
144
145
|
user: {
|
|
145
146
|
displayName: "Archibus Integration",
|
|
146
147
|
id: "system",
|
|
147
148
|
},
|
|
149
|
+
systemType: "Archibus",
|
|
148
150
|
});
|
|
149
151
|
|
|
150
152
|
await editRef(values.tableNameMaintenance, "id", request.id, {
|
|
@@ -176,11 +178,12 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
176
178
|
if (!failedJob.history) failedJob.history = [];
|
|
177
179
|
failedJob.history.push({
|
|
178
180
|
timestamp: moment.utc().valueOf(),
|
|
179
|
-
|
|
181
|
+
EntryType: "ExternalIDSetFailed",
|
|
180
182
|
user: {
|
|
181
183
|
displayName: "Archibus Integration",
|
|
182
184
|
id: "system",
|
|
183
185
|
},
|
|
186
|
+
systemType: "Archibus",
|
|
184
187
|
});
|
|
185
188
|
|
|
186
189
|
await editRef(values.tableNameMaintenance, "id", request.id, {
|
|
@@ -167,7 +167,7 @@ class SeeStuffStrategy extends IntegrationStrategy {
|
|
|
167
167
|
if (!failedJob.history) failedJob.history = [];
|
|
168
168
|
failedJob.history.push({
|
|
169
169
|
timestamp: moment.utc().valueOf(),
|
|
170
|
-
|
|
170
|
+
EntryType: "ExternalIDSetFailed",
|
|
171
171
|
user: {
|
|
172
172
|
displayName: "SeeStuff Integration",
|
|
173
173
|
id: "system",
|
package/package-lock.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
2
|
+
const indexQuery = require("@plusscommunities/pluss-core-aws/db/common/indexQuery");
|
|
3
|
+
const validateMasterAuth = require("@plusscommunities/pluss-core-aws/helper/auth/validateMasterAuth");
|
|
4
|
+
const isValidAssignee = require("./helper/isValidAssignee");
|
|
5
|
+
const getSessionUserFromReqAuthKey = require("@plusscommunities/pluss-core-aws/helper/auth/getSessionUserFromReqAuthKey");
|
|
6
|
+
const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
7
|
+
const { values } = require("../values.config");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves external system sync information for a maintenance request
|
|
11
|
+
*
|
|
12
|
+
* Checks both SeeStuff and Archibus external entity tables to find
|
|
13
|
+
* if the request has been synced to an external system.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} event - Lambda event object
|
|
16
|
+
* @param {Object} params - Query parameters (optional, uses event.queryStringParameters if not provided)
|
|
17
|
+
* @returns {Object} Response object with status and data
|
|
18
|
+
*
|
|
19
|
+
* Response format (200):
|
|
20
|
+
* {
|
|
21
|
+
* externalSystem: "SeeStuff" | "Archibus",
|
|
22
|
+
* externalId: string,
|
|
23
|
+
* syncedAt: number (Unix timestamp),
|
|
24
|
+
* trackedData: object
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* Error responses:
|
|
28
|
+
* - 422: Missing required field (id)
|
|
29
|
+
* - 404: Request not found OR no external sync exists
|
|
30
|
+
* - 403: Not authorized (user doesn't have permission to view request)
|
|
31
|
+
* - 500: Internal server error
|
|
32
|
+
*/
|
|
33
|
+
module.exports = async (event, params) => {
|
|
34
|
+
const data = params || event.queryStringParameters || {};
|
|
35
|
+
const logId = log("getExternalSync", "Params", data);
|
|
36
|
+
|
|
37
|
+
// Validate input
|
|
38
|
+
if (!data.id) {
|
|
39
|
+
log("getExternalSync", "MissingId", true, logId);
|
|
40
|
+
return {
|
|
41
|
+
status: 422,
|
|
42
|
+
data: { error: "Missing required field: id" },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
// Get the request to verify it exists and get site for permission check
|
|
48
|
+
let request;
|
|
49
|
+
try {
|
|
50
|
+
request = await getRef(values.tableNameMaintenance, "id", data.id);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
log("getExternalSync", "RequestNotFound", { id: data.id }, logId);
|
|
53
|
+
return {
|
|
54
|
+
status: 404,
|
|
55
|
+
data: { error: "Request not found" },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!request) {
|
|
60
|
+
log("getExternalSync", "RequestNotFound", { id: data.id }, logId);
|
|
61
|
+
return {
|
|
62
|
+
status: 404,
|
|
63
|
+
data: { error: "Request not found" },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Check permissions (same pattern as getRequest.js)
|
|
68
|
+
// Three levels of access:
|
|
69
|
+
// 1. Full admin with maintenance tracking permission
|
|
70
|
+
// 2. User assigned to the request
|
|
71
|
+
// 3. User who created the request
|
|
72
|
+
const authorised = await validateMasterAuth(
|
|
73
|
+
event,
|
|
74
|
+
values.permissionMaintenanceTracking,
|
|
75
|
+
request.site
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const assignAuthorised = await isValidAssignee(
|
|
79
|
+
event,
|
|
80
|
+
request.site,
|
|
81
|
+
request.AssigneeId
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (!authorised && !assignAuthorised) {
|
|
85
|
+
// Check if user is the request owner
|
|
86
|
+
const userId = await getSessionUserFromReqAuthKey(event);
|
|
87
|
+
if (userId !== request.userID) {
|
|
88
|
+
log(
|
|
89
|
+
"getExternalSync",
|
|
90
|
+
"NotAuthorised",
|
|
91
|
+
{ userId, requestOwner: request.userID },
|
|
92
|
+
logId
|
|
93
|
+
);
|
|
94
|
+
return {
|
|
95
|
+
status: 403,
|
|
96
|
+
data: { error: "Not authorised" },
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
log("getExternalSync", "Authorised", true, logId);
|
|
102
|
+
|
|
103
|
+
let externalSync = null;
|
|
104
|
+
const query = await indexQuery("externalentities", {
|
|
105
|
+
IndexName: "OnlyInternalIdIndex",
|
|
106
|
+
KeyConditionExpression: "InternalId = :internalId",
|
|
107
|
+
ExpressionAttributeValues: {
|
|
108
|
+
":internalId": request.id,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
log("getExternalSync", "Results", query.Items.length, logId);
|
|
113
|
+
|
|
114
|
+
if (query.Items && query.Items.length > 0) {
|
|
115
|
+
const item = query.Items[0];
|
|
116
|
+
externalSync = {
|
|
117
|
+
systemType: item.SystemType,
|
|
118
|
+
externalId: item.ExternalId,
|
|
119
|
+
syncedAt: item.LastUpdated,
|
|
120
|
+
trackedData: item.TrackedData || {},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
log("getExternalSync", "FoundSync", externalSync, logId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// If no external sync found, return 404
|
|
127
|
+
if (!externalSync) {
|
|
128
|
+
log("getExternalSync", "NoSyncFound", { id: data.id }, logId);
|
|
129
|
+
return {
|
|
130
|
+
status: 404,
|
|
131
|
+
data: { error: "No external sync found" },
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
log("getExternalSync", "Success", externalSync, logId);
|
|
136
|
+
return {
|
|
137
|
+
status: 200,
|
|
138
|
+
data: externalSync,
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
log("getExternalSync", "InternalError", error.toString(), logId);
|
|
142
|
+
return {
|
|
143
|
+
status: 500,
|
|
144
|
+
data: { error: "Internal error", message: error.message },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
@@ -67,6 +67,7 @@ module.exports = async (event, data) => {
|
|
|
67
67
|
LastUpdated: moment().valueOf(),
|
|
68
68
|
TrackedData: data.trackedData || {},
|
|
69
69
|
Site: job.site, // Store for site-specific queries
|
|
70
|
+
SystemType: data.systemType,
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
log(action, "ExternalEntityCreated", externalEntity, logId);
|
|
@@ -75,9 +76,10 @@ module.exports = async (event, data) => {
|
|
|
75
76
|
if (!job.history) job.history = [];
|
|
76
77
|
job.history.push({
|
|
77
78
|
timestamp: moment.utc().valueOf(),
|
|
78
|
-
|
|
79
|
+
EntryType: "ExternalIDSet",
|
|
79
80
|
externalId: data.externalId,
|
|
80
81
|
user,
|
|
82
|
+
systemType: data.systemType,
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
// 8. Update job with history and optionally update job number for system parity
|