23 lines
707 B
TypeScript
23 lines
707 B
TypeScript
![]() |
import { validateEmptyFields } from "@/utils/validate-empty-fields";
|
||
|
|
||
|
import type { TariffMessage } from "@/types/messages/tariff-message.type";
|
||
|
import type { ObjectWithRequiredFields } from "@/types/object-with-required-fields";
|
||
|
|
||
|
export const validateTariff = (tariff: TariffMessage): [ObjectWithRequiredFields<TariffMessage>, Error | null] => {
|
||
|
const [validatedTariff, errorEmpty] = validateEmptyFields(
|
||
|
tariff,
|
||
|
["isCustom", "name", "price", "privilegies"],
|
||
|
false
|
||
|
);
|
||
|
|
||
|
if (errorEmpty) {
|
||
|
return [validatedTariff, errorEmpty];
|
||
|
}
|
||
|
|
||
|
if (isNaN(Number(validatedTariff.price))) {
|
||
|
return [validatedTariff, new Error("invalid 'price' value")];
|
||
|
}
|
||
|
|
||
|
return [validatedTariff, null];
|
||
|
};
|