@plusscommunities/pluss-maintenance-aws-forms 2.1.22 → 2.1.23
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
|
}
|
|
@@ -139,7 +139,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
139
139
|
if (!updatedJob.history) updatedJob.history = [];
|
|
140
140
|
updatedJob.history.push({
|
|
141
141
|
timestamp: moment.utc().valueOf(),
|
|
142
|
-
|
|
142
|
+
EntryType: "ExternalIDSet",
|
|
143
143
|
externalId: response.data.wrId,
|
|
144
144
|
user: {
|
|
145
145
|
displayName: "Archibus Integration",
|
|
@@ -176,7 +176,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
176
176
|
if (!failedJob.history) failedJob.history = [];
|
|
177
177
|
failedJob.history.push({
|
|
178
178
|
timestamp: moment.utc().valueOf(),
|
|
179
|
-
|
|
179
|
+
EntryType: "ExternalIDSetFailed",
|
|
180
180
|
user: {
|
|
181
181
|
displayName: "Archibus Integration",
|
|
182
182
|
id: "system",
|
|
@@ -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,171 @@
|
|
|
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
|
+
// Query externalentities table for this request
|
|
104
|
+
// Check both SeeStuff and Archibus entity types
|
|
105
|
+
const entityTypes = [
|
|
106
|
+
`${values.serviceKey}_SeeStuff`,
|
|
107
|
+
`${values.serviceKey}_Archibus`,
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
log("getExternalSync", "CheckingEntityTypes", entityTypes, logId);
|
|
111
|
+
|
|
112
|
+
let externalSync = null;
|
|
113
|
+
|
|
114
|
+
// Check each external system type
|
|
115
|
+
for (const entityType of entityTypes) {
|
|
116
|
+
const query = await indexQuery("externalentities", {
|
|
117
|
+
IndexName: "InternalIdIndex",
|
|
118
|
+
KeyConditionExpression:
|
|
119
|
+
"EntityType = :entityType AND InternalId = :internalId",
|
|
120
|
+
ExpressionAttributeValues: {
|
|
121
|
+
":entityType": entityType,
|
|
122
|
+
":internalId": request.id,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
log(
|
|
127
|
+
"getExternalSync",
|
|
128
|
+
`${entityType}_Results`,
|
|
129
|
+
query.Items.length,
|
|
130
|
+
logId
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (query.Items && query.Items.length > 0) {
|
|
134
|
+
const item = query.Items[0];
|
|
135
|
+
// Extract system name from entity type (e.g., "maintenance_SeeStuff" -> "SeeStuff")
|
|
136
|
+
const systemName = entityType.split("_")[1];
|
|
137
|
+
|
|
138
|
+
externalSync = {
|
|
139
|
+
externalSystem: systemName,
|
|
140
|
+
externalId: item.ExternalId,
|
|
141
|
+
syncedAt: item.LastUpdated,
|
|
142
|
+
trackedData: item.TrackedData || {},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
log("getExternalSync", "FoundSync", externalSync, logId);
|
|
146
|
+
break; // Stop after finding first match
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// If no external sync found, return 404
|
|
151
|
+
if (!externalSync) {
|
|
152
|
+
log("getExternalSync", "NoSyncFound", { id: data.id }, logId);
|
|
153
|
+
return {
|
|
154
|
+
status: 404,
|
|
155
|
+
data: { error: "No external sync found" },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
log("getExternalSync", "Success", externalSync, logId);
|
|
160
|
+
return {
|
|
161
|
+
status: 200,
|
|
162
|
+
data: externalSync,
|
|
163
|
+
};
|
|
164
|
+
} catch (error) {
|
|
165
|
+
log("getExternalSync", "InternalError", error.toString(), logId);
|
|
166
|
+
return {
|
|
167
|
+
status: 500,
|
|
168
|
+
data: { error: "Internal error", message: error.message },
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|