From 625b0815bbca8a5f76f7359dca4433a6d1cc9829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 23 Sep 2019 23:51:45 -0400 Subject: [PATCH] refactor: shorter, new Date doesnt throw --- src/user/profile.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/user/profile.js b/src/user/profile.js index 9ce0bcb876..19f7e1cc65 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -136,19 +136,13 @@ module.exports = function (User) { } function isFullnameValid(data) { - if (!data.fullname) { - return; - } - if (validator.isURL(data.fullname)) { + if (data.fullname && validator.isURL(data.fullname)) { throw new Error('[[error:invalid-fullname]]'); } } function isLocationValid(data) { - if (!data.location) { - return; - } - if (validator.isURL(data.location)) { + if (data.location && validator.isURL(data.location)) { throw new Error('[[error:invalid-location]]'); } } @@ -158,12 +152,8 @@ module.exports = function (User) { return; } - try { - const result = new Date(data.birthday); - if (result && result.toString() === 'Invalid Date') { - throw new Error('[[error:invalid-birthday]]'); - } - } catch (err) { + const result = new Date(data.birthday); + if (result && result.toString() === 'Invalid Date') { throw new Error('[[error:invalid-birthday]]'); } }