@kne/fastify-task 1.0.5 → 1.0.6
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 +32 -3
- package/libs/services/main.js +45 -9
- package/package.json +1 -1
package/libs/controllers/main.js
CHANGED
|
@@ -22,9 +22,15 @@ module.exports = fp(async (fastify, options) => {
|
|
|
22
22
|
filter: {
|
|
23
23
|
type: 'object',
|
|
24
24
|
properties: {
|
|
25
|
+
id: {
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
25
28
|
targetId: {
|
|
26
29
|
type: 'string'
|
|
27
30
|
},
|
|
31
|
+
targetName: {
|
|
32
|
+
type: 'string'
|
|
33
|
+
},
|
|
28
34
|
type: {
|
|
29
35
|
type: 'string'
|
|
30
36
|
},
|
|
@@ -34,12 +40,35 @@ module.exports = fp(async (fastify, options) => {
|
|
|
34
40
|
runnerType: {
|
|
35
41
|
type: 'string'
|
|
36
42
|
},
|
|
43
|
+
createdAt: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
startTime: {
|
|
47
|
+
type: 'string'
|
|
48
|
+
},
|
|
49
|
+
endTime: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
description: 'createdAt区间查找'
|
|
54
|
+
},
|
|
37
55
|
completedAt: {
|
|
38
|
-
type: '
|
|
39
|
-
|
|
40
|
-
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
startTime: {
|
|
59
|
+
type: 'string'
|
|
60
|
+
},
|
|
61
|
+
endTime: {
|
|
62
|
+
type: 'string'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
description: 'completedAt区间查找'
|
|
41
66
|
}
|
|
42
67
|
}
|
|
68
|
+
},
|
|
69
|
+
sort: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
description: '按completedAt、updatedAt字段排序,ASC为升序,DESC为降序'
|
|
43
72
|
}
|
|
44
73
|
}
|
|
45
74
|
}
|
package/libs/services/main.js
CHANGED
|
@@ -281,25 +281,61 @@ module.exports = fp(async (fastify, options) => {
|
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
283
|
|
|
284
|
-
const
|
|
284
|
+
const getTimeQuery = fieldValue => {
|
|
285
|
+
const { startTime, endTime } = fieldValue;
|
|
286
|
+
if (!!startTime && !!endTime) {
|
|
287
|
+
// 两个日期都有值,使用between
|
|
288
|
+
return {
|
|
289
|
+
[Op.between]: [new Date(startTime), new Date(endTime)]
|
|
290
|
+
};
|
|
291
|
+
} else if (!!startTime) {
|
|
292
|
+
// 只有开始日期,大于等于
|
|
293
|
+
return {
|
|
294
|
+
[Op.gte]: new Date(startTime)
|
|
295
|
+
};
|
|
296
|
+
} else if (!!endTime) {
|
|
297
|
+
// 只有结束日期,小于等于
|
|
298
|
+
return {
|
|
299
|
+
[Op.lte]: new Date(endTime)
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const list = async ({ filter, perPage, currentPage, sort }) => {
|
|
285
305
|
const whereQuery = {};
|
|
286
306
|
|
|
287
|
-
['targetId', 'type', 'status', 'runnerType'].forEach(key => {
|
|
307
|
+
['id', 'targetId', 'type', 'status', 'runnerType'].forEach(key => {
|
|
288
308
|
if (filter && filter[key]) {
|
|
289
309
|
whereQuery[key] = filter[key];
|
|
290
310
|
}
|
|
291
311
|
});
|
|
292
312
|
|
|
293
|
-
// 处理
|
|
313
|
+
// 处理targetName模糊匹配,查询input.name字段
|
|
314
|
+
if (filter && filter.targetName) {
|
|
315
|
+
whereQuery['input.name'] = {
|
|
316
|
+
[Op.like]: `%${filter.targetName}%`
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 处理createdAt日期范围查询
|
|
321
|
+
if (filter && filter.createdAt) {
|
|
322
|
+
whereQuery.createdAt = getTimeQuery(filter.createdAt);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 处理completedAt日期范围查询
|
|
326
|
+
if (filter && filter.completedAt) {
|
|
327
|
+
whereQuery.completedAt = getTimeQuery(filter.completedAt);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 处理sort排序
|
|
294
331
|
let orderBy = 'createdAt';
|
|
295
332
|
let orderDirection = 'DESC';
|
|
296
333
|
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
334
|
+
if (sort && Object.keys(sort).length > 0) {
|
|
335
|
+
Object.keys(sort).forEach(key => {
|
|
336
|
+
orderBy = key;
|
|
337
|
+
orderDirection = sort[key];
|
|
338
|
+
});
|
|
303
339
|
}
|
|
304
340
|
|
|
305
341
|
const { rows, count } = await models.task.findAndCountAll({
|