@plusscommunities/pluss-maintenance-aws-forms 2.1.9 → 2.1.12-beta.0

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 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;
@@ -22,6 +22,7 @@ class ArchibusStrategy extends IntegrationStrategy {
22
22
  this.host = url.host;
23
23
 
24
24
  this.statusMap = config.StatusMap;
25
+ this.siteMap = config.SiteMap ?? {};
25
26
  }
26
27
 
27
28
  /**
@@ -55,38 +56,49 @@ class ArchibusStrategy extends IntegrationStrategy {
55
56
  * Creates a request from the Archibus system
56
57
  *
57
58
  * @param {Object} request - Request definition on Pluss
59
+ * @param {Object} mockResponse - Mock response from Archibus to simulate response
58
60
  * @returns {Boolean} Whether the request was created on Archibus
59
61
  */
60
- createRequest = async (request) => {
62
+ createRequest = async (request, mockResponse = null) => {
61
63
  const logId = log("Archibus:CreateRequest", "Start", request);
64
+ const siteId = this.siteMap[request.site];
65
+ if (!siteId) return false;
66
+
62
67
  try {
63
- const response = await axios({
64
- method: "PUT",
65
- url: `${this.baseUrl}/createWorkRequest`,
66
- timeout: 15000,
67
- headers: {
68
- [this.apiKeyHeader]: this.apiKey,
69
- "Content-Type": "application/json",
70
- Host: this.host,
71
- },
72
- data: {
73
- prob_type: "1.ON-SITE|1. MAINTENANCE",
74
- requestor: "PLUSS",
75
- description: `${request.title}${
76
- _.isEmpty(request.description) ? "" : `\n\n${request.description}`
77
- }${_.isEmpty(request.room) ? "" : `\n\nLocation: ${request.room}`}${
78
- _.isEmpty(request.userName) ? "" : `\n\nName: ${request.userName}`
79
- }${_.isEmpty(request.phone) ? "" : `\n\nPhone: ${request.phone}`}${
80
- _.isEmpty(request.type) ? "" : `\n\nJob Type: ${request.type}`
81
- }${
82
- _.isEmpty(request.images)
83
- ? ""
84
- : `\n\nImages: ${request.images.join("\n")}`
85
- }`,
86
- site_id: "2025", //TODO need to do site mapping 2025 is WooloowareShores in prod
87
- },
88
- });
89
- log("Archibus:CreateRequest", "Response", response.data, logId);
68
+ const response =
69
+ mockResponse ??
70
+ (await axios({
71
+ method: "PUT",
72
+ url: `${this.baseUrl}/createWorkRequest`,
73
+ timeout: 15000,
74
+ headers: {
75
+ [this.apiKeyHeader]: this.apiKey,
76
+ "Content-Type": "application/json",
77
+ Host: this.host,
78
+ },
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
+ },
95
+ }));
96
+ log(
97
+ "Archibus:CreateRequest",
98
+ "Response",
99
+ { data: response.data, siteId },
100
+ logId
101
+ );
90
102
 
91
103
  // Save the ID to external entities for future reference
92
104
  await updateRef("externalentities", {
@@ -105,7 +117,7 @@ class ArchibusStrategy extends IntegrationStrategy {
105
117
  });
106
118
 
107
119
  // add images
108
- if (!_.isEmpty(request.images)) {
120
+ if (!mockResponse && !_.isEmpty(request.images)) {
109
121
  const imagePromises = [];
110
122
  request.images.forEach((url) => {
111
123
  imagePromises.push(this.addFileToRequest(response.data.wrId, url));
@@ -350,114 +362,210 @@ class ArchibusStrategy extends IntegrationStrategy {
350
362
  };
351
363
 
352
364
  /**
365
+ * Get Archibus Id of the request
353
366
  *
354
367
  * @param {Object} request - Request definition on Pluss
355
- * @returns {Boolean} Represents whether the actions were successful
368
+ * @returns {Number} Id of the request on Archibus (null if not exists)
356
369
  */
357
- onCompleteRequest = async (request) => {
358
- const logId = log("Archibus:OnComplete", "Start", {
359
- Id: request.id,
370
+ getExternalId = async (request) => {
371
+ const logId = log("Archibus:GetExternalId", "Start", { Id: request.id });
372
+
373
+ // get external id
374
+ const externalEntityQuery = await indexQuery("externalentities", {
375
+ IndexName: "InternalIdIndex",
376
+ KeyConditionExpression:
377
+ "EntityType = :entityType AND InternalId = :internalId",
378
+ ExpressionAttributeValues: {
379
+ ":entityType": this.getEntityType(),
380
+ ":internalId": request.id,
381
+ },
360
382
  });
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
383
 
373
- log(
374
- "Archibus:OnComplete",
375
- "ExternalLength",
376
- externalEntityQuery.Items.length,
377
- logId
378
- );
379
- if (_.isEmpty(externalEntityQuery.Items)) {
380
- return true;
381
- }
384
+ log(
385
+ "Archibus:GetExternalId",
386
+ "ExternalLength",
387
+ externalEntityQuery.Items.length,
388
+ logId
389
+ );
390
+ if (_.isEmpty(externalEntityQuery.Items)) {
391
+ return null;
392
+ }
382
393
 
383
- const externalId = externalEntityQuery.Items[0].ExternalId;
384
- log("Archibus:OnComplete", "ExternalId", externalId, logId);
394
+ const externalId = externalEntityQuery.Items[0].ExternalId;
395
+ log("Archibus:GetExternalId", "ExternalId", externalId, logId);
385
396
 
386
- // get comments
387
- const commentsQuery = {
388
- IndexName: "CommentsEntityIdIndex",
389
- KeyConditionExpression: "EntityId = :groupId",
390
- ExpressionAttributeValues: {
391
- ":groupId": getRowId(request.id, values.serviceKey),
392
- },
393
- };
397
+ return externalId;
398
+ };
394
399
 
395
- const commentsQueryRes = await indexQuery("comments", commentsQuery);
396
- const comments = commentsQueryRes.Items;
397
- log("Archibus:OnComplete", "CommentsLength", comments.length, logId);
400
+ /**
401
+ * Get latest comment for a request
402
+ *
403
+ * @param {Object} request - Request definition on Pluss
404
+ * @param {String} entityKey - Request entity key (e.g. maintenancerequest)
405
+ * @returns {Object} Latest comment (null if not exists)
406
+ */
407
+ getLatestComment = async (request, entityKey) => {
408
+ const logId = log("Archibus:GetLatestComment", "Start", { Id: request.id });
409
+
410
+ // get comments
411
+ const commentsQuery = {
412
+ IndexName: "CommentsEntityIdIndex",
413
+ KeyConditionExpression: "EntityId = :groupId",
414
+ ExpressionAttributeValues: {
415
+ ":groupId": getRowId(request.id, entityKey),
416
+ },
417
+ };
418
+
419
+ const commentsQueryRes = await indexQuery("comments", commentsQuery);
420
+ const comments = _.orderBy(commentsQueryRes.Items, "Timestamp", "desc");
421
+ log(
422
+ "Archibus:GetLatestComment",
423
+ `CommentsLength - ${entityKey}`,
424
+ comments.length,
425
+ logId
426
+ );
398
427
 
399
- const promises = [];
428
+ return comments.length > 0 ? comments[0] : null;
429
+ };
400
430
 
401
- // save history as a comment
402
- if (!_.isEmpty(request.history)) {
403
- const historyComment = _.map(request.history, (entry) => {
404
- if (entry.EntryType === "assignment") {
405
- return "";
406
- }
407
- const time = moment(Number.parseFloat(entry.timestamp + "")).format(
408
- "D MMM YYYY HH:mm:ss"
409
- );
410
- const user = entry.user ? ` by ${entry.user.displayName}` : "";
411
- return `${time}: Marked ${entry.status}${user}`;
412
- }).join("\n");
413
- promises.push(this.addCommentToRequest(externalId, historyComment));
414
- }
431
+ /**
432
+ * Perform actions when a task's status has changed
433
+ *
434
+ * @param {Object} request - Request definition on Pluss
435
+ * @returns {Boolean} Represents whether the actions were successful
436
+ */
437
+ onStatusChanged = async (request) => {
438
+ const logId = log("Archibus:OnStatusChanged", "Start", { Id: request.id });
415
439
 
416
- // save history as a comment
417
- if (!_.isEmpty(request.Notes)) {
418
- // format comment to save
419
- const notesComment = _.map(request.Notes, (entry) => {
420
- const time = moment(Number.parseFloat(entry.Timestamp + "")).format(
421
- "YYYY-MM-DD HH:mm:ss"
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));
440
+ try {
441
+ const externalId = await this.getExternalId(request);
442
+ if (_.isNil(externalId)) return true;
443
+
444
+ const statues = _.orderBy(
445
+ (request.history ?? []).filter(
446
+ (entry) => entry.EntryType !== "assignment"
447
+ ),
448
+ "timestamp",
449
+ "desc"
450
+ );
451
+ const latest = statues.length > 0 ? statues[0] : null;
452
+
453
+ if (latest) {
454
+ const time = moment(Number.parseFloat(latest.timestamp + "")).format(
455
+ "D MMM YYYY HH:mm:ss"
456
+ );
457
+ const user = latest.user ? ` by ${latest.user.displayName}` : "";
458
+ const comment = `${time}: Marked ${latest.status}${user}`;
459
+ await this.addCommentToRequest(externalId, comment);
440
460
  }
441
461
 
442
- // save comments to Archibus
443
- comments.forEach((comment) => {
462
+ return true;
463
+ } catch (error) {
464
+ log("Archibus:OnStatusChanged", "Error", error.toString(), logId);
465
+ }
466
+ return false;
467
+ };
468
+
469
+ /**
470
+ * Perform actions when a a comment has been added to a task
471
+ *
472
+ * @param {Object} request - Request definition on Pluss
473
+ * @returns {Boolean} Represents whether the actions were successful
474
+ */
475
+ onCommentAdded = async (request) => {
476
+ const logId = log("Archibus:OnCommentAdded", "Start", {
477
+ Id: request.id,
478
+ });
479
+
480
+ try {
481
+ const externalId = await this.getExternalId(request);
482
+ if (_.isNil(externalId)) return true;
483
+
484
+ let comment = await this.getLatestComment(request, values.serviceKey);
485
+ if (!comment)
486
+ comment = await this.getLatestComment(request, values.entityKey);
487
+
488
+ if (comment) {
444
489
  const commentText = `${comment.User.displayName}:\n\n${
445
490
  comment.Comment
446
491
  }${!_.isEmpty(comment.Image) ? `\n\nImage: ${comment.Image}` : ""}}`;
447
492
  const commentTime = moment(comment.Timestamp);
448
- promises.push(
449
- this.addCommentToRequest(externalId, commentText, commentTime)
450
- );
451
- });
493
+ await this.addCommentToRequest(externalId, commentText, commentTime);
494
+ }
495
+
496
+ return true;
497
+ } catch (error) {
498
+ log("Archibus:OnCommentAdded", "Error", error.toString(), logId);
499
+ }
500
+ return false;
501
+ };
502
+
503
+ /**
504
+ * Perform actions when a note has been added to a task
505
+ *
506
+ * @param {Object} request - Request definition on Pluss
507
+ * @returns {Boolean} Represents whether the actions were successful
508
+ */
509
+ onNotesAdded = async (request) => {
510
+ const logId = log("Archibus:OnNotesAdded", "Start", { Id: request.id });
511
+
512
+ try {
513
+ const externalId = await this.getExternalId(request);
514
+ if (_.isNil(externalId)) return true;
452
515
 
453
- await Promise.all(promises);
516
+ const notes = _.orderBy(request.Notes ?? [], "Timestamp", "desc");
517
+ const latest = notes.length > 0 ? notes[0] : null;
518
+
519
+ if (latest) {
520
+ const promises = [];
521
+
522
+ const time = moment(Number.parseFloat(latest.Timestamp + "")).format(
523
+ "YYYY-MM-DD HH:mm:ss"
524
+ );
525
+ const user = latest.User ? latest.User.displayName : "Unknown User";
526
+ const note = latest.Note ? `Note: ${latest.Note}` : "No Note";
527
+ if (!_.isEmpty(latest.Attachments)) {
528
+ latest.Attachments.forEach((att) => {
529
+ promises.push(this.addFileToRequest(externalId, att.Source));
530
+ });
531
+ }
532
+ const attachments =
533
+ latest.Attachments && latest.Attachments.length > 0
534
+ ? `Attachments: ${latest.Attachments.map(
535
+ (att) => `${att.Title} (${att.Source})`
536
+ ).join(", ")}`
537
+ : "No Attachments";
538
+ if (!_.isEmpty(latest.Images)) {
539
+ latest.Images.forEach((image) => {
540
+ promises.push(this.addFileToRequest(externalId, image));
541
+ });
542
+ }
543
+ const images =
544
+ latest.Images && latest.Images.length > 0
545
+ ? `Images: ${latest.Images.map((image) => image).join(", ")}`
546
+ : "No Images";
547
+ const comment = `${time} by ${user}\n${note}\n${attachments}\n${images}`;
548
+ promises.push(this.addCommentToRequest(externalId, comment));
549
+
550
+ await Promise.all(promises);
551
+ }
454
552
 
455
553
  return true;
456
554
  } catch (error) {
457
- log("Archibus:OnComplete", "Error", error.toString(), logId);
555
+ log("Archibus:OnNotesAdded", "Error", error.toString(), logId);
458
556
  }
459
557
  return false;
460
558
  };
559
+
560
+ /**
561
+ * Perform completion actions when a task is completed
562
+ *
563
+ * @param {Object} request - Request definition on Pluss
564
+ * @returns {Boolean} Represents whether the actions were successful
565
+ */
566
+ onCompleteRequest = async (request) => {
567
+ return true;
568
+ };
461
569
  }
462
570
 
463
571
  module.exports = ArchibusStrategy;
@@ -19,7 +19,9 @@ exports.getStrategy = async (site) => {
19
19
  default:
20
20
  return new IntegrationStrategy();
21
21
  }
22
- } catch (e) {}
22
+ } catch (e) {
23
+ log("getStrategy", "Error", e, logId);
24
+ }
23
25
 
24
26
  return new IntegrationStrategy();
25
27
  };
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);
13
- await integrationStrategy.createRequest(request);
16
+ const mockRes = {
17
+ data: { wrId: moment().valueOf() },
18
+ };
19
+ await integrationStrategy.createRequest(request, mockRes);
20
+ // await integrationStrategy.createRequest(request);
14
21
  };
15
22
 
16
- const onCompletedRequest = async (request) => {
23
+ const onStatusChanged = async (request) => {
17
24
  const integrationStrategy = await getStrategy(request.site);
18
- await integrationStrategy.onCompleteRequest(request);
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 === "Completed" && prevRequest.status !== "Completed") {
36
- log("checkIntegrationActions", "CompletedRequest", true);
37
- await onCompletedRequest(request);
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.9",
3
+ "version": "2.1.12-beta.0",
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.19",
1472
- "resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.19.tgz",
1473
- "integrity": "sha512-A6y79EyAxYYPuvQSlMSI4sqeC8CXDQA/E4ZcGQCGUVmULJD65Nw24hfokl43KXSW7Igrgx0CQDoOMSRHBX4q2Q==",
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",
@@ -1744,7 +1744,7 @@
1744
1744
  "asynckit": {
1745
1745
  "version": "0.4.0",
1746
1746
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
1747
- "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
1747
+ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
1748
1748
  },
1749
1749
  "available-typed-arrays": {
1750
1750
  "version": "1.0.7",
@@ -2579,7 +2579,7 @@
2579
2579
  "delayed-stream": {
2580
2580
  "version": "1.0.0",
2581
2581
  "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
2582
- "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
2582
+ "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
2583
2583
  },
2584
2584
  "detect-newline": {
2585
2585
  "version": "3.1.0",
@@ -3077,7 +3077,7 @@
3077
3077
  "events": {
3078
3078
  "version": "1.1.1",
3079
3079
  "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
3080
- "integrity": "sha512-kEcvvCBByWXGnZy6JUlgAp2gBIUjfCAV6P6TgT1/aaQKcmuAEC4OZTV1I4EWQLz2gxZw76atuVyvHhTxvi0Flw=="
3080
+ "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ="
3081
3081
  },
3082
3082
  "execa": {
3083
3083
  "version": "5.1.1",
@@ -6657,7 +6657,7 @@
6657
6657
  "querystring": {
6658
6658
  "version": "0.2.0",
6659
6659
  "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
6660
- "integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g=="
6660
+ "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
6661
6661
  },
6662
6662
  "querystringify": {
6663
6663
  "version": "2.2.0",
@@ -6808,7 +6808,7 @@
6808
6808
  "sax": {
6809
6809
  "version": "1.2.1",
6810
6810
  "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
6811
- "integrity": "sha512-8I2a3LovHTOpm7NV5yOyO8IHqgVsfK4+UuySrXU8YXkSRX7k6hCV9b3HrkKCr3nMpgj+0bmocaJJWpvp1oc7ZA=="
6811
+ "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o="
6812
6812
  },
6813
6813
  "scmp": {
6814
6814
  "version": "2.1.0",
@@ -7308,7 +7308,7 @@
7308
7308
  "url": {
7309
7309
  "version": "0.10.3",
7310
7310
  "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz",
7311
- "integrity": "sha512-hzSUW2q06EqL1gKM/a+obYHLIO6ct2hwPuviqTTOcfFVc61UbfJ2Q32+uGL/HCPxKqrdGB5QUwIe7UqlDgwsOQ==",
7311
+ "integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=",
7312
7312
  "requires": {
7313
7313
  "punycode": "1.3.2",
7314
7314
  "querystring": "0.2.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-maintenance-aws-forms",
3
- "version": "2.1.9",
3
+ "version": "2.1.12-beta.0",
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.19",
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",
@@ -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
  }
@@ -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;
@@ -24,5 +24,6 @@ const values = {
24
24
  activityEditMaintenanceNote: "EditMaintenanceNote",
25
25
  textJobEmailTitle: "Service Request",
26
26
  allowGeneralType: true,
27
+ triggerMaintenanceStatusChanged: "MaintenanceStatusChanged",
27
28
  };
28
29
  exports.values = values;
@@ -24,5 +24,6 @@ const values = {
24
24
  activityEditMaintenanceNote: "EditMaintenanceNoteForms",
25
25
  textJobEmailTitle: "Form Submission",
26
26
  allowGeneralType: false,
27
+ triggerMaintenanceStatusChanged: "MaintenanceStatusChangedForms",
27
28
  };
28
29
  exports.values = values;
package/values.config.js CHANGED
@@ -24,5 +24,6 @@ const values = {
24
24
  activityEditMaintenanceNote: "EditMaintenanceNoteForms",
25
25
  textJobEmailTitle: "Form Submission",
26
26
  allowGeneralType: false,
27
+ triggerMaintenanceStatusChanged: "MaintenanceStatusChangedForms",
27
28
  };
28
29
  exports.values = values;