Create src/schema/report.schema.js
Browse files- src/schema/report.schema.js +35 -0
src/schema/report.schema.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function validateReport(r) {
|
| 2 |
+
if (!r) throw new Error("report_view missing");
|
| 3 |
+
|
| 4 |
+
if (!r.marketTitle) {
|
| 5 |
+
throw new Error("report_view.marketTitle missing");
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
if (!r.marketSizing) {
|
| 9 |
+
throw new Error("report_view.marketSizing missing");
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
const ms = r.marketSizing;
|
| 13 |
+
requireNumber(ms.pastYear_2023, "pastYear_2023");
|
| 14 |
+
requireNumber(ms.currentYear_2025, "currentYear_2025");
|
| 15 |
+
requireNumber(ms.forecastYear_2033, "forecastYear_2033");
|
| 16 |
+
requireNumber(ms.global_cagr_Forecast, "global_cagr_Forecast");
|
| 17 |
+
|
| 18 |
+
if (!Array.isArray(r.marketSegments)) {
|
| 19 |
+
throw new Error("report_view.marketSegments must be array");
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if (!Array.isArray(r.marketDrivers)) {
|
| 23 |
+
throw new Error("report_view.marketDrivers must be array");
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
if (!Array.isArray(r.strategicRecommendations)) {
|
| 27 |
+
throw new Error("report_view.strategicRecommendations must be array");
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function requireNumber(value, name) {
|
| 32 |
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
| 33 |
+
throw new Error(`report_view.marketSizing.${name} must be number`);
|
| 34 |
+
}
|
| 35 |
+
}
|