Skip to content
This repository was archived by the owner on Sep 20, 2025. It is now read-only.

Commit 4b0e798

Browse files
committed
Improve global validation checks
1 parent e004b16 commit 4b0e798

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/models/v1/user.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ module.exports = (sequelize, DataTypes) => {
270270
static getRegisterError(bodyInput) {
271271
if (undefined === bodyInput.firstName) {
272272
return "The first name field is missing.";
273-
} else if (typeof bodyInput.firstName !== "string") {
273+
} else if ("string" !== typeof bodyInput.firstName) {
274274
return "The first name field must be of type string";
275275
} else if (20 < bodyInput.firstName.trim().length) {
276276
return "The first name field length must not exceed 20 characters.";
@@ -280,7 +280,7 @@ module.exports = (sequelize, DataTypes) => {
280280

281281
if (undefined === bodyInput.lastName) {
282282
return "The last name field is missing.";
283-
} else if (typeof bodyInput.lastName !== "string") {
283+
} else if ("string" !== typeof bodyInput.lastName) {
284284
return "The last name field must be of type string";
285285
} else if (20 < bodyInput.lastName.trim().length) {
286286
return "The last name field length must not exceed 20 characters.";
@@ -290,7 +290,7 @@ module.exports = (sequelize, DataTypes) => {
290290

291291
if (undefined === bodyInput.email) {
292292
return "The email field is missing.";
293-
} else if (typeof bodyInput.email !== "string") {
293+
} else if ("string" !== typeof bodyInput.email) {
294294
return "The email field must be of type string";
295295
} else if (30 < bodyInput.email.length) {
296296
return "The email field length must not exceed 30 characters.";
@@ -300,7 +300,7 @@ module.exports = (sequelize, DataTypes) => {
300300

301301
if (undefined === bodyInput.password) {
302302
return "The password field is missing.";
303-
} else if (typeof bodyInput.password !== "string") {
303+
} else if ("string" !== typeof bodyInput.password) {
304304
return "The password field must be of type string";
305305
} else if (20 < bodyInput.password.length) {
306306
return "The password field length must not exceed 20 characters.";
@@ -506,7 +506,7 @@ module.exports = (sequelize, DataTypes) => {
506506
static getLoginError(bodyInput) {
507507
if (undefined === bodyInput.email) {
508508
return "The email field is missing.";
509-
} else if (typeof bodyInput.email !== "string") {
509+
} else if ("string" !== typeof bodyInput.email) {
510510
return "The email field must be of type string";
511511
} else if (30 < bodyInput.email.length) {
512512
return "The email field length must not exceed 30 characters.";
@@ -516,7 +516,7 @@ module.exports = (sequelize, DataTypes) => {
516516

517517
if (undefined === bodyInput.password) {
518518
return "The password field is missing.";
519-
} else if (typeof bodyInput.password !== "string") {
519+
} else if ("string" !== typeof bodyInput.password) {
520520
return "The password field must be of type string";
521521
} else if (20 < bodyInput.password.length) {
522522
return "The password field length must not exceed 20 characters.";

src/models/v1/userAddress.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,32 @@ module.exports = (sequelize, DataTypes) => {
151151
static async getNewUserAddressError(usersId, payload) {
152152
if (!payload.addressLine1) {
153153
return "The address line 1 field is required.";
154+
} else if ("string" !== typeof payload.addressLine1) {
155+
return "The address line 1 field must be of type string.";
156+
}
157+
158+
if (payload.addressLine2) {
159+
if ("string" !== typeof payload.addressLine2) {
160+
return "The address line 2 field must be of type string.";
161+
}
154162
}
155163

156164
if (!payload.zipCode) {
157165
return "The zip code field is required.";
166+
} else if ("string" !== typeof payload.zipCode) {
167+
return "The zip code field must be of type string.";
158168
}
159169

160170
if (!payload.city) {
161171
return "The city field is required.";
172+
} else if ("string" !== typeof payload.city) {
173+
return "The city field must be of type string.";
162174
}
163175

164176
if (!payload.state) {
165177
return "The state field is required.";
178+
} else if ("string" !== typeof payload.state) {
179+
return "The state field must be of type string.";
166180
}
167181

168182
if (payload.telephoneAreaCode) {

0 commit comments

Comments
 (0)