Refactor some server-side string types into newtypes.
This commit is contained in:
parent
6c2bd85287
commit
720acfb276
10 changed files with 346 additions and 225 deletions
server/resources
|
@ -7,6 +7,7 @@ import * as Resources from "../utils/resources";
|
|||
import {normalizeString} from "../utils/strings";
|
||||
import {forConstraint} from "../validation/validator";
|
||||
import {Request, Response} from "express";
|
||||
import {MonitoringToken, to} from "../types";
|
||||
|
||||
const isValidToken = forConstraint(CONSTRAINTS.token, false);
|
||||
|
||||
|
@ -38,8 +39,9 @@ export function confirm(req: Request, res: Response): void {
|
|||
if (!isValidToken(token)) {
|
||||
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
const validatedToken: MonitoringToken = to(token);
|
||||
|
||||
MonitoringService.confirm(token)
|
||||
MonitoringService.confirm(validatedToken)
|
||||
.then(node => Resources.success(res, {
|
||||
hostname: node.hostname,
|
||||
mac: node.mac,
|
||||
|
@ -57,8 +59,9 @@ export function disable(req: Request, res: Response): void {
|
|||
if (!isValidToken(token)) {
|
||||
return Resources.error(res, {data: 'Invalid token.', type: ErrorTypes.badRequest});
|
||||
}
|
||||
const validatedToken: MonitoringToken = to(token);
|
||||
|
||||
MonitoringService.disable(token)
|
||||
MonitoringService.disable(validatedToken)
|
||||
.then(node => Resources.success(res, {
|
||||
hostname: node.hostname,
|
||||
mac: node.mac,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue