From b94f5ebb4bf4cf9a5d319d078a5bda1ed783d4f2 Mon Sep 17 00:00:00 2001 From: Andrew Zhu Date: Tue, 5 Feb 2019 13:08:28 -0800 Subject: [PATCH] add getUserId API endpoint --- app/.gitignore | 1 + app/Routes/API.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/.gitignore b/app/.gitignore index 086ca397..9e3b6267 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -8,3 +8,4 @@ private/oldClient nohup.out node_modules dump +.idea/ diff --git a/app/Routes/API.js b/app/Routes/API.js index 7df32907..e375c4f0 100644 --- a/app/Routes/API.js +++ b/app/Routes/API.js @@ -42,6 +42,29 @@ Router.map(function() { ); }, }); + + this.route("getUserId", { // GET /api/user?username=:un + path: "/api/user", + where: "server", + action: function () { + this.response.setHeader("Content-Type", "application/json"); + var query = this.params.query; + var key = query && query.key; + var username = query && query.username; + ifKeyValid(key, this.response, "getUserId", () => { + Meteor.call("getUserId", username, (err, result) => { + if (err) { + console.error(err); + this.response.writeHead(404, "User not found"); + this.response.end(); + } else { + console.log(result); + this.response.end(JSON.stringify({id: result})); + } + }); + }); + } + }); }); var ifKeyValid = function(apiKey, response, method, callback){