Node.js based forum software built for the modern web
changes to user routes to return null
Baris Soner Usakli6a4dcc75c2d7
diff --git a/public/src/templates.js b/public/src/templates.jsindex 418018dded..392d907766 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -154,7 +154,7 @@(function() {jQuery.get(API_URL + api_url, function(data) {- if(data === false) {+ if(!data) {ajaxify.go('404');return;}diff --git a/src/routes/user.js b/src/routes/user.jsindex 34884afe86..a0c2f7b1d3 100644--- a/src/routes/user.js+++ b/src/routes/user.js@@ -259,22 +259,10 @@ var user = require('./../user.js'),});}else if(String(req.params.section).toLowerCase() === 'following') {- getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {- user.getFollowing(userData.uid, function(followingData){- userData.following = followingData;- userData.followingCount = followingData.length;- res.json(userData);- });- });+ getFollowing(req, res, callerUID);}else if(String(req.params.section).toLowerCase() === 'followers') {- getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {- user.getFollowers(userData.uid, function(followersData){- userData.followers = followersData;- userData.followersCount = followersData.length;- res.json(userData);- });- });+ getFollowers(req, res, callerUID);}else if (String(req.params.section).toLowerCase() === 'edit') {getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {@@ -295,6 +283,35 @@ var user = require('./../user.js'),}}+ function getFollowing(req, res, callerUid) {+ getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {+ if(userData) {+ user.getFollowing(userData.uid, function(followingData){+ userData.following = followingData;+ userData.followingCount = followingData.length;+ res.json(userData);+ });++ } else {+ res.json(null);+ }+ });+ }++ function getFollowers(req, res, callerUid) {+ getUserDataByUserSlug(req.params.userslug, callerUid, function(userData) {+ if(userData) {+ user.getFollowers(userData.uid, function(followersData){+ userData.followers = followersData;+ userData.followersCount = followersData.length;+ res.json(userData);+ });+ } else {+ res.json(null);+ }+ });+ }+app.get('/api/users/:userslug?/:section?', api_method);app.get('/api/users-sort-posts', getUsersSortedByPosts);app.get('/api/users-sort-reputation', getUsersSortedByReputation);@@ -332,9 +349,14 @@ var user = require('./../user.js'),res.json({ search_display: 'block', users: [] });}-function getUserDataByUserSlug(userslug, callerUID, callback) {user.get_uid_by_userslug(userslug, function(uid) {++ if(uid === null) {+ callback(null);+ return;+ }+user.getUserData(uid, function(data) {if(data) {data.joindate = utils.relativeTime(data.joindate);@@ -357,8 +379,7 @@ var user = require('./../user.js'),});});} else {- // @todo why is this an empty object? perhaps the callback should expect NULL or undefined instead.- callback({});+ callback(null);}});