Refactor replace some HTTP related magic values by enums.
This commit is contained in:
parent
c988227bc7
commit
15d3f45bae
9 changed files with 135 additions and 24 deletions
|
@ -7,6 +7,7 @@ import { normalizeString, parseInteger } from "../shared/utils/strings";
|
|||
import { forConstraint } from "../shared/validation/validator";
|
||||
import type { Request, Response } from "express";
|
||||
import { isString, Mail, MailId } from "../types";
|
||||
import { HttpHeader } from "../shared/utils/http";
|
||||
|
||||
const isValidId = forConstraint(CONSTRAINTS.id, false);
|
||||
|
||||
|
@ -39,7 +40,7 @@ async function doGetAll(
|
|||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then(({ total, mails }) => {
|
||||
res.set("X-Total-Count", total.toString(10));
|
||||
res.set(HttpHeader.X_TOTAL_COUNT, total.toString(10));
|
||||
return Resources.success(res, mails);
|
||||
})
|
||||
.catch((err) => Resources.error(res, err));
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
NodeMonitoringStateResponse,
|
||||
toMonitoringResponse,
|
||||
} from "../types";
|
||||
import { HttpHeader } from "../shared/utils/http";
|
||||
|
||||
const isValidToken = forConstraint(CONSTRAINTS.token, false);
|
||||
|
||||
|
@ -33,7 +34,7 @@ async function doGetAll(
|
|||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then(({ total, result }) => {
|
||||
res.set("X-Total-Count", total.toString(10));
|
||||
res.set(HttpHeader.X_TOTAL_COUNT, total.toString(10));
|
||||
Resources.success(res, result);
|
||||
})
|
||||
.catch((err) => Resources.error(res, err));
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
toNodeTokenResponse,
|
||||
} from "../types";
|
||||
import { filterUndefinedFromJSON } from "../shared/utils/json";
|
||||
import { HttpHeader } from "../shared/utils/http";
|
||||
|
||||
const nodeFields = [
|
||||
"hostname",
|
||||
|
@ -165,7 +166,7 @@ export function getAll(req: Request, res: Response): void {
|
|||
total: number;
|
||||
pageNodes: DomainSpecificNodeResponse[];
|
||||
}) => {
|
||||
res.set("X-Total-Count", result.total.toString(10));
|
||||
res.set(HttpHeader.X_TOTAL_COUNT, result.total.toString(10));
|
||||
return Resources.success(
|
||||
res,
|
||||
result.pageNodes.map(filterUndefinedFromJSON)
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
TaskState,
|
||||
UnixTimestampSeconds,
|
||||
} from "../types";
|
||||
import { HttpHeader } from "../shared/utils/http";
|
||||
|
||||
const isValidId = forConstraint(CONSTRAINTS.id, false);
|
||||
|
||||
|
@ -109,7 +110,7 @@ async function doGetAll(
|
|||
export function getAll(req: Request, res: Response): void {
|
||||
doGetAll(req)
|
||||
.then(({ total, pageTasks }) => {
|
||||
res.set("X-Total-Count", total.toString(10));
|
||||
res.set(HttpHeader.X_TOTAL_COUNT, total.toString(10));
|
||||
Resources.success(res, pageTasks.map(toTaskResponse));
|
||||
})
|
||||
.catch((err) => Resources.error(res, err));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue