import { BodyValidator, Validator } from "sim-shared/aplication/BodyValidator.js"; const iccidNotNull = >{ field: "iccid", errorMsg: "El iccid no está definido", validationFunc: (a: { iccid: unknown }) => { return (a.iccid != null && a.iccid != undefined) } } const iccidValueOrArray = >{ 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 = >{ 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, ] )