@plusscommunities/pluss-maintenance-aws-forms 2.1.42 → 2.1.44
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 +79 -54
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.44",
|
|
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,68 @@ 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 = 250;
|
|
27
|
+
|
|
28
|
+
// When filters are active, fetch all matching results so the
|
|
29
|
+
// client receives a complete set rather than a truncated page.
|
|
30
|
+
const MIN_RESULT_COUNT_FILTERED = Infinity;
|
|
31
|
+
|
|
32
|
+
const hasActiveFilters = (qParams) =>
|
|
33
|
+
qParams.status || qParams.priority || qParams.type || qParams.search || qParams.startTime || qParams.endTime;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Apply all post-query filters to a set of jobs.
|
|
37
|
+
* Extracted so the same logic runs on every auto-fill page.
|
|
38
|
+
*/
|
|
39
|
+
const filterJobs = (jobs, qParams, authorised, assigneeTracking, userId) => {
|
|
40
|
+
let filtered = jobs;
|
|
41
|
+
|
|
42
|
+
if (qParams.status) {
|
|
43
|
+
if (qParams.status === "Incomplete") {
|
|
44
|
+
filtered = filtered.filter((j) => !isCompleted(normalizeStatus(j.status)));
|
|
45
|
+
} else {
|
|
46
|
+
filtered = filtered.filter((j) => qParams.status.includes(normalizeStatus(j.status)));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (qParams.priority) {
|
|
51
|
+
filtered = filtered.filter((j) => qParams.priority.includes(normalizePriority(j.priority)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (qParams.type) {
|
|
55
|
+
filtered = filtered.filter((j) => qParams.type.includes(j.type));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!authorised && assigneeTracking) {
|
|
59
|
+
filtered = filtered.filter((j) => j.AssigneeId === userId || j.userID === userId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (qParams.startTime) {
|
|
63
|
+
const startTime = parseInt(qParams.startTime, 10);
|
|
64
|
+
filtered = filtered.filter((j) => j.createdUnix >= startTime);
|
|
65
|
+
}
|
|
66
|
+
if (qParams.endTime) {
|
|
67
|
+
const endTime = parseInt(qParams.endTime, 10);
|
|
68
|
+
filtered = filtered.filter((j) => j.createdUnix <= endTime);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (qParams.search) {
|
|
72
|
+
const searchLower = qParams.search.toLowerCase();
|
|
73
|
+
filtered = filtered.filter((j) => {
|
|
74
|
+
if (j.jobId && j.jobId === qParams.search) return true;
|
|
75
|
+
if (j.room && j.room.toLowerCase().indexOf(searchLower) > -1) return true;
|
|
76
|
+
if (j.title && j.title.toLowerCase().indexOf(searchLower) > -1) return true;
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return filtered;
|
|
82
|
+
};
|
|
83
|
+
|
|
22
84
|
module.exports = async (event) => {
|
|
23
85
|
const qParams = event.queryStringParameters;
|
|
24
86
|
const logId = log("getRequests", "Params", qParams);
|
|
@@ -89,67 +151,30 @@ module.exports = async (event) => {
|
|
|
89
151
|
} catch (e) {}
|
|
90
152
|
}
|
|
91
153
|
|
|
92
|
-
// get jobs
|
|
93
|
-
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
log("getRequests", "LastEvaluatedKey", result.LastEvaluatedKey, logId);
|
|
97
|
-
log("getRequests", "JobsLength", jobs.length, logId);
|
|
154
|
+
// get first page of jobs
|
|
155
|
+
let result = await indexQuery(values.tableNameMaintenance, query);
|
|
156
|
+
let allJobs = filterJobs(result.Items, qParams, authorised, assigneeTracking, userId);
|
|
157
|
+
let lastKey = result.LastEvaluatedKey;
|
|
98
158
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (qParams.status === "Incomplete") {
|
|
102
|
-
jobs = jobs.filter((j) => !isCompleted(normalizeStatus(j.status)));
|
|
103
|
-
} else {
|
|
104
|
-
jobs = jobs.filter((j) => qParams.status.includes(normalizeStatus(j.status)));
|
|
105
|
-
}
|
|
106
|
-
log("getRequests", "FilteredOnStatus", jobs.length, logId);
|
|
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
|
-
}
|
|
159
|
+
log("getRequests", "LastEvaluatedKey", lastKey, logId);
|
|
160
|
+
log("getRequests", "FirstPageFiltered", allJobs.length, logId);
|
|
120
161
|
|
|
121
|
-
|
|
122
|
-
if (!authorised && assigneeTracking) {
|
|
123
|
-
jobs = jobs.filter((j) => j.AssigneeId === userId || j.userID === userId);
|
|
124
|
-
log("getRequests", "FilteredOnAssignee", jobs.length, logId);
|
|
125
|
-
}
|
|
162
|
+
const minResults = hasActiveFilters(qParams) ? MIN_RESULT_COUNT_FILTERED : MIN_RESULT_COUNT;
|
|
126
163
|
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const endTime = parseInt(qParams.endTime, 10);
|
|
135
|
-
jobs = jobs.filter((j) => j.createdUnix <= endTime);
|
|
136
|
-
log("getRequests", "FilteredOnEndTime", jobs.length, logId);
|
|
164
|
+
// auto-fill: keep fetching pages until we have enough filtered results
|
|
165
|
+
while (lastKey && allJobs.length < minResults) {
|
|
166
|
+
const nextQuery = { ...query, ExclusiveStartKey: lastKey };
|
|
167
|
+
result = await indexQuery(values.tableNameMaintenance, nextQuery);
|
|
168
|
+
const filtered = filterJobs(result.Items, qParams, authorised, assigneeTracking, userId);
|
|
169
|
+
allJobs = [...allJobs, ...filtered];
|
|
170
|
+
lastKey = result.LastEvaluatedKey;
|
|
137
171
|
}
|
|
138
172
|
|
|
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
|
-
}
|
|
173
|
+
log("getRequests", "TotalFiltered", allJobs.length, logId);
|
|
174
|
+
log("getRequests", "PagesFetched", lastKey ? "more available" : "exhausted", logId);
|
|
150
175
|
|
|
151
176
|
// compile results
|
|
152
|
-
const results = { Items:
|
|
177
|
+
const results = { Items: allJobs, LastKey: lastKey };
|
|
153
178
|
log("getRequests", "Done", true, logId);
|
|
154
179
|
return { status: 200, data: results };
|
|
155
180
|
};
|