40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { BodyValidator, Validator } from "sim-shared/aplication/BodyValidator.js";
|
|
|
|
const iccidNotNull = <Validator<{ iccid: unknown }>>{
|
|
field: "iccid",
|
|
errorMsg: "El iccid no está definido",
|
|
validationFunc: (a: { iccid: unknown }) => {
|
|
return (a.iccid != null && a.iccid != undefined)
|
|
}
|
|
}
|
|
|
|
const iccidValueOrArray = <Validator<{ iccid: unknown }>>{
|
|
field: "iccid",
|
|
errorMsg: "El iccid debe de ser un único valor o una lista",
|
|
validationFunc: (a: { iccid: unknown }) => {
|
|
return (typeof a.iccid == "string" || Array.isArray(a.iccid))
|
|
}
|
|
}
|
|
|
|
const iccidLongitudValidator = <Validator<{ iccid: string | string[] }>>{
|
|
field: "iccid",
|
|
errorMsg: "La longitud del iccid/s es incorrecta debera ser de 19 caracteres",
|
|
validationFunc: (a: { iccid: string | string[] }) => {
|
|
if (Array.isArray(a.iccid)) {
|
|
const res = (a.iccid as string[]).filter(e => e.length != 19)
|
|
if (res.length > 0) return false;
|
|
} else {
|
|
return (a.iccid as string).length == 19
|
|
}
|
|
},
|
|
}
|
|
|
|
export const iccidValidator = new BodyValidator<{ iccid: string | string[] }>(
|
|
[
|
|
iccidNotNull,
|
|
iccidValueOrArray,
|
|
iccidLongitudValidator,
|
|
]
|
|
)
|
|
|