2024-05-12 21:25:52 +02:00
|
|
|
import * as yup from "yup";
|
|
|
|
import YupPassword from "yup-password";
|
2024-05-03 01:46:23 +02:00
|
|
|
YupPassword(yup);
|
2024-05-12 21:25:52 +02:00
|
|
|
import { Schema } from "mongoose";
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
interface mongooseAddition {
|
|
|
|
_id?: Schema.Types.ObjectId;
|
|
|
|
createdAt?: Schema.Types.Date;
|
|
|
|
updatedAt?: Schema.Types.Date;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create
|
|
|
|
export const add = yup.object({
|
|
|
|
brand: yup.string().required(),
|
|
|
|
name: yup.string().required(),
|
|
|
|
degree: yup.number().required(),
|
2024-05-12 21:25:52 +02:00
|
|
|
packaging: yup.string().required(),
|
2024-05-03 01:46:23 +02:00
|
|
|
});
|
|
|
|
export interface IBeer extends yup.InferType<typeof add>, mongooseAddition {}
|
|
|
|
export const addExam: IBeer = {
|
2024-05-12 21:25:52 +02:00
|
|
|
brand: "Pilsner Urqell",
|
|
|
|
name: "Kozel",
|
2024-05-03 01:46:23 +02:00
|
|
|
degree: 11,
|
2024-05-12 21:25:52 +02:00
|
|
|
packaging: "can",
|
2024-05-03 01:46:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Remove
|
|
|
|
export const del = yup.object({
|
2024-05-12 21:25:52 +02:00
|
|
|
_id: yup.string().required(),
|
2024-05-03 01:46:23 +02:00
|
|
|
});
|
|
|
|
export interface IDel extends yup.InferType<typeof del> {}
|
|
|
|
export const delExam: IDel = {
|
2024-05-12 21:25:52 +02:00
|
|
|
_id: "6352b303b71cb62222f39895",
|
2024-05-03 01:46:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update
|
|
|
|
export const edit = yup.object({
|
|
|
|
_id: yup.string().required(),
|
|
|
|
brand: yup.string(),
|
|
|
|
name: yup.string(),
|
|
|
|
degree: yup.number(),
|
|
|
|
packaging: yup.string(),
|
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
//imgs: yup.mixed().when('$imgs', (imgs, schema) =>
|
|
|
|
// Array.isArray(imgs) ? schema.array() : schema.string()
|
|
|
|
//)
|
2024-05-03 01:46:23 +02:00
|
|
|
|
2024-05-12 21:25:52 +02:00
|
|
|
imgs: yup
|
|
|
|
.mixed()
|
|
|
|
.test(
|
|
|
|
"is-array-or-string",
|
|
|
|
"imgs must be either an array or a string",
|
|
|
|
(value) => Array.isArray(value) || typeof value === "string",
|
|
|
|
),
|
2024-05-03 01:46:23 +02:00
|
|
|
|
|
|
|
//imgs: yup.mixed().when('isArray', {
|
|
|
|
// is: Array.isArray,
|
|
|
|
// then: yup.array(),
|
|
|
|
// otherwise: yup.string()
|
|
|
|
//})
|
|
|
|
});
|
|
|
|
export interface IEdit extends yup.InferType<typeof edit> {}
|
|
|
|
export const editExam: IEdit = {
|
2024-05-12 21:25:52 +02:00
|
|
|
_id: "6355b95dc03fad77bc380146",
|
|
|
|
brand: "Pilsner Urqell",
|
|
|
|
name: "Radegast",
|
2024-05-03 01:46:23 +02:00
|
|
|
degree: 12,
|
2024-05-12 21:25:52 +02:00
|
|
|
packaging: "bottle",
|
|
|
|
imgs: [],
|
2024-05-03 01:46:23 +02:00
|
|
|
};
|