-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSONValidator.js
140 lines (130 loc) · 3.45 KB
/
JSONValidator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Validator } from "jsonschema";
var v = new Validator();
function validateJSON(req, schema){
const incomingSchema = req.body;
const result = v.validate(incomingSchema, schema);
console.log(result.valid);
return result.valid;
}
function usersignupJV(req, res, next){
const schema1 = {
"id": "/signup",
"type": "object",
"properties" : {
"Name": {"type": "string"},
"Contact": {"type": "number"},
"Username": {"type": "string"},
"Password": {"type": "string"}
},
"required": ["Name", "Contact", "Username", "Password"]
};
const response = validateJSON(req, schema1);
if(response === true){
next();
}
else{
res.status(403).send("Invalid Input Format");
}
}
function usersigninJV(req, res, next){
const schema2 = {
"id": "/signin",
"type": "object",
"properties" : {
"Username": {"type": "string"},
"Password": {"type": "string"}
},
"required": ["Username", "Password"]
};
const response = validateJSON(req, schema2);
if(response === true){
next();
}
else{
res.status(403).send("Invalid Input Format");
}
}
function modifyAnimalJV(req, res, next){
const schema3 = {
"id": "/modify",
"type": "object",
"properties" : {
"Animalid": {"type": "string"},
"Name": {"type": "string"},
"HealthCondition": {"type": "string"},
"Status": {"type": "string"},
"OtherInformation": {"type": "string"}
},
"required": ["Animalid", "Name", "HealthCondition", "Status", "OtherInformation"]
};
const response = validateJSON(req, schema3);
if(response === true){
next();
}
else{
res.status(403).send("Invalid Input Format");
}
}
function modifyGeofenceJV(req, res, next){
const schema4 = {
"id": "/modifyGeofence",
"type": "object",
"properties" : {
"Animalid": {"type": "string"},
"Center" : {"type": "number"},
"Radius" : {"type": "number"}
},
"required": ["Animalid", "Center", "Radius"]
};
const response = validateJSON(req, schema4);
if(response === true){
next();
}
else{
res.status(403).send("Invalid Input Format");
}
}
function particularAnimalDetailJV(req, res, next){
const schema5 = {
"id": "/pad",
"type": "object",
"properties" : {
"Animalid": {"type": "string"}
},
"required": ["Animalid"]
};
const response = validateJSON(req, schema5);
if(response === true){
next();
}
else{
res.status(403).send("Invalid Input Format");
}
}
function particularAnimalHistoryJV(req, res, next){
const schema6 = {
"id": "/modifyGeofence",
"type": "object",
"properties" : {
"Animalid": {"type": "string"},
"StartDate" : {"type": "date"},
"EndDate" : {"type": "date"}
},
"required": ["Animalid", "StartDate", "EndDate"]
};
const response = validateJSON(req, schema6);
if(response === true){
next();
}
else{
res.status(403).send("Invalid Input Format");
}
}
export default {
usersignupJV,
usersigninJV,
modifyAnimalJV,
modifyGeofenceJV,
particularAnimalDetailJV,
particularAnimalHistoryJV
};