Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import express from 'express';
- import passport from 'passport';
- import userController from '../controllers/user';
- import roleFilter from '../middlewares/role-filter';
- const router = express.Router();
- const requireAuth = passport.authenticate('bearer', {
- session: false
- });
- /**
- * @api {get} /api/users list users
- * @apiVersion 0.0.1
- * @apiName list
- * @apiGroup users
- * @apiPermission user
- *
- * @apiParam {String} page page number
- * @apiParam {String} size desired documents per page
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { count: 1,
- * list:
- * [ { _id: '59c80c08ff78f074fde62ef4',
- * updatedAt: '2017-09-24T19:48:24.637Z',
- * createdAt: '2017-09-24T19:48:24.395Z',
- * username: 'Buster.Zieme42',
- * email: 'dustin53@yahoo.com',
- * __v: 0,
- * lastLogin: '2017-09-24T19:48:24.636Z',
- * profile: [Object],
- * passwordChanged: false,
- * role: 'user',
- * verify: [Object],
- * ban: [Object],
- * reset: [Object] } ] }
- *
- * @apiSuccessExample headers
- * HTTP/1.1 200 OK
- * { 'next-page': '/api/users?page=1&size=50',
- * etag: 'W/"1a-6HEOOYo/3j1gaZ0QSSux1FITqXI"',
- * date: 'Sun, 24 Sep 2017 18:19:49 GMT',
- * connection: 'close' }
- */
- router.get('/', requireAuth, roleFilter('all'), userController.listUsers);
- /**
- * @api {post} /api/users create user
- * @apiVersion 0.0.1
- * @apiName create
- * @apiGroup users
- * @apiPermission none
- *
- * @apiParam {String} email user email
- * @apiParam {String} username user alias
- * @apiParam {String} password user password
- * @apiParam {Object} profile profile object
- * @apiParam {String} profile.fistName user first name
- * @apiParam {String} profile.lastName user last name
- * @apiParam {String} profile.avatar user avatar image url
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 201 OK
- * { message: 'User Created' }
- *
- * @apiSuccessExample headers
- * HTTP/1.1 201 OK
- * { location: '/api/users/59c7f74541e37d6e51f43eff',
- * etag: 'W/"1a-6HEOOYo/3j1gaZ0QSSux1FITqXI"',
- * date: 'Sun, 24 Sep 2017 18:19:49 GMT',
- * connection: 'close' }
- */
- router.post('/', userController.createUser);
- /**
- * @api {post} /api/users/forgot forgot password
- * @apiVersion 0.0.1
- * @apiName forgot
- * @apiGroup users
- * @apiPermission none
- *
- * @apiParam {String} email user email
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { message: 'Reset link sent to email' }
- */
- router.post('/forgot', userController.forgotPassword);
- /**
- * @api {get} /api/users/me get logged in user info
- * @apiVersion 0.0.1
- * @apiName me
- * @apiGroup users
- * @apiPermission user
- *
- * @apiSuccess {Object} body response logged in user
- *
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 200 OK
- * { reset: { token: null, expires: null },
- * ban: { since: null, until: null, times: 0 },
- * verify:
- * { token: '8fd2f03e-169b-460f-bf22-8c470182f497',
- * generation: '2017-09-24T18:16:11.892Z',
- * execution: null },
- * role: 'user',
- * passwordChanged: false,
- * profile:
- * { avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/rodnylobos/128.jpg',
- * firstName: 'Luther',
- * lastName: 'Homenick' },
- * lastLogin: '2017-09-24T18:16:14.422Z',
- * __v: 0,
- * email: 'dawn_kuhic@gmail.com',
- * username: 'Brady_Hahn',
- * createdAt: '2017-09-24T18:16:14.180Z',
- * updatedAt: '2017-09-24T18:16:14.423Z',
- * _id: '59c7f66efda2166df63cf452' }
- */
- router.get('/me', requireAuth, roleFilter('all'), userController.meUser);
- router.get('/count', requireAuth, roleFilter('all'), userController.countUsers);
- /**
- * @api {get} /api/users/:id get user
- * @apiVersion 0.0.1
- * @apiName get
- * @apiGroup users
- * @apiPermission user
- *
- * @apiSuccess {Object} body response logged in user
- *
- * @apiSuccessExample Success-Response:
- * HTTP/1.1 200 OK
- * { reset: { token: null, expires: null },
- * ban: { since: null, until: null, times: 0 },
- * verify:
- * { token: '8fd2f03e-169b-460f-bf22-8c470182f497',
- * generation: '2017-09-24T18:16:11.892Z',
- * execution: null },
- * role: 'user',
- * passwordChanged: false,
- * profile:
- * { avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/rodnylobos/128.jpg',
- * firstName: 'Luther',
- * lastName: 'Homenick' },
- * lastLogin: '2017-09-24T18:16:14.422Z',
- * __v: 0,
- * email: 'dawn_kuhic@gmail.com',
- * username: 'Brady_Hahn',
- * createdAt: '2017-09-24T18:16:14.180Z',
- * updatedAt: '2017-09-24T18:16:14.423Z',
- * _id: '59c7f66efda2166df63cf452' }
- */
- router.get('/:id', requireAuth, roleFilter('all'), userController.getUser);
- /**
- * @api {put} /api/users/:id update user
- * @apiVersion 0.0.1
- * @apiName update
- * @apiGroup users
- * @apiPermission user
- *
- * @apiParam {String} fistName user first name
- * @apiParam {String} lastName user last name
- * @apiParam {String} avatar user avatar image url
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { message: 'User updated' }
- *
- * @apiSuccessExample headers
- * HTTP/1.1 200 OK
- * { location: '/api/users/59c7f74541e37d6e51f43eff',
- * etag: 'W/"1a-6HEOOYo/3j1gaZ0QSSux1FITqXI"',
- * date: 'Sun, 24 Sep 2017 18:19:49 GMT',
- * connection: 'close' }
- */
- router.put('/:id', requireAuth, roleFilter('all'), userController.updateUser);
- /**
- * @api {get} /api/users/:id/reset reset password
- * @apiVersion 0.0.1
- * @apiName reset
- * @apiGroup users
- * @apiPermission none
- *
- * @apiParam {String} token user reset password token
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { message: 'Password changed' }
- */
- router.get('/:id/reset', userController.resetPassword);
- /**
- * @api {get} /api/users/:id/verify verify email
- * @apiVersion 0.0.1
- * @apiName verify
- * @apiGroup users
- * @apiPermission none
- *
- * @apiParam {String} token user reset password token
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { message: 'Email verified' }
- */
- router.get('/:id/verify', userController.verifyEmail);
- /**
- * @api {post} /api/users/:id/verify ask verify email
- * @apiVersion 0.0.1
- * @apiName ask
- * @apiGroup users
- * @apiPermission user
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { message: 'Verification email sent' }
- */
- router.post('/:id/verify', requireAuth, roleFilter('all'), userController.askVerification);
- /**
- * @api {post} /api/users/:id/change update user
- * @apiVersion 0.0.1
- * @apiName change
- * @apiGroup users
- * @apiPermission user
- *
- * @apiParam {String} oldPassword user old password
- * @apiParam {String} newPassword user new password
- *
- * @apiSuccess {Object} body response body
- *
- * @apiSuccessExample response
- * HTTP/1.1 200 OK
- * { message: 'Password changed' }
- */
- router.post('/:id/change', requireAuth, roleFilter('all'), userController.changePassword);
- export default router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement