Remove duplicate code for parsing numbers.

This commit is contained in:
baldo 2022-09-20 19:11:36 +02:00
parent 15d3f45bae
commit b1075aa2ec
6 changed files with 181 additions and 35 deletions
server/resources

View file

@ -3,11 +3,12 @@ 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 { normalizeString } 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";
import { parseToInteger } from "../shared/utils/numbers";
const isValidId = forConstraint(CONSTRAINTS.id, false);
@ -22,7 +23,7 @@ async function withValidMailId(data: RequestData): Promise<MailId> {
throw { data: "Invalid mail id.", type: ErrorTypes.badRequest };
}
return parseInteger(id) as MailId;
return parseToInteger(id) as MailId;
}
export const get = handleJSONWithData(async (data) => {