@@ -44,19 +44,19 @@ handlers._users.post = (data, callback) => {
44
44
// check that all required fields are filled out
45
45
const firstName = helpers . requiredParamValidator ( data , 'firstName' , {
46
46
type : 'string' ,
47
- minLength : 1
47
+ minLength : 1 ,
48
48
} ) ;
49
49
const lastName = helpers . requiredParamValidator ( data , 'lastName' , {
50
50
type : 'string' ,
51
- minLength : 1
51
+ minLength : 1 ,
52
52
} ) ;
53
53
const phone = helpers . requiredParamValidator ( data , 'phone' , {
54
54
type : 'string' ,
55
- exactLength : 12
55
+ exactLength : 12 ,
56
56
} ) ;
57
57
const password = helpers . requiredParamValidator ( data , 'password' , {
58
58
type : 'string' ,
59
- minLength : 1
59
+ minLength : 1 ,
60
60
} ) ;
61
61
const tosAgreement = helpers . requiredParamValidator ( data , 'tosAgreement' , { type : 'boolean' } ) ;
62
62
@@ -102,25 +102,25 @@ handlers._users.post = (data, callback) => {
102
102
handlers . _users . put = ( data , callback ) => {
103
103
const firstName = helpers . requiredParamValidator ( data , 'firstName' , {
104
104
type : 'string' ,
105
- minLength : 1
105
+ minLength : 1 ,
106
106
} ) ;
107
107
const lastName = helpers . requiredParamValidator ( data , 'lastName' , {
108
108
type : 'string' ,
109
- minLength : 1
109
+ minLength : 1 ,
110
110
} ) ;
111
111
const phone = helpers . requiredParamValidator ( data , 'phone' , {
112
112
type : 'string' ,
113
- exactLength : 12
113
+ exactLength : 12 ,
114
114
} ) ;
115
115
const password = helpers . requiredParamValidator ( data , 'password' , {
116
116
type : 'string' ,
117
- minLength : 1
117
+ minLength : 1 ,
118
118
} ) ;
119
119
120
- const token = typeof ( data . headers . token ) === "string" ? data . headers . token : false ;
121
- handlers . _tokens . verifyToken ( token , phoneValidated , ( tokenIsValid ) => {
122
- if ( tokenIsValid ) {
123
- if ( phone ) {
120
+ if ( phone ) {
121
+ const token = typeof ( data . headers . token ) === "string" ? data . headers . token : false ;
122
+ handlers . _tokens . verifyToken ( token , phone , ( tokenIsValid ) => {
123
+ if ( tokenIsValid ) {
124
124
if ( firstName || lastName || password ) {
125
125
DataLibrary . read ( 'users' , phone , ( err , data ) => {
126
126
if ( ! err && data ) {
@@ -150,12 +150,12 @@ handlers._users.put = (data, callback) => {
150
150
callback ( 400 , { 'Error' : "One field at least should be specified" } ) ;
151
151
}
152
152
} else {
153
- callback ( 400 , { ' Error' : "Missing required fields " } ) ;
153
+ callback ( 403 , { " Error" : "Missing required token in header or token is invalid " } )
154
154
}
155
- } else {
156
- callback ( 403 , { "Error" : "Missing required token in header or token is invalid" } )
157
- }
158
- } ) ;
155
+ } ) ;
156
+ } else {
157
+ callback ( 400 , { 'Error' : "Missing required fields" } ) ;
158
+ }
159
159
} ;
160
160
161
161
// Required fields: phone
@@ -216,12 +216,12 @@ handlers._tokens.get = (data, callback) => {
216
216
handlers . _tokens . post = ( data , callback ) => {
217
217
const phone = helpers . requiredParamValidator ( data , 'phone' , {
218
218
type : 'string' ,
219
- exactLength : 12
219
+ exactLength : 12 ,
220
220
} ) ;
221
221
222
222
const password = helpers . requiredParamValidator ( data , 'password' , {
223
223
type : 'string' ,
224
- minLength : 1
224
+ minLength : 1 ,
225
225
} ) ;
226
226
227
227
if ( phone && password ) {
0 commit comments