-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.js
70 lines (63 loc) · 1.8 KB
/
globals.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
class Validator {
constructor(model){
this.truth = model.schema.obj;
}
isTopNull(T, detail) {
if(!T) return false;
let keys = Object.keys(T);
keys.forEach(k => {
if(!detail[k]) return false;
});
return true;
}
verify(detail){
return !this.isTopNull(this.truth, detail);
}
}
class BathroomValidator extends Validator{
constructor(){
super(require('./models/bathroom'));
}
verify(detail){
let valid = !this.isTopNull(this.truth, detail);
if(!valid) return null;
valid = !this.isTopNull(this.truth.location, detail.location);
if(!valid) return null;
let errors = [];
let _ = detail.location;
if(_.buildingName.length >= 20) errors.push("Building name should be less than 20 characters");
if(_.street.length >= 20) errors.push("Street should be less than 20 characters");
if(_.city.length >= 20) errors.push("City should be less than 20 characters");
if(_.state.length !== 2) errors.push("State should be 2 characters long. (Use state code)");
if(_.zip.length !== 5 && !isNaN(parseInt(_.zip))) errors.push("Zip code should be 5 numbers long.");
}
}
module.exports = {
BRTag: {
AllGender: "ALL_GENDER",
FamilyFriendly: "FAMILY_FRIENDLY"
},
Key: {
Google: {
API: "AIzaSyDJmWU0PG7G_uCmW5NCEeLSwA0tw1K7ers"
}
},
URL: {
Geocoding: "https://maps.googleapis.com/maps/api/geocode/json",
Places: "https://maps.googleapis.com/maps/api/place/nearbysearch/json",
Place: "https://maps.googleapis.com/maps/api/place/details/json"
},
onError: (err, res, customMessage) => {
if(err) {
let error = {
err: err,
msg: customMessage
};
console.error(error);
res.json(error);
return true;
}
},
Validator: Validator,
BathroomValidator: BathroomValidator
};