-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
32 lines (30 loc) · 1.08 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { ErrorResponse } from "./models/error"
export function getInvalidUsernameErrorResponse(username: string): ErrorResponse {
let errorResponse: ErrorResponse
if (!username.match(/^[0-9A-Za-z]+$/)) {
errorResponse = {
errorCode: 400,
errorMessage: `Invalid username ${username}. Username can only contain digits or alphabets`
}
return errorResponse
}
return null
}
export function checkValidNum(number: any, paramName: string): ErrorResponse {
if (number !== undefined) {
let value = Number(number)
if (isNaN(number)) {
return {
errorCode: 400,
errorMessage: `The provided ${paramName} value ${value} is not a number, please provide a correct limit numeric value greater than zero`
}
}
if (value < 0) {
return {
errorCode: 400,
errorMessage: `The provided ${paramName} value should be greater than or equal to zero, but you have provided ${number}`
}
}
}
return null
}