Fixed compile errors.

This commit is contained in:
baldo 2022-07-21 18:49:49 +02:00
parent 250353edbf
commit a1f27a9f64
2 changed files with 12 additions and 8 deletions

View file

@ -8,7 +8,7 @@ import {handleJSONWithData} from "../utils/resources";
import {normalizeString} from "../utils/strings";
import {forConstraint} from "../validation/validator";
import {Request, Response} from "express";
import {MonitoringResponse, MonitoringToken, toMonitoringResponse} from "../types";
import {isMonitoringToken, JSONObject, MonitoringResponse, MonitoringToken, toMonitoringResponse} from "../types";
const isValidToken = forConstraint(CONSTRAINTS.token, false);
@ -33,23 +33,26 @@ export function getAll(req: Request, res: Response): void {
.catch(err => Resources.error(res, err));
}
export const confirm = handleJSONWithData<MonitoringResponse>(async data => {
function getValidatedToken(data: JSONObject): MonitoringToken {
if (!isMonitoringToken(data.token)) {
throw {data: 'Missing token.', type: ErrorTypes.badRequest};
}
const token = normalizeString(data.token);
if (!isValidToken(token)) {
throw {data: 'Invalid token.', type: ErrorTypes.badRequest};
}
const validatedToken: MonitoringToken = token as MonitoringToken;
return token as MonitoringToken;
}
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 => {
const token = normalizeString(data.token);
if (!isValidToken(token)) {
throw {data: 'Invalid token.', type: ErrorTypes.badRequest};
}
const validatedToken: MonitoringToken = token as MonitoringToken;
const validatedToken: MonitoringToken = getValidatedToken(data);
const node = await MonitoringService.disable(validatedToken);
return toMonitoringResponse(node);

View file

@ -337,6 +337,7 @@ export function toUnixTimestampSeconds(ms: UnixTimestampMilliseconds): UnixTimes
}
export type MonitoringToken = string & { readonly __tag: unique symbol };
export const isMonitoringToken = isString;
export enum MonitoringState {
ACTIVE = "active",