@plusscommunities/pluss-maintenance-aws 2.1.44 → 2.1.46

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.
Files changed (45) hide show
  1. package/createJob.js +201 -114
  2. package/createJobType.js +49 -49
  3. package/db/maintenance/addMaintenanceJob.js +100 -90
  4. package/db/maintenance/editMaintenanceJob.js +22 -12
  5. package/db/maintenance/getJobEmail.js +22 -22
  6. package/deleteJob.js +58 -58
  7. package/deleteJobType.js +40 -40
  8. package/editJob.js +126 -65
  9. package/editJobStatus.js +57 -57
  10. package/editJobType.js +61 -61
  11. package/editNote.js +117 -117
  12. package/feature.config.js +279 -262
  13. package/getData.js +48 -41
  14. package/getJob.js +4 -4
  15. package/getJobType.js +35 -35
  16. package/getJobTypes.js +66 -66
  17. package/getJobs.js +48 -48
  18. package/integration/IntegrationStrategy.js +52 -52
  19. package/integration/archibus/ArchibusStrategy.js +42 -28
  20. package/integration/index.js +19 -19
  21. package/jobChanged.js +88 -89
  22. package/jobTypesChanged.js +52 -39
  23. package/package.json +3 -3
  24. package/requests/assignRequest.js +81 -81
  25. package/requests/getAssignees.js +27 -27
  26. package/requests/getExternalSync.js +100 -100
  27. package/requests/getPropertyRequests.js +89 -0
  28. package/requests/getRequest.js +77 -77
  29. package/requests/getRequests.js +210 -144
  30. package/requests/helper/hasRequestPermission.js +12 -12
  31. package/requests/helper/isValidAssignee.js +10 -10
  32. package/requests/retrySync.js +90 -90
  33. package/requests/setExternalJobId.js +113 -113
  34. package/requests/updatePriority.js +33 -33
  35. package/scheduleJobImport.js +63 -63
  36. package/sendJobEmail.js +105 -104
  37. package/updateData.js +34 -34
  38. package/values.config.a.js +26 -25
  39. package/values.config.default.js +30 -28
  40. package/values.config.enquiry.js +222 -221
  41. package/values.config.feedback.js +194 -193
  42. package/values.config.food.js +29 -28
  43. package/values.config.forms.js +29 -28
  44. package/values.config.js +30 -28
  45. package/watchJobs.js +154 -154
package/watchJobs.js CHANGED
@@ -11,167 +11,167 @@ const getUserPreview = require("@plusscommunities/pluss-core-aws/helper/getUserP
11
11
  const { values } = require("./values.config");
12
12
 
13
13
  const checkFixCompleted = async (job) => {
14
- const logId = log("checkFixCompleted", "Input", job.id);
15
- if (job.status !== "Completed") {
16
- log("checkFixCompleted", "Incomplete", job.status);
17
- return true;
18
- }
19
-
20
- // find entry in history to determine who completed and at what time
21
- let userId;
22
- let time = job.lastActivity;
23
- if (!_.isEmpty(job.history)) {
24
- const entry = _.findLast(job.history, (e) => {
25
- return e.status === "Completed";
26
- });
27
- if (entry) {
28
- if (entry.user && entry.user.id) {
29
- userId = entry.user.id;
30
- }
31
- time = entry.timestamp;
32
- }
33
- }
34
- const user = await getUserPreview(userId);
35
-
36
- // add old log
37
- await logAnalyticsActivity(
38
- "RequestCompleted",
39
- values.entityKey,
40
- job.site,
41
- user,
42
- job.id,
43
- null,
44
- moment(time).valueOf()
45
- );
46
- log("checkFixCompleted", "Logged", true, logId);
47
-
48
- // tell system to aggregate this date again
49
- const date = moment(time).local().format("DD-MM-YYYY");
50
- log("checkFixCompleted", "QueueingDate", date, logId);
51
- await updateRef("analyticsqueue", {
52
- Id: getRowId(job.site, date),
53
- Site: job.site,
54
- Date: date,
55
- });
14
+ const logId = log("checkFixCompleted", "Input", job.id);
15
+ if (job.status !== "Completed") {
16
+ log("checkFixCompleted", "Incomplete", job.status);
17
+ return true;
18
+ }
19
+
20
+ // find entry in history to determine who completed and at what time
21
+ let userId;
22
+ let time = job.lastActivity;
23
+ if (!_.isEmpty(job.history)) {
24
+ const entry = _.findLast(job.history, (e) => {
25
+ return e.status === "Completed";
26
+ });
27
+ if (entry) {
28
+ if (entry.user && entry.user.id) {
29
+ userId = entry.user.id;
30
+ }
31
+ time = entry.timestamp;
32
+ }
33
+ }
34
+ const user = await getUserPreview(userId);
35
+
36
+ // add old log
37
+ await logAnalyticsActivity(
38
+ "RequestCompleted",
39
+ values.entityKey,
40
+ job.site,
41
+ user,
42
+ job.id,
43
+ null,
44
+ moment(time).valueOf(),
45
+ );
46
+ log("checkFixCompleted", "Logged", true, logId);
47
+
48
+ // tell system to aggregate this date again
49
+ const date = moment(time).local().format("DD-MM-YYYY");
50
+ log("checkFixCompleted", "QueueingDate", date, logId);
51
+ await updateRef("analyticsqueue", {
52
+ Id: getRowId(job.site, date),
53
+ Site: job.site,
54
+ Date: date,
55
+ });
56
56
  };
57
57
 
58
58
  const fixActivityLog = async (job, startTime) => {
59
- const now = moment().unix();
60
- if (now - startTime > 240) {
61
- return false;
62
- }
63
-
64
- // check whether it's already been logged
65
- const exists = await checkActivityExists(job.id, values.entityKey, "Request");
66
- const logId = log("fixActivityLog", "exists", exists);
67
-
68
- if (!exists) {
69
- const user = await getUserPreview(job.userID);
70
-
71
- // add old log
72
- await logAnalyticsActivity(
73
- "Request",
74
- values.entityKey,
75
- job.site,
76
- user,
77
- job.id,
78
- null,
79
- moment(job.createdTime).valueOf()
80
- );
81
- log("fixActivityLog", "Logged", true, logId);
82
-
83
- // tell system to aggregate this date again
84
- const date = moment(job.createdTime).local().format("DD-MM-YYYY");
85
- log("fixActivityLog", "QueueingDate", date, logId);
86
- await updateRef("analyticsqueue", {
87
- Id: getRowId(job.site, date),
88
- Site: job.site,
89
- Date: date,
90
- });
91
-
92
- // check whether to log activity for the job's completion
93
- await checkFixCompleted(job);
94
- }
95
-
96
- // update entry to show it's been logged
97
- await editRef(values.tableNameMaintenance, "id", job.id, {
98
- ActivityLogged: true,
99
- });
100
-
101
- return true;
59
+ const now = moment().unix();
60
+ if (now - startTime > 240) {
61
+ return false;
62
+ }
63
+
64
+ // check whether it's already been logged
65
+ const exists = await checkActivityExists(job.id, values.entityKey, "Request");
66
+ const logId = log("fixActivityLog", "exists", exists);
67
+
68
+ if (!exists) {
69
+ const user = await getUserPreview(job.userID);
70
+
71
+ // add old log
72
+ await logAnalyticsActivity(
73
+ "Request",
74
+ values.entityKey,
75
+ job.site,
76
+ user,
77
+ job.id,
78
+ null,
79
+ moment(job.createdTime).valueOf(),
80
+ );
81
+ log("fixActivityLog", "Logged", true, logId);
82
+
83
+ // tell system to aggregate this date again
84
+ const date = moment(job.createdTime).local().format("DD-MM-YYYY");
85
+ log("fixActivityLog", "QueueingDate", date, logId);
86
+ await updateRef("analyticsqueue", {
87
+ Id: getRowId(job.site, date),
88
+ Site: job.site,
89
+ Date: date,
90
+ });
91
+
92
+ // check whether to log activity for the job's completion
93
+ await checkFixCompleted(job);
94
+ }
95
+
96
+ // update entry to show it's been logged
97
+ await editRef(values.tableNameMaintenance, "id", job.id, {
98
+ ActivityLogged: true,
99
+ });
100
+
101
+ return true;
102
102
  };
103
103
 
104
104
  const checkFixLog = async (startTime) => {
105
- // Check whether all posts have been logged
106
- const logId = log("checkFixLog", "StartTime", startTime);
107
- const stringSite = "plussSpace";
108
- const stringId = `JobActivityLogged`;
109
- const stringRowId = getRowId(stringSite, stringId);
110
- try {
111
- const string = await getRef("strings", "RowId", stringRowId);
112
- if (string && string.Value === "true") {
113
- log("checkFixLog", "ActivityLogged", true, logId);
114
- return true;
115
- }
116
- } catch (e) {
117
- // ignore error
118
- }
119
-
120
- // Scans the DynamoDB table and fetch all items. The parameters describe which attributes to get.
121
- const items = await scanRefRecursive(values.tableNameMaintenance, {
122
- ProjectionExpression:
123
- "#id, site, createdTime, #status, lastActivity, history, ActivityLogged",
124
- ExpressionAttributeNames: {
125
- "#id": "id",
126
- "#status": "status",
127
- },
128
- });
129
- log(
130
- "checkFixLog",
131
- "FetchedItemsCount",
132
- {
133
- count: items.length,
134
- },
135
- logId
136
- );
137
-
138
- // Filters out items which have already had the activity log operation applied.
139
- const itemsToProcess = items.filter((item) => !item.ActivityLogged);
140
- log(
141
- "checkFixLog",
142
- "ItemsToProcessCount",
143
- { count: itemsToProcess.length },
144
- logId
145
- );
146
-
147
- // Finished logging old entries. Save to avoid continuous full scans of the table.
148
- if (_.isEmpty(itemsToProcess)) {
149
- const entry = {
150
- Site: stringSite,
151
- StringId: stringId,
152
- Value: "true",
153
- RowId: stringRowId,
154
- };
155
-
156
- await updateRef("strings", entry);
157
- }
158
-
159
- // The loop goes through the remaining items and applies the fixActivityLog operation on each item.
160
- // If the operation fails on an item, it logs the error but continues with the remaining items.
161
- for (let item of itemsToProcess) {
162
- // try {
163
- await fixActivityLog(item, startTime);
164
- log("checkFixLog", "SuccessFixActivityLog", { id: item.Id }, logId);
165
- // } catch (err) {
166
- // log("checkFixLog", `Error:${item.Id}`, err, logId);
167
- // }
168
- }
169
-
170
- log("checkFixLog", "End", "All items processed", logId);
171
- return true;
105
+ // Check whether all posts have been logged
106
+ const logId = log("checkFixLog", "StartTime", startTime);
107
+ const stringSite = "plussSpace";
108
+ const stringId = `JobActivityLogged`;
109
+ const stringRowId = getRowId(stringSite, stringId);
110
+ try {
111
+ const string = await getRef("strings", "RowId", stringRowId);
112
+ if (string && string.Value === "true") {
113
+ log("checkFixLog", "ActivityLogged", true, logId);
114
+ return true;
115
+ }
116
+ } catch (e) {
117
+ // ignore error
118
+ }
119
+
120
+ // Scans the DynamoDB table and fetch all items. The parameters describe which attributes to get.
121
+ const items = await scanRefRecursive(values.tableNameMaintenance, {
122
+ ProjectionExpression:
123
+ "#id, site, createdTime, #status, lastActivity, history, ActivityLogged",
124
+ ExpressionAttributeNames: {
125
+ "#id": "id",
126
+ "#status": "status",
127
+ },
128
+ });
129
+ log(
130
+ "checkFixLog",
131
+ "FetchedItemsCount",
132
+ {
133
+ count: items.length,
134
+ },
135
+ logId,
136
+ );
137
+
138
+ // Filters out items which have already had the activity log operation applied.
139
+ const itemsToProcess = items.filter((item) => !item.ActivityLogged);
140
+ log(
141
+ "checkFixLog",
142
+ "ItemsToProcessCount",
143
+ { count: itemsToProcess.length },
144
+ logId,
145
+ );
146
+
147
+ // Finished logging old entries. Save to avoid continuous full scans of the table.
148
+ if (_.isEmpty(itemsToProcess)) {
149
+ const entry = {
150
+ Site: stringSite,
151
+ StringId: stringId,
152
+ Value: "true",
153
+ RowId: stringRowId,
154
+ };
155
+
156
+ await updateRef("strings", entry);
157
+ }
158
+
159
+ // The loop goes through the remaining items and applies the fixActivityLog operation on each item.
160
+ // If the operation fails on an item, it logs the error but continues with the remaining items.
161
+ for (let item of itemsToProcess) {
162
+ // try {
163
+ await fixActivityLog(item, startTime);
164
+ log("checkFixLog", "SuccessFixActivityLog", { id: item.Id }, logId);
165
+ // } catch (err) {
166
+ // log("checkFixLog", `Error:${item.Id}`, err, logId);
167
+ // }
168
+ }
169
+
170
+ log("checkFixLog", "End", "All items processed", logId);
171
+ return true;
172
172
  };
173
173
 
174
174
  module.exports.watchJobs = async (event, context, callback) => {
175
- const startTime = moment().unix();
176
- await checkFixLog(startTime);
175
+ const startTime = moment().unix();
176
+ await checkFixLog(startTime);
177
177
  };