@kne/fastify-task 3.0.0-alpha.11 → 3.0.0-alpha.13
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/libs/controllers/main.js
CHANGED
|
@@ -212,7 +212,17 @@ const createContext = (fastify, options) => {
|
|
|
212
212
|
const getTaskDeclaration = type => {
|
|
213
213
|
const declaration = resolveTaskDeclaration(type);
|
|
214
214
|
if (!declaration) {
|
|
215
|
-
|
|
215
|
+
const { taskName } = splitTaskName(type);
|
|
216
|
+
return registerTaskDeclaration({
|
|
217
|
+
namespace: mainNamespace,
|
|
218
|
+
taskName,
|
|
219
|
+
dirs: options.dirs,
|
|
220
|
+
scriptName: options.scriptName,
|
|
221
|
+
config: {},
|
|
222
|
+
override: false,
|
|
223
|
+
syncLegacyTask: false,
|
|
224
|
+
useGlobalDirs: true
|
|
225
|
+
}).declaration;
|
|
216
226
|
}
|
|
217
227
|
return declaration;
|
|
218
228
|
};
|
package/libs/services/task.js
CHANGED
|
@@ -142,7 +142,36 @@ module.exports = fp(async (fastify, options) => {
|
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
const
|
|
145
|
+
const normalizeListQuery = (query = {}) => {
|
|
146
|
+
const normalized = Object.assign({}, query);
|
|
147
|
+
|
|
148
|
+
Object.entries(query || {}).forEach(([rawKey, value]) => {
|
|
149
|
+
const match = rawKey.match(/^(filter|sort)\[([^\]]+)\](?:\[([^\]]+)\])?$/);
|
|
150
|
+
if (!match) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const [, root, key, childKey] = match;
|
|
155
|
+
if (!normalized[root] || typeof normalized[root] !== 'object' || Array.isArray(normalized[root])) {
|
|
156
|
+
normalized[root] = {};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (childKey) {
|
|
160
|
+
if (!normalized[root][key] || typeof normalized[root][key] !== 'object' || Array.isArray(normalized[root][key])) {
|
|
161
|
+
normalized[root][key] = {};
|
|
162
|
+
}
|
|
163
|
+
normalized[root][key][childKey] = value;
|
|
164
|
+
} else {
|
|
165
|
+
normalized[root][key] = value;
|
|
166
|
+
}
|
|
167
|
+
delete normalized[rawKey];
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return normalized;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const list = async query => {
|
|
174
|
+
const { filter, perPage = 20, currentPage = 1, sort } = normalizeListQuery(query);
|
|
146
175
|
const whereQuery = {};
|
|
147
176
|
|
|
148
177
|
['id', 'targetId', 'type', 'status', 'runnerType'].forEach(key => {
|
|
@@ -151,6 +180,10 @@ module.exports = fp(async (fastify, options) => {
|
|
|
151
180
|
}
|
|
152
181
|
});
|
|
153
182
|
|
|
183
|
+
if (filter && filter.targetName) {
|
|
184
|
+
whereQuery['input.name'] = filter.targetName;
|
|
185
|
+
}
|
|
186
|
+
|
|
154
187
|
if (filter && filter.createdAt) {
|
|
155
188
|
whereQuery.createdAt = getTimeQuery(filter.createdAt);
|
|
156
189
|
}
|