@plusscommunities/pluss-maintenance-aws-forms 2.1.42 → 2.1.43
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/package.json +2 -2
- package/requests/getRequests.js +73 -57
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.43",
|
|
4
4
|
"description": "Extension package to enable maintenance on Pluss Communities Platform",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"gc": "node ../../tools/gc ./",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"copy:get": "echo $npm_package_name",
|
|
17
17
|
"copy:set": "run(){ target='\\@plusscommunities\\/pluss-maintenance-aws'; ext=${1:-default}; [ $ext == 'default' ] && replace=$target || replace=$target'-'$ext; echo 'Setting target to '$replace; test -f values.config.$ext.js && cp -f values.config.$ext.js values.config.js; sed -i '' -e 's/'$target'.*\"/'$replace'\"/g' package.json; }; run",
|
|
18
18
|
"copy:deploy": "for file in `ls ./values.config.*.js`; do dup=`echo $file | sed 's/.*values\\.config\\.\\(.*\\)\\.js/\\1/'`; npm run copy:set $dup; npm run deploy; done; npm run copy:set; npm run gs;",
|
|
19
|
-
"copy:betaupload": "
|
|
19
|
+
"copy:betaupload": "for file in `ls ./values.config.*.js`; do dup=`echo $file | sed 's/.*values\\.config\\.\\(.*\\)\\.js/\\1/'`; npm run copy:set $dup; npm run betaupload; done; npm run copy:set;",
|
|
20
20
|
"copy:upload": "for file in `ls ./values.config.*.js`; do dup=`echo $file | sed 's/.*values\\.config\\.\\(.*\\)\\.js/\\1/'`; npm run copy:set $dup; npm run upload; done; npm run copy:set;",
|
|
21
21
|
"test": "jest tests -i"
|
|
22
22
|
},
|
package/requests/getRequests.js
CHANGED
|
@@ -19,6 +19,61 @@ const DEFAULT_PRIORITY = "Low";
|
|
|
19
19
|
const normalizePriority = (priority) =>
|
|
20
20
|
priority == null ? DEFAULT_PRIORITY : priority;
|
|
21
21
|
|
|
22
|
+
// Minimum number of filtered results to return before stopping.
|
|
23
|
+
// Because DynamoDB pages are unfiltered and we filter after query,
|
|
24
|
+
// a single page may yield very few matching results. We keep
|
|
25
|
+
// fetching pages until we have this many items to return.
|
|
26
|
+
const MIN_RESULT_COUNT = 50;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Apply all post-query filters to a set of jobs.
|
|
30
|
+
* Extracted so the same logic runs on every auto-fill page.
|
|
31
|
+
*/
|
|
32
|
+
const filterJobs = (jobs, qParams, authorised, assigneeTracking, userId) => {
|
|
33
|
+
let filtered = jobs;
|
|
34
|
+
|
|
35
|
+
if (qParams.status) {
|
|
36
|
+
if (qParams.status === "Incomplete") {
|
|
37
|
+
filtered = filtered.filter((j) => !isCompleted(normalizeStatus(j.status)));
|
|
38
|
+
} else {
|
|
39
|
+
filtered = filtered.filter((j) => qParams.status.includes(normalizeStatus(j.status)));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (qParams.priority) {
|
|
44
|
+
filtered = filtered.filter((j) => qParams.priority.includes(normalizePriority(j.priority)));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (qParams.type) {
|
|
48
|
+
filtered = filtered.filter((j) => qParams.type.includes(j.type));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!authorised && assigneeTracking) {
|
|
52
|
+
filtered = filtered.filter((j) => j.AssigneeId === userId || j.userID === userId);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (qParams.startTime) {
|
|
56
|
+
const startTime = parseInt(qParams.startTime, 10);
|
|
57
|
+
filtered = filtered.filter((j) => j.createdUnix >= startTime);
|
|
58
|
+
}
|
|
59
|
+
if (qParams.endTime) {
|
|
60
|
+
const endTime = parseInt(qParams.endTime, 10);
|
|
61
|
+
filtered = filtered.filter((j) => j.createdUnix <= endTime);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (qParams.search) {
|
|
65
|
+
const searchLower = qParams.search.toLowerCase();
|
|
66
|
+
filtered = filtered.filter((j) => {
|
|
67
|
+
if (j.jobId && j.jobId === qParams.search) return true;
|
|
68
|
+
if (j.room && j.room.toLowerCase().indexOf(searchLower) > -1) return true;
|
|
69
|
+
if (j.title && j.title.toLowerCase().indexOf(searchLower) > -1) return true;
|
|
70
|
+
return false;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return filtered;
|
|
75
|
+
};
|
|
76
|
+
|
|
22
77
|
module.exports = async (event) => {
|
|
23
78
|
const qParams = event.queryStringParameters;
|
|
24
79
|
const logId = log("getRequests", "Params", qParams);
|
|
@@ -89,67 +144,28 @@ module.exports = async (event) => {
|
|
|
89
144
|
} catch (e) {}
|
|
90
145
|
}
|
|
91
146
|
|
|
92
|
-
// get jobs
|
|
93
|
-
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
log("getRequests", "
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// filter on priority (normalise null to the default)
|
|
110
|
-
if (qParams.priority) {
|
|
111
|
-
jobs = jobs.filter((j) => qParams.priority.includes(normalizePriority(j.priority)));
|
|
112
|
-
log("getRequests", "FilterOnPriority", jobs.length, logId);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// filter on type
|
|
116
|
-
if (qParams.type) {
|
|
117
|
-
jobs = jobs.filter((j) => qParams.type.includes(j.type));
|
|
118
|
-
log("getRequests", "FilteredOnType", jobs.length, logId);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// filter to assigned jobs
|
|
122
|
-
if (!authorised && assigneeTracking) {
|
|
123
|
-
jobs = jobs.filter((j) => j.AssigneeId === userId || j.userID === userId);
|
|
124
|
-
log("getRequests", "FilteredOnAssignee", jobs.length, logId);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// filter on time range
|
|
128
|
-
if (qParams.startTime) {
|
|
129
|
-
const startTime = parseInt(qParams.startTime, 10);
|
|
130
|
-
jobs = jobs.filter((j) => j.createdUnix >= startTime);
|
|
131
|
-
log("getRequests", "FilteredOnStartTime", jobs.length, logId);
|
|
132
|
-
}
|
|
133
|
-
if (qParams.endTime) {
|
|
134
|
-
const endTime = parseInt(qParams.endTime, 10);
|
|
135
|
-
jobs = jobs.filter((j) => j.createdUnix <= endTime);
|
|
136
|
-
log("getRequests", "FilteredOnEndTime", jobs.length, logId);
|
|
147
|
+
// get first page of jobs
|
|
148
|
+
let result = await indexQuery(values.tableNameMaintenance, query);
|
|
149
|
+
let allJobs = filterJobs(result.Items, qParams, authorised, assigneeTracking, userId);
|
|
150
|
+
let lastKey = result.LastEvaluatedKey;
|
|
151
|
+
|
|
152
|
+
log("getRequests", "LastEvaluatedKey", lastKey, logId);
|
|
153
|
+
log("getRequests", "FirstPageFiltered", allJobs.length, logId);
|
|
154
|
+
|
|
155
|
+
// auto-fill: keep fetching pages until we have MIN_RESULT_COUNT filtered results
|
|
156
|
+
while (lastKey && allJobs.length < MIN_RESULT_COUNT) {
|
|
157
|
+
const nextQuery = { ...query, ExclusiveStartKey: lastKey };
|
|
158
|
+
result = await indexQuery(values.tableNameMaintenance, nextQuery);
|
|
159
|
+
const filtered = filterJobs(result.Items, qParams, authorised, assigneeTracking, userId);
|
|
160
|
+
allJobs = [...allJobs, ...filtered];
|
|
161
|
+
lastKey = result.LastEvaluatedKey;
|
|
137
162
|
}
|
|
138
163
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const searchLower = qParams.search.toLowerCase();
|
|
142
|
-
jobs = jobs.filter((j) => {
|
|
143
|
-
if (j.jobId && j.jobId === qParams.search) return true;
|
|
144
|
-
if (j.room && j.room.toLowerCase().indexOf(searchLower) > -1) return true;
|
|
145
|
-
if (j.title && j.title.toLowerCase().indexOf(searchLower) > -1) return true;
|
|
146
|
-
return false;
|
|
147
|
-
});
|
|
148
|
-
log("getRequests", "FilteredOnSearch", jobs.length, logId);
|
|
149
|
-
}
|
|
164
|
+
log("getRequests", "TotalFiltered", allJobs.length, logId);
|
|
165
|
+
log("getRequests", "PagesFetched", lastKey ? "more available" : "exhausted", logId);
|
|
150
166
|
|
|
151
167
|
// compile results
|
|
152
|
-
const results = { Items:
|
|
168
|
+
const results = { Items: allJobs, LastKey: lastKey };
|
|
153
169
|
log("getRequests", "Done", true, logId);
|
|
154
170
|
return { status: 200, data: results };
|
|
155
171
|
};
|