@plusscommunities/pluss-maintenance-aws-forms 2.1.9 → 2.1.10
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/editNote.js +4 -2
- package/integration/IntegrationStrategy.js +15 -0
- package/integration/archibus/ArchibusStrategy.js +211 -112
- package/integration/index.js +3 -1
- package/jobChanged.js +59 -5
- package/package-lock.json +4 -4
- package/package.json +2 -2
- package/requests/getRequests.js +6 -0
- package/requests/updatePriority.js +46 -0
- package/updateData.js +4 -0
- package/values.config.a.js +1 -0
- package/values.config.default.js +1 -0
- package/values.config.forms.js +1 -0
- package/values.config.js +1 -0
package/editNote.js
CHANGED
|
@@ -24,7 +24,7 @@ module.exports.editNote = (event, context, callback) => {
|
|
|
24
24
|
}
|
|
25
25
|
switch (data.action) {
|
|
26
26
|
case "AddNote":
|
|
27
|
-
if (!data.note && !data.attachments) {
|
|
27
|
+
if (!data.note && !data.attachments && !data.images) {
|
|
28
28
|
return callback(
|
|
29
29
|
null,
|
|
30
30
|
generateJsonResponse(422, { error: { message: "Incomplete data" } })
|
|
@@ -40,7 +40,7 @@ module.exports.editNote = (event, context, callback) => {
|
|
|
40
40
|
}
|
|
41
41
|
break;
|
|
42
42
|
case "EditNote":
|
|
43
|
-
if ((!data.note && !data.attachments) || !data.noteId) {
|
|
43
|
+
if ((!data.note && !data.attachments && !data.images) || !data.noteId) {
|
|
44
44
|
return callback(
|
|
45
45
|
null,
|
|
46
46
|
generateJsonResponse(422, { error: { message: "Incomplete data" } })
|
|
@@ -76,6 +76,7 @@ module.exports.editNote = (event, context, callback) => {
|
|
|
76
76
|
User: user,
|
|
77
77
|
Note: data.note,
|
|
78
78
|
Attachments: data.attachments,
|
|
79
|
+
Images: data.images,
|
|
79
80
|
});
|
|
80
81
|
activityAction = values.activityAddMaintenanceNote;
|
|
81
82
|
break;
|
|
@@ -99,6 +100,7 @@ module.exports.editNote = (event, context, callback) => {
|
|
|
99
100
|
}
|
|
100
101
|
note.Note = data.note;
|
|
101
102
|
note.Attachments = data.attachments;
|
|
103
|
+
note.Images = data.images;
|
|
102
104
|
activityAction = values.activityEditMaintenanceNote;
|
|
103
105
|
break;
|
|
104
106
|
default:
|
|
@@ -26,6 +26,21 @@ class IntegrationStrategy {
|
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
// actions taken when a request's status has changed
|
|
30
|
+
onStatusChanged = async (request) => {
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// actions taken when a comment has been added to a request
|
|
35
|
+
onCommentAdded = async (request) => {
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// actions taken when a note has been added to a request
|
|
40
|
+
onNotesAdded = async (request) => {
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
|
|
29
44
|
// actions taken when a request is marked as completed
|
|
30
45
|
onCompleteRequest = async (request) => {
|
|
31
46
|
return null;
|
|
@@ -55,37 +55,40 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
55
55
|
* Creates a request from the Archibus system
|
|
56
56
|
*
|
|
57
57
|
* @param {Object} request - Request definition on Pluss
|
|
58
|
+
* @param {Object} mockResponse - Mock response from Archibus to simulate response
|
|
58
59
|
* @returns {Boolean} Whether the request was created on Archibus
|
|
59
60
|
*/
|
|
60
|
-
createRequest = async (request) => {
|
|
61
|
+
createRequest = async (request, mockResponse = null) => {
|
|
61
62
|
const logId = log("Archibus:CreateRequest", "Start", request);
|
|
62
63
|
try {
|
|
63
|
-
const response =
|
|
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
|
-
|
|
64
|
+
const response =
|
|
65
|
+
mockResponse ??
|
|
66
|
+
(await axios({
|
|
67
|
+
method: "PUT",
|
|
68
|
+
url: `${this.baseUrl}/createWorkRequest`,
|
|
69
|
+
timeout: 15000,
|
|
70
|
+
headers: {
|
|
71
|
+
[this.apiKeyHeader]: this.apiKey,
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
Host: this.host,
|
|
74
|
+
},
|
|
75
|
+
data: {
|
|
76
|
+
prob_type: "1.ON-SITE|1. MAINTENANCE",
|
|
77
|
+
requestor: "PLUSS",
|
|
78
|
+
description: `${request.title}${
|
|
79
|
+
_.isEmpty(request.description) ? "" : `\n\n${request.description}`
|
|
80
|
+
}${_.isEmpty(request.room) ? "" : `\n\nLocation: ${request.room}`}${
|
|
81
|
+
_.isEmpty(request.userName) ? "" : `\n\nName: ${request.userName}`
|
|
82
|
+
}${_.isEmpty(request.phone) ? "" : `\n\nPhone: ${request.phone}`}${
|
|
83
|
+
_.isEmpty(request.type) ? "" : `\n\nJob Type: ${request.type}`
|
|
84
|
+
}${
|
|
85
|
+
_.isEmpty(request.images)
|
|
86
|
+
? ""
|
|
87
|
+
: `\n\nImages: ${request.images.join("\n")}`
|
|
88
|
+
}`,
|
|
89
|
+
site_id: "2025", //TODO need to do site mapping 2025 is WooloowareShores in prod
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
89
92
|
log("Archibus:CreateRequest", "Response", response.data, logId);
|
|
90
93
|
|
|
91
94
|
// Save the ID to external entities for future reference
|
|
@@ -105,7 +108,7 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
105
108
|
});
|
|
106
109
|
|
|
107
110
|
// add images
|
|
108
|
-
if (!_.isEmpty(request.images)) {
|
|
111
|
+
if (!mockResponse && !_.isEmpty(request.images)) {
|
|
109
112
|
const imagePromises = [];
|
|
110
113
|
request.images.forEach((url) => {
|
|
111
114
|
imagePromises.push(this.addFileToRequest(response.data.wrId, url));
|
|
@@ -350,114 +353,210 @@ class ArchibusStrategy extends IntegrationStrategy {
|
|
|
350
353
|
};
|
|
351
354
|
|
|
352
355
|
/**
|
|
356
|
+
* Get Archibus Id of the request
|
|
353
357
|
*
|
|
354
358
|
* @param {Object} request - Request definition on Pluss
|
|
355
|
-
* @returns {
|
|
359
|
+
* @returns {Number} Id of the request on Archibus (null if not exists)
|
|
356
360
|
*/
|
|
357
|
-
|
|
358
|
-
const logId = log("Archibus:
|
|
359
|
-
|
|
361
|
+
getExternalId = async (request) => {
|
|
362
|
+
const logId = log("Archibus:GetExternalId", "Start", { Id: request.id });
|
|
363
|
+
|
|
364
|
+
// get external id
|
|
365
|
+
const externalEntityQuery = await indexQuery("externalentities", {
|
|
366
|
+
IndexName: "InternalIdIndex",
|
|
367
|
+
KeyConditionExpression:
|
|
368
|
+
"EntityType = :entityType AND InternalId = :internalId",
|
|
369
|
+
ExpressionAttributeValues: {
|
|
370
|
+
":entityType": this.getEntityType(),
|
|
371
|
+
":internalId": request.id,
|
|
372
|
+
},
|
|
360
373
|
});
|
|
361
|
-
try {
|
|
362
|
-
// get external id
|
|
363
|
-
const externalEntityQuery = await indexQuery("externalentities", {
|
|
364
|
-
IndexName: "InternalIdIndex",
|
|
365
|
-
KeyConditionExpression:
|
|
366
|
-
"EntityType = :entityType AND InternalId = :internalId",
|
|
367
|
-
ExpressionAttributeValues: {
|
|
368
|
-
":entityType": this.getEntityType(),
|
|
369
|
-
":internalId": request.id,
|
|
370
|
-
},
|
|
371
|
-
});
|
|
372
374
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
375
|
+
log(
|
|
376
|
+
"Archibus:GetExternalId",
|
|
377
|
+
"ExternalLength",
|
|
378
|
+
externalEntityQuery.Items.length,
|
|
379
|
+
logId
|
|
380
|
+
);
|
|
381
|
+
if (_.isEmpty(externalEntityQuery.Items)) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
382
384
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
+
const externalId = externalEntityQuery.Items[0].ExternalId;
|
|
386
|
+
log("Archibus:GetExternalId", "ExternalId", externalId, logId);
|
|
385
387
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
388
|
+
return externalId;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Get latest comment for a request
|
|
393
|
+
*
|
|
394
|
+
* @param {Object} request - Request definition on Pluss
|
|
395
|
+
* @param {String} entityKey - Request entity key (e.g. maintenancerequest)
|
|
396
|
+
* @returns {Object} Latest comment (null if not exists)
|
|
397
|
+
*/
|
|
398
|
+
getLatestComment = async (request, entityKey) => {
|
|
399
|
+
const logId = log("Archibus:GetLatestComment", "Start", { Id: request.id });
|
|
400
|
+
|
|
401
|
+
// get comments
|
|
402
|
+
const commentsQuery = {
|
|
403
|
+
IndexName: "CommentsEntityIdIndex",
|
|
404
|
+
KeyConditionExpression: "EntityId = :groupId",
|
|
405
|
+
ExpressionAttributeValues: {
|
|
406
|
+
":groupId": getRowId(request.id, entityKey),
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const commentsQueryRes = await indexQuery("comments", commentsQuery);
|
|
411
|
+
const comments = _.orderBy(commentsQueryRes.Items, "Timestamp", "desc");
|
|
412
|
+
log(
|
|
413
|
+
"Archibus:GetLatestComment",
|
|
414
|
+
`CommentsLength - ${entityKey}`,
|
|
415
|
+
comments.length,
|
|
416
|
+
logId
|
|
417
|
+
);
|
|
394
418
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
log("Archibus:OnComplete", "CommentsLength", comments.length, logId);
|
|
419
|
+
return comments.length > 0 ? comments[0] : null;
|
|
420
|
+
};
|
|
398
421
|
|
|
399
|
-
|
|
422
|
+
/**
|
|
423
|
+
* Perform actions when a task's status has changed
|
|
424
|
+
*
|
|
425
|
+
* @param {Object} request - Request definition on Pluss
|
|
426
|
+
* @returns {Boolean} Represents whether the actions were successful
|
|
427
|
+
*/
|
|
428
|
+
onStatusChanged = async (request) => {
|
|
429
|
+
const logId = log("Archibus:OnStatusChanged", "Start", { Id: request.id });
|
|
400
430
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
promises.push(this.addCommentToRequest(externalId, historyComment));
|
|
414
|
-
}
|
|
431
|
+
try {
|
|
432
|
+
const externalId = await this.getExternalId(request);
|
|
433
|
+
if (_.isNil(externalId)) return true;
|
|
434
|
+
|
|
435
|
+
const statues = _.orderBy(
|
|
436
|
+
(request.history ?? []).filter(
|
|
437
|
+
(entry) => entry.EntryType !== "assignment"
|
|
438
|
+
),
|
|
439
|
+
"timestamp",
|
|
440
|
+
"desc"
|
|
441
|
+
);
|
|
442
|
+
const latest = statues.length > 0 ? statues[0] : null;
|
|
415
443
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const user = entry.User ? entry.User.displayName : "Unknown User";
|
|
424
|
-
const note = entry.Note ? `Note: ${entry.Note}` : "No Note";
|
|
425
|
-
if (!_.isEmpty(entry.Attachments)) {
|
|
426
|
-
entry.Attachments.forEach((att) => {
|
|
427
|
-
promises.push(this.addFileToRequest(externalId, att.Source));
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
const attachments =
|
|
431
|
-
entry.Attachments && entry.Attachments.length > 0
|
|
432
|
-
? `Attachments: ${entry.Attachments.map(
|
|
433
|
-
(att) => `${att.Title} (${att.Source})`
|
|
434
|
-
).join(", ")}`
|
|
435
|
-
: "No Attachments";
|
|
436
|
-
return `${time} by ${user}\n${note}\n${attachments}`;
|
|
437
|
-
}).join("\n\n");
|
|
438
|
-
// save comment
|
|
439
|
-
promises.push(this.addCommentToRequest(externalId, notesComment));
|
|
444
|
+
if (latest) {
|
|
445
|
+
const time = moment(Number.parseFloat(latest.timestamp + "")).format(
|
|
446
|
+
"D MMM YYYY HH:mm:ss"
|
|
447
|
+
);
|
|
448
|
+
const user = latest.user ? ` by ${latest.user.displayName}` : "";
|
|
449
|
+
const comment = `${time}: Marked ${latest.status}${user}`;
|
|
450
|
+
await this.addCommentToRequest(externalId, comment);
|
|
440
451
|
}
|
|
441
452
|
|
|
442
|
-
|
|
443
|
-
|
|
453
|
+
return true;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
log("Archibus:OnStatusChanged", "Error", error.toString(), logId);
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Perform actions when a a comment has been added to a task
|
|
462
|
+
*
|
|
463
|
+
* @param {Object} request - Request definition on Pluss
|
|
464
|
+
* @returns {Boolean} Represents whether the actions were successful
|
|
465
|
+
*/
|
|
466
|
+
onCommentAdded = async (request) => {
|
|
467
|
+
const logId = log("Archibus:OnCommentAdded", "Start", {
|
|
468
|
+
Id: request.id,
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
try {
|
|
472
|
+
const externalId = await this.getExternalId(request);
|
|
473
|
+
if (_.isNil(externalId)) return true;
|
|
474
|
+
|
|
475
|
+
let comment = await this.getLatestComment(request, values.serviceKey);
|
|
476
|
+
if (!comment)
|
|
477
|
+
comment = await this.getLatestComment(request, values.entityKey);
|
|
478
|
+
|
|
479
|
+
if (comment) {
|
|
444
480
|
const commentText = `${comment.User.displayName}:\n\n${
|
|
445
481
|
comment.Comment
|
|
446
482
|
}${!_.isEmpty(comment.Image) ? `\n\nImage: ${comment.Image}` : ""}}`;
|
|
447
483
|
const commentTime = moment(comment.Timestamp);
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
);
|
|
451
|
-
});
|
|
484
|
+
await this.addCommentToRequest(externalId, commentText, commentTime);
|
|
485
|
+
}
|
|
452
486
|
|
|
453
|
-
|
|
487
|
+
return true;
|
|
488
|
+
} catch (error) {
|
|
489
|
+
log("Archibus:OnCommentAdded", "Error", error.toString(), logId);
|
|
490
|
+
}
|
|
491
|
+
return false;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Perform actions when a note has been added to a task
|
|
496
|
+
*
|
|
497
|
+
* @param {Object} request - Request definition on Pluss
|
|
498
|
+
* @returns {Boolean} Represents whether the actions were successful
|
|
499
|
+
*/
|
|
500
|
+
onNotesAdded = async (request) => {
|
|
501
|
+
const logId = log("Archibus:OnNotesAdded", "Start", { Id: request.id });
|
|
502
|
+
|
|
503
|
+
try {
|
|
504
|
+
const externalId = await this.getExternalId(request);
|
|
505
|
+
if (_.isNil(externalId)) return true;
|
|
506
|
+
|
|
507
|
+
const notes = _.orderBy(request.Notes ?? [], "Timestamp", "desc");
|
|
508
|
+
const latest = notes.length > 0 ? notes[0] : null;
|
|
509
|
+
|
|
510
|
+
if (latest) {
|
|
511
|
+
const promises = [];
|
|
512
|
+
|
|
513
|
+
const time = moment(Number.parseFloat(latest.Timestamp + "")).format(
|
|
514
|
+
"YYYY-MM-DD HH:mm:ss"
|
|
515
|
+
);
|
|
516
|
+
const user = latest.User ? latest.User.displayName : "Unknown User";
|
|
517
|
+
const note = latest.Note ? `Note: ${latest.Note}` : "No Note";
|
|
518
|
+
if (!_.isEmpty(latest.Attachments)) {
|
|
519
|
+
latest.Attachments.forEach((att) => {
|
|
520
|
+
promises.push(this.addFileToRequest(externalId, att.Source));
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
const attachments =
|
|
524
|
+
latest.Attachments && latest.Attachments.length > 0
|
|
525
|
+
? `Attachments: ${latest.Attachments.map(
|
|
526
|
+
(att) => `${att.Title} (${att.Source})`
|
|
527
|
+
).join(", ")}`
|
|
528
|
+
: "No Attachments";
|
|
529
|
+
if (!_.isEmpty(latest.Images)) {
|
|
530
|
+
latest.Images.forEach((image) => {
|
|
531
|
+
promises.push(this.addFileToRequest(externalId, image));
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
const images =
|
|
535
|
+
latest.Images && latest.Images.length > 0
|
|
536
|
+
? `Images: ${latest.Images.map((image) => image).join(", ")}`
|
|
537
|
+
: "No Images";
|
|
538
|
+
const comment = `${time} by ${user}\n${note}\n${attachments}\n${images}`;
|
|
539
|
+
promises.push(this.addCommentToRequest(externalId, comment));
|
|
540
|
+
|
|
541
|
+
await Promise.all(promises);
|
|
542
|
+
}
|
|
454
543
|
|
|
455
544
|
return true;
|
|
456
545
|
} catch (error) {
|
|
457
|
-
log("Archibus:
|
|
546
|
+
log("Archibus:OnNotesAdded", "Error", error.toString(), logId);
|
|
458
547
|
}
|
|
459
548
|
return false;
|
|
460
549
|
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Perform completion actions when a task is completed
|
|
553
|
+
*
|
|
554
|
+
* @param {Object} request - Request definition on Pluss
|
|
555
|
+
* @returns {Boolean} Represents whether the actions were successful
|
|
556
|
+
*/
|
|
557
|
+
onCompleteRequest = async (request) => {
|
|
558
|
+
return true;
|
|
559
|
+
};
|
|
461
560
|
}
|
|
462
561
|
|
|
463
562
|
module.exports = ArchibusStrategy;
|
package/integration/index.js
CHANGED
package/jobChanged.js
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
+
const moment = require("moment");
|
|
2
|
+
const _ = require("lodash");
|
|
1
3
|
const { Marshaller } = require("@aws/dynamodb-auto-marshaller");
|
|
2
4
|
const config = require("./config.json");
|
|
3
5
|
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
4
6
|
const logUpdate = require("@plusscommunities/pluss-core-aws/db/strings/logUpdate");
|
|
5
7
|
const { getStrategy } = require("./integration");
|
|
6
8
|
const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
9
|
+
const triggerAutomatedAction = require("@plusscommunities/pluss-core-aws/helper/triggerAutomatedAction");
|
|
7
10
|
const { values } = require("./values.config");
|
|
8
11
|
|
|
9
12
|
const marshaller = new Marshaller();
|
|
10
13
|
|
|
11
14
|
const pushRequestToIntegration = async (request) => {
|
|
12
15
|
const integrationStrategy = await getStrategy(request.site);
|
|
16
|
+
// const mockRes = {
|
|
17
|
+
// data: { wrId: moment().valueOf() },
|
|
18
|
+
// };
|
|
19
|
+
// await integrationStrategy.createRequest(request, mockRes);
|
|
13
20
|
await integrationStrategy.createRequest(request);
|
|
14
21
|
};
|
|
15
22
|
|
|
16
|
-
const
|
|
23
|
+
const onStatusChanged = async (request) => {
|
|
17
24
|
const integrationStrategy = await getStrategy(request.site);
|
|
18
|
-
await integrationStrategy.
|
|
25
|
+
await integrationStrategy.onStatusChanged(request);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const onCommentAdded = async (request) => {
|
|
29
|
+
const integrationStrategy = await getStrategy(request.site);
|
|
30
|
+
await integrationStrategy.onCommentAdded(request);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const onNotesAdded = async (request) => {
|
|
34
|
+
const integrationStrategy = await getStrategy(request.site);
|
|
35
|
+
await integrationStrategy.onNotesAdded(request);
|
|
19
36
|
};
|
|
20
37
|
|
|
21
38
|
/**
|
|
@@ -32,9 +49,45 @@ const checkIntegrationActions = async (request, prevRequest) => {
|
|
|
32
49
|
await pushRequestToIntegration(request);
|
|
33
50
|
}
|
|
34
51
|
|
|
35
|
-
if (request.status
|
|
36
|
-
log("checkIntegrationActions", "
|
|
37
|
-
|
|
52
|
+
if (request.status !== prevRequest.status) {
|
|
53
|
+
log("checkIntegrationActions", "StatusChanaged", {
|
|
54
|
+
new: request.status,
|
|
55
|
+
old: prevRequest.status,
|
|
56
|
+
});
|
|
57
|
+
await onStatusChanged(request);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (request.commentCount > prevRequest.commentCount) {
|
|
61
|
+
log("checkIntegrationActions", "CommentCountChanged", {
|
|
62
|
+
new: request.commentCount,
|
|
63
|
+
old: prevRequest.commentCount,
|
|
64
|
+
});
|
|
65
|
+
await onCommentAdded(request);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ((request.Notes ?? []).length > (prevRequest.Notes ?? []).length) {
|
|
69
|
+
log("checkIntegrationActions", "NotesAdded", {
|
|
70
|
+
new: (request.Notes ?? []).length,
|
|
71
|
+
old: (prevRequest.Notes ?? []).length,
|
|
72
|
+
});
|
|
73
|
+
await onNotesAdded(request);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const checkAutomatedActions = async (request, prevRequest) => {
|
|
78
|
+
if (request.status !== prevRequest.status) {
|
|
79
|
+
log("checkAutomatedActions", "StatusChanaged", {
|
|
80
|
+
new: request.status,
|
|
81
|
+
old: prevRequest.status,
|
|
82
|
+
});
|
|
83
|
+
await triggerAutomatedAction(
|
|
84
|
+
request.site,
|
|
85
|
+
values.triggerMaintenanceStatusChanged,
|
|
86
|
+
{
|
|
87
|
+
JobNumber: request.jobNo,
|
|
88
|
+
status: request.status,
|
|
89
|
+
}
|
|
90
|
+
);
|
|
38
91
|
}
|
|
39
92
|
};
|
|
40
93
|
|
|
@@ -59,6 +112,7 @@ module.exports.jobChanged = (event, context, callback) => {
|
|
|
59
112
|
console.log("Old record: ", JSON.stringify(previousData));
|
|
60
113
|
|
|
61
114
|
checkIntegrationActions(data, previousData);
|
|
115
|
+
checkAutomatedActions(data, previousData);
|
|
62
116
|
|
|
63
117
|
site = data.site;
|
|
64
118
|
} else if (record.eventName == "REMOVE") {
|
package/package-lock.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-maintenance-aws-forms",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"lockfileVersion": 1,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"dependencies": {
|
|
@@ -1468,9 +1468,9 @@
|
|
|
1468
1468
|
}
|
|
1469
1469
|
},
|
|
1470
1470
|
"@plusscommunities/pluss-core-aws": {
|
|
1471
|
-
"version": "2.0.
|
|
1472
|
-
"resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.
|
|
1473
|
-
"integrity": "sha512-
|
|
1471
|
+
"version": "2.0.20-beta.1",
|
|
1472
|
+
"resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.20-beta.1.tgz",
|
|
1473
|
+
"integrity": "sha512-9PEkZ3UPiSK84d+fsr0jkNhHfZ6FuvY1ujjdmsULDi7XS2eUCBA770BRBPPoRiXaaGr0RJ1euBVrZmmqVvfxRw==",
|
|
1474
1474
|
"requires": {
|
|
1475
1475
|
"@aws/dynamodb-auto-marshaller": "^0.7.1",
|
|
1476
1476
|
"amazon-cognito-identity-js": "^2.0.19",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-maintenance-aws-forms",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "Extension package to enable maintenance on Pluss Communities Platform",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"gc": "node ../../tools/gc ./",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@aws/dynamodb-auto-marshaller": "^0.7.1",
|
|
27
|
-
"@plusscommunities/pluss-core-aws": "2.0.
|
|
27
|
+
"@plusscommunities/pluss-core-aws": "2.0.20-beta.1",
|
|
28
28
|
"amazon-cognito-identity-js": "^2.0.19",
|
|
29
29
|
"aws-sdk": "^2.1591.0",
|
|
30
30
|
"axios": "^1.6.8",
|
package/requests/getRequests.js
CHANGED
|
@@ -81,6 +81,12 @@ module.exports = async (event) => {
|
|
|
81
81
|
log("getRequests", "FilteredOnStatus", jobs.length, logId);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
// filter on priority
|
|
85
|
+
if (qParams.priority) {
|
|
86
|
+
jobs = jobs.filter((j) => qParams.priority.includes(j.priority));
|
|
87
|
+
log("getRequests", "FilterOnPriority", jobs.length, logId);
|
|
88
|
+
}
|
|
89
|
+
|
|
84
90
|
// filter on type
|
|
85
91
|
if (qParams.type) {
|
|
86
92
|
jobs = jobs.filter((j) => qParams.type.includes(j.type));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const validateMasterAuth = require("@plusscommunities/pluss-core-aws/helper/auth/validateMasterAuth");
|
|
2
|
+
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
3
|
+
const editMaintenanceJob = require("../db/maintenance/editMaintenanceJob");
|
|
4
|
+
const isValidAssignee = require("./helper/isValidAssignee");
|
|
5
|
+
const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
6
|
+
const { values } = require("../values.config");
|
|
7
|
+
|
|
8
|
+
module.exports = async (event, data) => {
|
|
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
|
+
|
|
17
|
+
const job = await getRef(values.tableNameMaintenance, "id", data.id);
|
|
18
|
+
log("updatePriority", "job", job, logId);
|
|
19
|
+
log("updatePriority", "site", job.site, logId);
|
|
20
|
+
|
|
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
|
+
|
|
41
|
+
job.priority = data.priority;
|
|
42
|
+
const result = await editMaintenanceJob(job);
|
|
43
|
+
|
|
44
|
+
log("updatePriority", "result", result, logId);
|
|
45
|
+
return { status: 200, data: { job: result } };
|
|
46
|
+
};
|
package/updateData.js
CHANGED
|
@@ -3,6 +3,7 @@ const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/ge
|
|
|
3
3
|
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
4
4
|
const config = require("./config.json");
|
|
5
5
|
const assignRequest = require("./requests/assignRequest");
|
|
6
|
+
const updatePriority = require("./requests/updatePriority");
|
|
6
7
|
|
|
7
8
|
module.exports.updateData = async (event, context, callback) => {
|
|
8
9
|
init(config);
|
|
@@ -17,6 +18,9 @@ module.exports.updateData = async (event, context, callback) => {
|
|
|
17
18
|
case "assign":
|
|
18
19
|
response = await assignRequest(event, data);
|
|
19
20
|
break;
|
|
21
|
+
case "priority":
|
|
22
|
+
response = await updatePriority(event, data);
|
|
23
|
+
break;
|
|
20
24
|
default:
|
|
21
25
|
break;
|
|
22
26
|
}
|
package/values.config.a.js
CHANGED
|
@@ -22,5 +22,6 @@ const values = {
|
|
|
22
22
|
activityDeleteMaintenanceNote: "DeleteMaintenanceNoteA",
|
|
23
23
|
activityEditMaintenanceNote: "EditMaintenanceNoteA",
|
|
24
24
|
textJobEmailTitle: "Service Request",
|
|
25
|
+
triggerMaintenanceStatusChanged: "MaintenanceStatusChangedA",
|
|
25
26
|
};
|
|
26
27
|
exports.values = values;
|
package/values.config.default.js
CHANGED
package/values.config.forms.js
CHANGED
package/values.config.js
CHANGED