getzero11 commited on
Commit
e70f810
·
verified ·
1 Parent(s): 92c04c0

Create src/schema/dashboard.schema.js

Browse files
Files changed (1) hide show
  1. src/schema/dashboard.schema.js +39 -0
src/schema/dashboard.schema.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function validateDashboard(d) {
2
+ if (!d) throw new Error("dashboard_view missing");
3
+
4
+ if (!d.marketTitle) {
5
+ throw new Error("dashboard_view.marketTitle missing");
6
+ }
7
+
8
+ if (!d.marketSummary) {
9
+ throw new Error("dashboard_view.marketSummary missing");
10
+ }
11
+
12
+ const ms = d.marketSummary;
13
+ requireNumber(ms.past2023, "past2023");
14
+ requireNumber(ms.current2025, "current2025");
15
+ requireNumber(ms.forecast2033, "forecast2033");
16
+ requireNumber(ms.cagr, "cagr");
17
+
18
+ if (!Array.isArray(d.forecast)) {
19
+ throw new Error("dashboard_view.forecast must be array");
20
+ }
21
+
22
+ if (!Array.isArray(d.regional)) {
23
+ throw new Error("dashboard_view.regional must be array");
24
+ }
25
+
26
+ if (!Array.isArray(d.segments)) {
27
+ throw new Error("dashboard_view.segments must be array");
28
+ }
29
+
30
+ if (!Array.isArray(d.competitive)) {
31
+ throw new Error("dashboard_view.competitive must be array");
32
+ }
33
+ }
34
+
35
+ function requireNumber(value, name) {
36
+ if (typeof value !== "number" || Number.isNaN(value)) {
37
+ throw new Error(`dashboard_view.marketSummary.${name} must be number`);
38
+ }
39
+ }