51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { companyFromIccid } from "#domain/companies.js";
|
|
import { BodyValidator, Validator } from "sim-shared/aplication/BodyValidator.js";
|
|
|
|
const offers = new Map([
|
|
["mensual", "SAVEFAMILY1"],
|
|
["anual", "SAVEFAMILY2"]
|
|
])
|
|
|
|
const iccidLongitudValidator = <Validator<{ iccid: string }>>{
|
|
field: "iccid",
|
|
errorMsg: "La longitud del iccid es incorrecta debera ser de 19 caracteres",
|
|
validationFunc: (a: { iccid: string }) => a.iccid.length == 19,
|
|
}
|
|
|
|
const iccidRequired = <Validator<{ iccid: string }>>{
|
|
field: "iccid",
|
|
errorMsg: "El iccid debe estara definido",
|
|
validationFunc: (a: { iccid: string }) => a.iccid != undefined,
|
|
}
|
|
|
|
const iccidWithValidCompany = <Validator<{ iccid: string }>>{
|
|
field: "iccid",
|
|
errorMsg: "El iccid no corresponde a una compañia registrada",
|
|
validationFunc: (a: { iccid: string }) => companyFromIccid(a.iccid) != undefined,
|
|
}
|
|
|
|
|
|
const offerExists = <Validator<{ offer: string }>>{
|
|
field: "offer",
|
|
errorMsg: "La oferta introducida no es valida",
|
|
validationFunc: (a: { offer: string }) => offers.has(a.offer),
|
|
}
|
|
|
|
|
|
export const activationValidator = new BodyValidator<{ iccid: string, offer: string }>(
|
|
[
|
|
iccidRequired,
|
|
iccidLongitudValidator,
|
|
iccidWithValidCompany,
|
|
offerExists,
|
|
]
|
|
)
|
|
|
|
export const iccidValidator = new BodyValidator<{ iccid: string, offer: string }>(
|
|
[
|
|
iccidRequired,
|
|
iccidLongitudValidator,
|
|
iccidWithValidCompany,
|
|
]
|
|
)
|