@plusscommunities/pluss-maintenance-aws-forms 2.1.12 → 2.1.14
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.
|
@@ -9,6 +9,7 @@ const updateRef = require("@plusscommunities/pluss-core-aws/db/common/updateRef"
|
|
|
9
9
|
const indexQuery = require("@plusscommunities/pluss-core-aws/db/common/indexQuery");
|
|
10
10
|
const publishNotifications = require("@plusscommunities/pluss-core-aws/db/notifications/publishNotifications");
|
|
11
11
|
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
12
|
+
const getString = require("@plusscommunities/pluss-core-aws/db/strings/getString");
|
|
12
13
|
const { values } = require("../../values.config");
|
|
13
14
|
|
|
14
15
|
class ArchibusStrategy extends IntegrationStrategy {
|
|
@@ -23,6 +24,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
23
24
|
|
|
24
25
|
this.statusMap = config.StatusMap;
|
|
25
26
|
this.siteMap = config.SiteMap ?? {};
|
|
27
|
+
this.buildingCodes = [];
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -61,44 +63,62 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
61
63
|
*/
|
|
62
64
|
createRequest = async (request, mockResponse = null) => {
|
|
63
65
|
const logId = log("Archibus:CreateRequest", "Start", request);
|
|
64
|
-
|
|
66
|
+
|
|
67
|
+
let siteId = this.siteMap[request.site];
|
|
68
|
+
let buildingCode = null;
|
|
69
|
+
if (request.room) {
|
|
70
|
+
if (this.buildingCodes.length === 0) {
|
|
71
|
+
this.buildingCodes = await getString(
|
|
72
|
+
getRowId(request.site, `${values.serviceKey}buildingcodes`),
|
|
73
|
+
"plussSpace"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const building = this.buildingCodes.find((b) => {
|
|
77
|
+
const address = request.room.toLowerCase();
|
|
78
|
+
const search = b.SearchString.toLowerCase();
|
|
79
|
+
const name = b.BuildingName.toLowerCase();
|
|
80
|
+
return address.includes(search) || address.includes(name);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (building?.SiteCode) siteId = building.SiteCode.toString();
|
|
84
|
+
buildingCode = building?.BuildingCode;
|
|
85
|
+
}
|
|
65
86
|
if (!siteId) return false;
|
|
66
87
|
|
|
67
88
|
try {
|
|
89
|
+
const data = {
|
|
90
|
+
prob_type: "1.ON-SITE|1. MAINTENANCE",
|
|
91
|
+
requestor: "PLUSS",
|
|
92
|
+
description: `${request.title}${
|
|
93
|
+
_.isEmpty(request.description) ? "" : `\n\n${request.description}`
|
|
94
|
+
}${_.isEmpty(request.room) ? "" : `\n\nLocation: ${request.room}`}${
|
|
95
|
+
_.isEmpty(request.userName) ? "" : `\n\nName: ${request.userName}`
|
|
96
|
+
}${_.isEmpty(request.phone) ? "" : `\n\nPhone: ${request.phone}`}${
|
|
97
|
+
_.isEmpty(request.type) ? "" : `\n\nJob Type: ${request.type}`
|
|
98
|
+
}${
|
|
99
|
+
_.isEmpty(request.images)
|
|
100
|
+
? ""
|
|
101
|
+
: `\n\nImages: ${request.images.join("\n")}`
|
|
102
|
+
}`,
|
|
103
|
+
site_id: siteId,
|
|
104
|
+
};
|
|
105
|
+
if (buildingCode) data.bl_id = buildingCode;
|
|
106
|
+
log("Archibus:CreateRequest", "Request", data, logId);
|
|
107
|
+
|
|
68
108
|
const response =
|
|
69
109
|
mockResponse ??
|
|
70
110
|
(await axios({
|
|
71
111
|
method: "PUT",
|
|
72
112
|
url: `${this.baseUrl}/createWorkRequest`,
|
|
73
|
-
timeout:
|
|
113
|
+
timeout: 30000,
|
|
74
114
|
headers: {
|
|
75
115
|
[this.apiKeyHeader]: this.apiKey,
|
|
76
116
|
"Content-Type": "application/json",
|
|
77
117
|
Host: this.host,
|
|
78
118
|
},
|
|
79
|
-
data
|
|
80
|
-
prob_type: "1.ON-SITE|1. MAINTENANCE",
|
|
81
|
-
requestor: "PLUSS",
|
|
82
|
-
description: `${request.title}${
|
|
83
|
-
_.isEmpty(request.description) ? "" : `\n\n${request.description}`
|
|
84
|
-
}${_.isEmpty(request.room) ? "" : `\n\nLocation: ${request.room}`}${
|
|
85
|
-
_.isEmpty(request.userName) ? "" : `\n\nName: ${request.userName}`
|
|
86
|
-
}${_.isEmpty(request.phone) ? "" : `\n\nPhone: ${request.phone}`}${
|
|
87
|
-
_.isEmpty(request.type) ? "" : `\n\nJob Type: ${request.type}`
|
|
88
|
-
}${
|
|
89
|
-
_.isEmpty(request.images)
|
|
90
|
-
? ""
|
|
91
|
-
: `\n\nImages: ${request.images.join("\n")}`
|
|
92
|
-
}`,
|
|
93
|
-
site_id: siteId,
|
|
94
|
-
},
|
|
119
|
+
data,
|
|
95
120
|
}));
|
|
96
|
-
log(
|
|
97
|
-
"Archibus:CreateRequest",
|
|
98
|
-
"Response",
|
|
99
|
-
{ data: response.data, siteId },
|
|
100
|
-
logId
|
|
101
|
-
);
|
|
121
|
+
log("Archibus:CreateRequest", "Response", response.data, logId);
|
|
102
122
|
|
|
103
123
|
// Save the ID to external entities for future reference
|
|
104
124
|
await updateRef("externalentities", {
|
|
@@ -144,7 +164,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
144
164
|
const response = await axios({
|
|
145
165
|
method: "GET",
|
|
146
166
|
url: `${this.baseUrl}/getWorkRequest/${externalId}`,
|
|
147
|
-
timeout:
|
|
167
|
+
timeout: 30000,
|
|
148
168
|
headers: {
|
|
149
169
|
[this.apiKeyHeader]: this.apiKey,
|
|
150
170
|
"Content-Type": "application/json",
|
|
@@ -275,7 +295,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
275
295
|
method: "POST",
|
|
276
296
|
url: `${this.baseUrl}/addCommentsToWRSteps`,
|
|
277
297
|
data: postData,
|
|
278
|
-
timeout:
|
|
298
|
+
timeout: 30000,
|
|
279
299
|
headers: {
|
|
280
300
|
[this.apiKeyHeader]: this.apiKey,
|
|
281
301
|
"Content-Type": "application/json",
|
package/package-lock.json
CHANGED
package/package.json
CHANGED