feat: optional tariff price
This commit is contained in:
parent
a8b7bbc02a
commit
79de4ae1ca
@ -4,17 +4,13 @@ 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
|
||||
);
|
||||
const [validatedTariff, errorEmpty] = validateEmptyFields(tariff ?? {}, ["isCustom", "name", "privilegies"], false);
|
||||
|
||||
if (errorEmpty) {
|
||||
return [validatedTariff, errorEmpty];
|
||||
}
|
||||
|
||||
if (isNaN(Number(validatedTariff.price))) {
|
||||
if (validatedTariff.price && isNaN(Number(validatedTariff.price))) {
|
||||
return [validatedTariff, new Error("invalid 'price' value")];
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ const schema: SchemaDefinition<Tariff> = {
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
required: true,
|
||||
required: false,
|
||||
},
|
||||
isCustom: {
|
||||
type: Boolean,
|
||||
|
@ -29,7 +29,7 @@ export const getTariffsQuerystring: SwaggerMessage = {
|
||||
export const tariffBody: SwaggerMessage = {
|
||||
type: "object",
|
||||
description: "Тариф",
|
||||
required: ["name", "price", "isCustom", "privilegies"],
|
||||
required: ["name", "isCustom", "privilegies"],
|
||||
properties: {
|
||||
name: { type: "string" },
|
||||
price: { type: "number" },
|
||||
|
@ -3,7 +3,7 @@ import type { Eloquent } from "./eloquent.type";
|
||||
|
||||
export type Tariff = Eloquent & {
|
||||
name: string;
|
||||
price: number;
|
||||
price?: number;
|
||||
isCustom: boolean;
|
||||
privilegies: Array<Omit<Privilege, keyof Eloquent>>;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user