Refactoring of sorting and filtering in API.
This commit is contained in:
parent
3590ba048d
commit
975d5288a3
6 changed files with 140 additions and 91 deletions
server/resources
|
@ -10,7 +10,7 @@ import {forConstraint, forConstraints} from "../validation/validator";
|
|||
import * as Resources from "../utils/resources";
|
||||
import {Entity} from "../utils/resources";
|
||||
import {Request, Response} from "express";
|
||||
import {EnhancedNode, Node} from "../types";
|
||||
import {EnhancedNode, isNodeSortField, Node} from "../types";
|
||||
|
||||
const nodeFields = ['hostname', 'key', 'email', 'nickname', 'mac', 'coords', 'monitoring'];
|
||||
|
||||
|
@ -130,19 +130,7 @@ async function doGetAll(req: Request): Promise<{ total: number; pageNodes: any }
|
|||
|
||||
const sortedNodes = Resources.sort(
|
||||
filteredNodes,
|
||||
[
|
||||
'hostname',
|
||||
'nickname',
|
||||
'email',
|
||||
'token',
|
||||
'mac',
|
||||
'key',
|
||||
'site',
|
||||
'domain',
|
||||
'coords',
|
||||
'onlineState',
|
||||
'monitoringState'
|
||||
],
|
||||
isNodeSortField,
|
||||
restParams
|
||||
);
|
||||
const pageNodes = Resources.getPageEntities(sortedNodes, restParams);
|
||||
|
|
|
@ -8,6 +8,7 @@ import {getTasks, Task, TaskState} from "../jobs/scheduler";
|
|||
import {normalizeString} from "../utils/strings";
|
||||
import {forConstraint} from "../validation/validator";
|
||||
import {Request, Response} from "express";
|
||||
import {isTaskSortField} from "../types";
|
||||
|
||||
const isValidId = forConstraint(CONSTRAINTS.id, false);
|
||||
|
||||
|
@ -81,7 +82,7 @@ async function doGetAll(req: Request): Promise<{total: number, pageTasks: Entity
|
|||
|
||||
const tasks = Resources.sort(
|
||||
_.values(getTasks()),
|
||||
['id', 'name', 'schedule', 'state', 'runningSince', 'lastRunStarted'],
|
||||
isTaskSortField,
|
||||
restParams
|
||||
);
|
||||
const filteredTasks = Resources.filter(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue