ESLint: Auto reformat and fixing some warnings / errors.
This commit is contained in:
parent
5237db38e0
commit
91690509d3
50 changed files with 2141 additions and 1493 deletions
|
@ -1,4 +1,4 @@
|
|||
import {handleJSON} from "../utils/resources";
|
||||
import {config} from "../config";
|
||||
import { handleJSON } from "../utils/resources";
|
||||
import { config } from "../config";
|
||||
|
||||
export const get = handleJSON(async () => config.client);
|
||||
|
|
|
@ -1,26 +1,36 @@
|
|||
import {promises as fs} from "graceful-fs";
|
||||
import { promises as fs } from "graceful-fs";
|
||||
|
||||
import ErrorTypes from "../utils/errorTypes";
|
||||
import Logger from "../logger";
|
||||
import * as Resources from "../utils/resources";
|
||||
import {Request, Response} from "express";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
const indexHtml = __dirname + '/../../client/index.html';
|
||||
const indexHtml = __dirname + "/../../client/index.html";
|
||||
|
||||
export function render (req: Request, res: Response): void {
|
||||
export function render(req: Request, res: Response): void {
|
||||
const data = Resources.getData(req);
|
||||
|
||||
fs.readFile(indexHtml, 'utf8')
|
||||
.then(body =>
|
||||
fs.readFile(indexHtml, "utf8")
|
||||
.then((body) =>
|
||||
Resources.successHtml(
|
||||
res,
|
||||
body.replace(
|
||||
/<body/,
|
||||
'<script>window.__nodeToken = \''+ data.token + '\';</script><body'
|
||||
"<script>window.__nodeToken = '" +
|
||||
data.token +
|
||||
"';</script><body"
|
||||
)
|
||||
))
|
||||
.catch(err => {
|
||||
Logger.tag('frontend').error('Could not read file: ', indexHtml, err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
})
|
||||
)
|
||||
)
|
||||
.catch((err) => {
|
||||
Logger.tag("frontend").error(
|
||||
"Could not read file: ",
|
||||
indexHtml,
|
||||
err
|
||||
);
|
||||
return Resources.error(res, {
|
||||
data: "Internal error.",
|
||||
type: ErrorTypes.internalError,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,53 +2,55 @@ import CONSTRAINTS from "../shared/validation/constraints";
|
|||
import ErrorTypes from "../utils/errorTypes";
|
||||
import * as MailService from "../services/mailService";
|
||||
import * as Resources from "../utils/resources";
|
||||
import {handleJSONWithData, RequestData} from "../utils/resources";
|
||||
import {normalizeString, parseInteger} from "../shared/utils/strings";
|
||||
import {forConstraint} from "../shared/validation/validator";
|
||||
import {Request, Response} from "express";
|
||||
import {isString, Mail, MailId} from "../types";
|
||||
import { handleJSONWithData, RequestData } from "../utils/resources";
|
||||
import { normalizeString, parseInteger } from "../shared/utils/strings";
|
||||
import { forConstraint } from "../shared/validation/validator";
|
||||
import { Request, Response } from "express";
|
||||
import { isString, Mail, MailId } from "../types";
|
||||
|
||||
const isValidId = forConstraint(CONSTRAINTS.id, false);
|
||||
|
||||
async function withValidMailId(data: RequestData): Promise<MailId> {
|
||||
if (!isString(data.id)) {
|
||||
throw {data: 'Missing mail id.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Missing mail id.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
|
||||
const id = normalizeString(data.id);
|
||||
|
||||
if (!isValidId(id)) {
|
||||
throw {data: 'Invalid mail id.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid mail id.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
|
||||
return parseInteger(id) as MailId;
|
||||
}
|
||||
|
||||
export const get = handleJSONWithData(async data => {
|
||||
export const get = handleJSONWithData(async (data) => {
|
||||
const id = await withValidMailId(data);
|
||||
return await MailService.getMail(id);
|
||||
});
|
||||
|
||||
async function doGetAll(req: Request): Promise<{ total: number, mails: Mail[] }> {
|
||||
const restParams = await Resources.getValidRestParams('list', null, req);
|
||||
async function doGetAll(
|
||||
req: Request
|
||||
): Promise<{ total: number; mails: Mail[] }> {
|
||||
const restParams = await Resources.getValidRestParams("list", null, req);
|
||||
return await MailService.getPendingMails(restParams);
|
||||
}
|
||||
|
||||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then(({total, mails}) => {
|
||||
res.set('X-Total-Count', total.toString(10));
|
||||
.then(({ total, mails }) => {
|
||||
res.set("X-Total-Count", total.toString(10));
|
||||
return Resources.success(res, mails);
|
||||
})
|
||||
.catch(err => Resources.error(res, err))
|
||||
.catch((err) => Resources.error(res, err));
|
||||
}
|
||||
|
||||
export const remove = handleJSONWithData(async data => {
|
||||
export const remove = handleJSONWithData(async (data) => {
|
||||
const id = await withValidMailId(data);
|
||||
await MailService.deleteMail(id);
|
||||
});
|
||||
|
||||
export const resetFailures = handleJSONWithData(async data => {
|
||||
export const resetFailures = handleJSONWithData(async (data) => {
|
||||
const id = await withValidMailId(data);
|
||||
return await MailService.resetFailures(id);
|
||||
});
|
||||
|
|
|
@ -2,55 +2,63 @@ import CONSTRAINTS from "../shared/validation/constraints";
|
|||
import ErrorTypes from "../utils/errorTypes";
|
||||
import * as MonitoringService from "../services/monitoringService";
|
||||
import * as Resources from "../utils/resources";
|
||||
import {handleJSONWithData} from "../utils/resources";
|
||||
import {normalizeString} from "../shared/utils/strings";
|
||||
import {forConstraint} from "../shared/validation/validator";
|
||||
import {Request, Response} from "express";
|
||||
import {isMonitoringToken, JSONObject, MonitoringResponse, MonitoringToken, toMonitoringResponse} from "../types";
|
||||
import { handleJSONWithData } from "../utils/resources";
|
||||
import { normalizeString } from "../shared/utils/strings";
|
||||
import { forConstraint } from "../shared/validation/validator";
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
isMonitoringToken,
|
||||
JSONObject,
|
||||
MonitoringResponse,
|
||||
MonitoringToken,
|
||||
toMonitoringResponse,
|
||||
} from "../types";
|
||||
|
||||
const isValidToken = forConstraint(CONSTRAINTS.token, false);
|
||||
|
||||
// FIXME: Get rid of any
|
||||
async function doGetAll(req: Request): Promise<{ total: number, result: any }> {
|
||||
const restParams = await Resources.getValidRestParams('list', null, req);
|
||||
const {monitoringStates, total} = await MonitoringService.getAll(restParams);
|
||||
async function doGetAll(req: Request): Promise<{ total: number; result: any }> {
|
||||
const restParams = await Resources.getValidRestParams("list", null, req);
|
||||
const { monitoringStates, total } = await MonitoringService.getAll(
|
||||
restParams
|
||||
);
|
||||
return {
|
||||
total,
|
||||
result: monitoringStates.map(state => {
|
||||
result: monitoringStates.map((state) => {
|
||||
state.mapId = state.mac.toLowerCase().replace(/:/g, "");
|
||||
return state;
|
||||
})
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then(({total, result}) => {
|
||||
res.set('X-Total-Count', total.toString(10));
|
||||
Resources.success(res, result)
|
||||
.then(({ total, result }) => {
|
||||
res.set("X-Total-Count", total.toString(10));
|
||||
Resources.success(res, result);
|
||||
})
|
||||
.catch(err => Resources.error(res, err));
|
||||
.catch((err) => Resources.error(res, err));
|
||||
}
|
||||
|
||||
function getValidatedToken(data: JSONObject): MonitoringToken {
|
||||
if (!isMonitoringToken(data.token)) {
|
||||
throw {data: 'Missing token.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Missing token.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
const token = normalizeString(data.token);
|
||||
if (!isValidToken(token)) {
|
||||
throw {data: 'Invalid token.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid token.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
return token as MonitoringToken;
|
||||
}
|
||||
|
||||
export const confirm = handleJSONWithData<MonitoringResponse>(async data => {
|
||||
export const confirm = handleJSONWithData<MonitoringResponse>(async (data) => {
|
||||
const validatedToken = getValidatedToken(data);
|
||||
|
||||
const node = await MonitoringService.confirm(validatedToken);
|
||||
return toMonitoringResponse(node);
|
||||
});
|
||||
|
||||
export const disable = handleJSONWithData<MonitoringResponse>(async data => {
|
||||
export const disable = handleJSONWithData<MonitoringResponse>(async (data) => {
|
||||
const validatedToken: MonitoringToken = getValidatedToken(data);
|
||||
|
||||
const node = await MonitoringService.disable(validatedToken);
|
||||
|
|
|
@ -2,11 +2,11 @@ import Constraints from "../shared/validation/constraints";
|
|||
import ErrorTypes from "../utils/errorTypes";
|
||||
import * as MonitoringService from "../services/monitoringService";
|
||||
import * as NodeService from "../services/nodeService";
|
||||
import {normalizeMac, normalizeString} from "../shared/utils/strings";
|
||||
import {forConstraint, forConstraints} from "../shared/validation/validator";
|
||||
import { normalizeMac, normalizeString } from "../shared/utils/strings";
|
||||
import { forConstraint, forConstraints } from "../shared/validation/validator";
|
||||
import * as Resources from "../utils/resources";
|
||||
import {handleJSONWithData} from "../utils/resources";
|
||||
import {Request, Response} from "express";
|
||||
import { handleJSONWithData } from "../utils/resources";
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
CreateOrUpdateNode,
|
||||
DomainSpecificNodeResponse,
|
||||
|
@ -24,18 +24,26 @@ import {
|
|||
toDomainSpecificNodeResponse,
|
||||
Token,
|
||||
toNodeResponse,
|
||||
toNodeTokenResponse
|
||||
toNodeTokenResponse,
|
||||
} from "../types";
|
||||
|
||||
const nodeFields = ['hostname', 'key', 'email', 'nickname', 'mac', 'coords', 'monitoring'];
|
||||
const nodeFields = [
|
||||
"hostname",
|
||||
"key",
|
||||
"email",
|
||||
"nickname",
|
||||
"mac",
|
||||
"coords",
|
||||
"monitoring",
|
||||
];
|
||||
|
||||
function getNormalizedNodeData(reqData: JSONObject): CreateOrUpdateNode {
|
||||
const node: { [key: string]: any } = {};
|
||||
const node: { [key: string]: unknown } = {};
|
||||
for (const field of nodeFields) {
|
||||
let value: JSONValue | undefined = reqData[field];
|
||||
if (isString(value)) {
|
||||
value = normalizeString(value);
|
||||
if (field === 'mac') {
|
||||
if (field === "mac") {
|
||||
value = normalizeMac(value as MAC);
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +57,7 @@ function getNormalizedNodeData(reqData: JSONObject): CreateOrUpdateNode {
|
|||
return node;
|
||||
}
|
||||
|
||||
throw {data: "Invalid node data.", type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid node data.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
|
||||
const isValidNode = forConstraints(Constraints.node, false);
|
||||
|
@ -57,77 +65,82 @@ const isValidToken = forConstraint(Constraints.token, false);
|
|||
|
||||
function getValidatedToken(data: JSONObject): Token {
|
||||
if (!isToken(data.token)) {
|
||||
throw {data: 'Missing token.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Missing token.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
const token = normalizeString(data.token);
|
||||
if (!isValidToken(token)) {
|
||||
throw {data: 'Invalid token.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid token.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
return token as Token;
|
||||
}
|
||||
|
||||
export const create = handleJSONWithData<NodeTokenResponse>(async data => {
|
||||
export const create = handleJSONWithData<NodeTokenResponse>(async (data) => {
|
||||
const baseNode = getNormalizedNodeData(data);
|
||||
if (!isValidNode(baseNode)) {
|
||||
throw {data: 'Invalid node data.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid node data.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
|
||||
const node = await NodeService.createNode(baseNode);
|
||||
return toNodeTokenResponse(node);
|
||||
});
|
||||
|
||||
export const update = handleJSONWithData<NodeTokenResponse>(async data => {
|
||||
export const update = handleJSONWithData<NodeTokenResponse>(async (data) => {
|
||||
const validatedToken: Token = getValidatedToken(data);
|
||||
const baseNode = getNormalizedNodeData(data);
|
||||
if (!isValidNode(baseNode)) {
|
||||
throw {data: 'Invalid node data.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid node data.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
|
||||
const node = await NodeService.updateNode(validatedToken, baseNode);
|
||||
return toNodeTokenResponse(node);
|
||||
});
|
||||
|
||||
export const remove = handleJSONWithData<void>(async data => {
|
||||
export const remove = handleJSONWithData<void>(async (data) => {
|
||||
const validatedToken = getValidatedToken(data);
|
||||
await NodeService.deleteNode(validatedToken);
|
||||
});
|
||||
|
||||
export const get = handleJSONWithData<NodeResponse>(async data => {
|
||||
export const get = handleJSONWithData<NodeResponse>(async (data) => {
|
||||
const validatedToken: Token = getValidatedToken(data);
|
||||
const node = await NodeService.getNodeDataByToken(validatedToken);
|
||||
return toNodeResponse(node);
|
||||
});
|
||||
|
||||
async function doGetAll(req: Request): Promise<{ total: number; pageNodes: any }> {
|
||||
const restParams = await Resources.getValidRestParams('list', 'node', req);
|
||||
async function doGetAll(
|
||||
req: Request
|
||||
): Promise<{ total: number; pageNodes: any }> {
|
||||
const restParams = await Resources.getValidRestParams("list", "node", req);
|
||||
|
||||
const nodes = await NodeService.getAllNodes();
|
||||
|
||||
const realNodes = nodes.filter(node =>
|
||||
// We ignore nodes without tokens as those are only manually added ones like gateways.
|
||||
!!node.token // FIXME: As node.token may not be undefined or null here, handle this when loading!
|
||||
const realNodes = nodes.filter(
|
||||
(node) =>
|
||||
// We ignore nodes without tokens as those are only manually added ones like gateways.
|
||||
!!node.token // FIXME: As node.token may not be undefined or null here, handle this when loading!
|
||||
);
|
||||
|
||||
const macs: MAC[] = realNodes.map(node => node.mac);
|
||||
const macs: MAC[] = realNodes.map((node) => node.mac);
|
||||
const nodeStateByMac = await MonitoringService.getByMacs(macs);
|
||||
|
||||
const domainSpecificNodes: DomainSpecificNodeResponse[] = realNodes.map(node => {
|
||||
const nodeState: NodeStateData = nodeStateByMac[node.mac] || {};
|
||||
return toDomainSpecificNodeResponse(node, nodeState);
|
||||
});
|
||||
const domainSpecificNodes: DomainSpecificNodeResponse[] = realNodes.map(
|
||||
(node) => {
|
||||
const nodeState: NodeStateData = nodeStateByMac[node.mac] || {};
|
||||
return toDomainSpecificNodeResponse(node, nodeState);
|
||||
}
|
||||
);
|
||||
|
||||
const filteredNodes = Resources.filter<DomainSpecificNodeResponse>(
|
||||
domainSpecificNodes,
|
||||
[
|
||||
'hostname',
|
||||
'nickname',
|
||||
'email',
|
||||
'token',
|
||||
'mac',
|
||||
'site',
|
||||
'domain',
|
||||
'key',
|
||||
'onlineState'
|
||||
"hostname",
|
||||
"nickname",
|
||||
"email",
|
||||
"token",
|
||||
"mac",
|
||||
"site",
|
||||
"domain",
|
||||
"key",
|
||||
"onlineState",
|
||||
],
|
||||
restParams
|
||||
);
|
||||
|
@ -141,13 +154,13 @@ async function doGetAll(req: Request): Promise<{ total: number; pageNodes: any }
|
|||
);
|
||||
const pageNodes = Resources.getPageEntities(sortedNodes, restParams);
|
||||
|
||||
return {total, pageNodes};
|
||||
return { total, pageNodes };
|
||||
}
|
||||
|
||||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then((result: { total: number, pageNodes: any[] }) => {
|
||||
res.set('X-Total-Count', result.total.toString(10));
|
||||
.then((result: { total: number; pageNodes: any[] }) => {
|
||||
res.set("X-Total-Count", result.total.toString(10));
|
||||
return Resources.success(res, result.pageNodes);
|
||||
})
|
||||
.catch((err: any) => Resources.error(res, err));
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import ErrorTypes from "../utils/errorTypes";
|
||||
import Logger from "../logger";
|
||||
import {getNodeStatistics} from "../services/nodeService";
|
||||
import {handleJSON} from "../utils/resources";
|
||||
import { getNodeStatistics } from "../services/nodeService";
|
||||
import { handleJSON } from "../utils/resources";
|
||||
|
||||
export const get = handleJSON(async () => {
|
||||
try {
|
||||
const nodeStatistics = await getNodeStatistics();
|
||||
return {
|
||||
nodes: nodeStatistics
|
||||
nodes: nodeStatistics,
|
||||
};
|
||||
} catch (error) {
|
||||
Logger.tag('statistics').error('Error getting statistics:', error);
|
||||
throw {data: 'Internal error.', type: ErrorTypes.internalError};
|
||||
Logger.tag("statistics").error("Error getting statistics:", error);
|
||||
throw { data: "Internal error.", type: ErrorTypes.internalError };
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import CONSTRAINTS from "../shared/validation/constraints";
|
||||
import ErrorTypes from "../utils/errorTypes";
|
||||
import * as Resources from "../utils/resources";
|
||||
import {handleJSONWithData, RequestData} from "../utils/resources";
|
||||
import {getTasks, Task, TaskState} from "../jobs/scheduler";
|
||||
import {normalizeString} from "../shared/utils/strings";
|
||||
import {forConstraint} from "../shared/validation/validator";
|
||||
import {Request, Response} from "express";
|
||||
import {isString, isTaskSortField} from "../types";
|
||||
import { handleJSONWithData, RequestData } from "../utils/resources";
|
||||
import { getTasks, Task, TaskState } from "../jobs/scheduler";
|
||||
import { normalizeString } from "../shared/utils/strings";
|
||||
import { forConstraint } from "../shared/validation/validator";
|
||||
import { Request, Response } from "express";
|
||||
import { isString, isTaskSortField } from "../types";
|
||||
|
||||
const isValidId = forConstraint(CONSTRAINTS.id, false);
|
||||
|
||||
|
@ -22,7 +22,7 @@ type TaskResponse = {
|
|||
result: string | null;
|
||||
message: string | null;
|
||||
enabled: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
function toTaskResponse(task: Task): TaskResponse {
|
||||
return {
|
||||
|
@ -34,20 +34,26 @@ function toTaskResponse(task: Task): TaskResponse {
|
|||
lastRunStarted: task.lastRunStarted && task.lastRunStarted.unix(),
|
||||
lastRunDuration: task.lastRunDuration || null,
|
||||
state: task.state,
|
||||
result: task.state !== TaskState.RUNNING && task.result ? task.result.state : null,
|
||||
message: task.state !== TaskState.RUNNING && task.result ? task.result.message || null : null,
|
||||
enabled: task.enabled
|
||||
result:
|
||||
task.state !== TaskState.RUNNING && task.result
|
||||
? task.result.state
|
||||
: null,
|
||||
message:
|
||||
task.state !== TaskState.RUNNING && task.result
|
||||
? task.result.message || null
|
||||
: null,
|
||||
enabled: task.enabled,
|
||||
};
|
||||
}
|
||||
|
||||
async function withValidTaskId(data: RequestData): Promise<string> {
|
||||
if (!isString(data.id)) {
|
||||
throw {data: 'Missing task id.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Missing task id.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
const id = normalizeString(data.id);
|
||||
|
||||
if (!isValidId(id)) {
|
||||
throw {data: 'Invalid task id.', type: ErrorTypes.badRequest};
|
||||
throw { data: "Invalid task id.", type: ErrorTypes.badRequest };
|
||||
}
|
||||
|
||||
return id;
|
||||
|
@ -58,7 +64,7 @@ async function getTask(id: string): Promise<Task> {
|
|||
const task = tasks[id];
|
||||
|
||||
if (!task) {
|
||||
throw {data: 'Task not found.', type: ErrorTypes.notFound};
|
||||
throw { data: "Task not found.", type: ErrorTypes.notFound };
|
||||
}
|
||||
|
||||
return task;
|
||||
|
@ -69,14 +75,19 @@ async function withTask(data: RequestData): Promise<Task> {
|
|||
return await getTask(id);
|
||||
}
|
||||
|
||||
async function setTaskEnabled(data: RequestData, enable: boolean): Promise<TaskResponse> {
|
||||
async function setTaskEnabled(
|
||||
data: RequestData,
|
||||
enable: boolean
|
||||
): Promise<TaskResponse> {
|
||||
const task = await withTask(data);
|
||||
task.enabled = enable;
|
||||
return toTaskResponse(task);
|
||||
}
|
||||
|
||||
async function doGetAll(req: Request): Promise<{ total: number, pageTasks: Task[] }> {
|
||||
const restParams = await Resources.getValidRestParams('list', null, req);
|
||||
async function doGetAll(
|
||||
req: Request
|
||||
): Promise<{ total: number; pageTasks: Task[] }> {
|
||||
const restParams = await Resources.getValidRestParams("list", null, req);
|
||||
|
||||
const tasks = Resources.sort(
|
||||
Object.values(getTasks()),
|
||||
|
@ -85,7 +96,7 @@ async function doGetAll(req: Request): Promise<{ total: number, pageTasks: Task[
|
|||
);
|
||||
const filteredTasks = Resources.filter(
|
||||
tasks,
|
||||
['id', 'name', 'schedule', 'state'],
|
||||
["id", "name", "schedule", "state"],
|
||||
restParams
|
||||
);
|
||||
|
||||
|
@ -100,28 +111,28 @@ async function doGetAll(req: Request): Promise<{ total: number, pageTasks: Task[
|
|||
|
||||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then(({total, pageTasks}) => {
|
||||
res.set('X-Total-Count', total.toString(10));
|
||||
.then(({ total, pageTasks }) => {
|
||||
res.set("X-Total-Count", total.toString(10));
|
||||
Resources.success(res, pageTasks.map(toTaskResponse));
|
||||
})
|
||||
.catch(err => Resources.error(res, err));
|
||||
.catch((err) => Resources.error(res, err));
|
||||
}
|
||||
|
||||
export const run = handleJSONWithData(async data => {
|
||||
export const run = handleJSONWithData(async (data) => {
|
||||
const task = await withTask(data);
|
||||
|
||||
if (task.runningSince) {
|
||||
throw {data: 'Task already running.', type: ErrorTypes.conflict};
|
||||
throw { data: "Task already running.", type: ErrorTypes.conflict };
|
||||
}
|
||||
|
||||
task.run();
|
||||
return toTaskResponse(task);
|
||||
});
|
||||
|
||||
export const enable = handleJSONWithData(async data => {
|
||||
export const enable = handleJSONWithData(async (data) => {
|
||||
await setTaskEnabled(data, true);
|
||||
});
|
||||
|
||||
export const disable = handleJSONWithData(async data => {
|
||||
export const disable = handleJSONWithData(async (data) => {
|
||||
await setTaskEnabled(data, false);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {handleJSON} from "../utils/resources";
|
||||
import {version} from "../config";
|
||||
import { handleJSON } from "../utils/resources";
|
||||
import { version } from "../config";
|
||||
|
||||
export const get = handleJSON(async () => ({
|
||||
version
|
||||
version,
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue