From a7437c02d9e580d2d6ac151420d625a31ebf3a04 Mon Sep 17 00:00:00 2001 From: tanmoythander Date: Wed, 9 Jan 2019 01:26:51 +0600 Subject: [PATCH] updated routes to accept date in milliseconds --- routes/admin.js | 33 ++++++++++++- routes/token.js | 50 ++++++++++++++++++- routes/user.js | 126 ++++++++++++++++++++++++++++++------------------ 3 files changed, 157 insertions(+), 52 deletions(-) diff --git a/routes/admin.js b/routes/admin.js index ce28ca6..b094d0b 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -25,7 +25,7 @@ router.route('/profile') * @api {get} /admin/profile Get admin profile * @apiHeader {String} Content-Type application/json * @apiHeader {String} access-key Admin authentication token. - * @apiVersion 0.1.0 + * @apiVersion 1.0.0 * @apiGroup AdminProfile * @apiName GetAdminProfile * @apiExample Example usage: @@ -78,6 +78,35 @@ router.route('/profile') * @apiParam {String} profile.phone Phone number. * @apiParam {Date} profile.dob Date of birth. */ + + /** + * @api {put} /admin/profile Update admin profile + * @apiHeader {String} Content-Type application/json + * @apiHeader {String} access-key Admin authentication token. + * @apiVersion 1.0.0 + * @apiGroup AdminProfile + * @apiName UpdateAdminProfile + * @apiExample Example usage: + * url: http://localhost:3484/admin/profile + * + * body: + * { + * "name": "John Doe", + * "profile": { + * "address": "Sylhet, BD", + * "company": "Owlette", + * "phone": "+8801413667755", + * "dob": 1546973225829 + * } + * } + * + * @apiParam {String} name Admin's name. + * @apiParam {Object} profile Profile object. + * @apiParam {String} profile.address Address. + * @apiParam {String} profile.company Company. + * @apiParam {String} profile.phone Phone number. + * @apiParam {Date} profile.dob Date of birth(in millis). + */ .put(function(req, res) { Admin.findById(req.decoded._id, function(err, admin) { if (err) { @@ -93,7 +122,7 @@ router.route('/profile') admin.profile.address = req.body.profile.address; admin.profile.company = req.body.profile.company; admin.profile.phone = req.body.profile.phone; - admin.profile.updated_at = Date.now(); + admin.profile.updated_at = (new Date()).getTime(); admin.save(function(err, admin) { if (err) { diff --git a/routes/token.js b/routes/token.js index 65f026f..632418d 100644 --- a/routes/token.js +++ b/routes/token.js @@ -40,6 +40,29 @@ var createHash = function(password){ * @apiParam {Date} dob Users date of birth. * @apiParam {String} pass Users password. */ + +/** + * @api {post} /token/user/signup User Signup + * @apiHeader {String} Content-Type application/json + * @apiVersion 1.0.0 + * @apiGroup Authentication + * @apiName UserSignup + * @apiExample Example usage: + * url: http://localhost:3484/token/user/signup + * + * body: + * { + * "name": "John Doe", + * "email": "example@example.com", + * "dob": 1546973225829, + * "pass": "thisIsPassword" + * } + * + * @apiParam {String} name Users name. + * @apiParam {String} email Users email. + * @apiParam {Number} dob Users date of birth(in millis). + * @apiParam {String} pass Users password. + */ router.route('/user/signup') .post(function(req, res) { User.findOne({'email':req.body.email}, function(err, user) { @@ -95,7 +118,7 @@ router.route('/user/signup') /** * @api {post} /token/user/login User Login * @apiHeader {String} Content-Type application/json - * @apiVersion 0.1.0 + * @apiVersion 1.0.0 * @apiGroup Authentication * @apiName UserLogin * @apiExample Example usage: @@ -176,6 +199,29 @@ router.route('/user/login') * @apiParam {Date} dob Admins date of birth. * @apiParam {String} pass Admins password. */ + +/** + * @api {post} /token/admin/signup Admin Signup + * @apiHeader {String} Content-Type application/json + * @apiVersion 1.0.0 + * @apiGroup Authentication + * @apiName AdminSignup + * @apiExample Example usage: + * url: http://localhost:3484/token/admin/signup + * + * body: + * { + * "name": "John Doe", + * "email": "example@example.com", + * "dob": 1546973225829, + * "pass": "thisIsPassword" + * } + * + * @apiParam {String} name Admins name. + * @apiParam {String} email Admins email. + * @apiParam {Number} dob Admins date of birth(in millis). + * @apiParam {String} pass Admins password. + */ router.route('/admin/signup') .post(function(req, res) { Admin.findOne({'email':req.body.email}, function(err, admin) { @@ -231,7 +277,7 @@ router.route('/admin/signup') /** * @api {post} /token/admin/login Admin Login * @apiHeader {String} Content-Type application/json - * @apiVersion 0.1.0 + * @apiVersion 1.0.0 * @apiGroup Authentication * @apiName AdminLogin * @apiExample Example usage: diff --git a/routes/user.js b/routes/user.js index 04bb3c4..98045b9 100644 --- a/routes/user.js +++ b/routes/user.js @@ -57,7 +57,7 @@ router.route('/posts') * @api {post} /user/posts Create a post * @apiHeader {String} Content-Type application/json * @apiHeader {String} access-key User authentication token. - * @apiVersion 0.1.0 + * @apiVersion 1.0.0 * @apiGroup Posts * @apiName CreatePost * @apiExample Example usage: @@ -81,7 +81,7 @@ router.route('/posts') error: err }); } - var newPostEcho = post; + post.archieved = undefined; User.findById(req.decoded._id, function(err, user) { if (err) { return res.status(500).send({ @@ -90,7 +90,7 @@ router.route('/posts') error: err }); } - user.posts.push(newPostEcho); + user.posts.push(post._id); user.save(function(err, user) { if (err) { return res.status(500).send({ @@ -113,12 +113,12 @@ router.route('/posts') }) .get(function(req, res) { // get all posts - // NOTE: Every single post by every user except deleted posts + // NOTE: Every single post created by the user except deleted posts /** - * @api {get} /user/posts Get all posts + * @api {get} /user/posts Get all user posts * @apiHeader {String} Content-Type application/json * @apiHeader {String} access-key User authentication token. - * @apiVersion 0.1.0 + * @apiVersion 1.0.0 * @apiGroup Posts * @apiName AllPosts * @apiExample Example usage: @@ -127,7 +127,8 @@ router.route('/posts') * @apiDescription Every single post by every user except deleted posts. */ var query = Post.find({ - '_created_by': req.decoded._id + '_created_by': req.decoded._id, + 'archieved': false }, function(err, posts) { if (err) { return res.status(500).send({ @@ -136,22 +137,13 @@ router.route('/posts') error: err }); } - var i = 0; - while (i