2023-11-27 23:35:18 +01:00
|
|
|
import Joi from "joi";
|
|
|
|
import { PdfFile } from "./PdfFile";
|
|
|
|
|
2023-12-21 16:42:00 +01:00
|
|
|
export const JoiPDFFileSchema = Joi.binary().custom((value: Express.Multer.File[] | PdfFile | PdfFile[], helpers) => {
|
|
|
|
if (value instanceof PdfFile) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
else if (Array.isArray(value)) {
|
|
|
|
if(value.every((e) => e instanceof PdfFile))
|
|
|
|
return value;
|
|
|
|
else
|
|
|
|
throw new Error("Some elements in the array are not of type PdfFile");
|
|
|
|
}
|
|
|
|
else {
|
2023-11-27 23:35:18 +01:00
|
|
|
try {
|
|
|
|
return PdfFile.fromMulterFiles(value);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
throw new Error('value is not of type PdfFile');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "pdffile validation");
|