Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. import express from 'express';
  2. import passport from 'passport';
  3. import userController from '../controllers/user';
  4. import roleFilter from '../middlewares/role-filter';
  5.  
  6. const router = express.Router();
  7.  
  8. const requireAuth = passport.authenticate('bearer', {
  9. session: false
  10. });
  11.  
  12. /**
  13. * @api {get} /api/users list users
  14. * @apiVersion 0.0.1
  15. * @apiName list
  16. * @apiGroup users
  17. * @apiPermission user
  18. *
  19. * @apiParam {String} page page number
  20. * @apiParam {String} size desired documents per page
  21. *
  22. * @apiSuccess {Object} body response body
  23. *
  24. * @apiSuccessExample response
  25. * HTTP/1.1 200 OK
  26. * { count: 1,
  27. * list:
  28. * [ { _id: '59c80c08ff78f074fde62ef4',
  29. * updatedAt: '2017-09-24T19:48:24.637Z',
  30. * createdAt: '2017-09-24T19:48:24.395Z',
  31. * username: 'Buster.Zieme42',
  32. * email: 'dustin53@yahoo.com',
  33. * __v: 0,
  34. * lastLogin: '2017-09-24T19:48:24.636Z',
  35. * profile: [Object],
  36. * passwordChanged: false,
  37. * role: 'user',
  38. * verify: [Object],
  39. * ban: [Object],
  40. * reset: [Object] } ] }
  41. *
  42. * @apiSuccessExample headers
  43. * HTTP/1.1 200 OK
  44. * { 'next-page': '/api/users?page=1&size=50',
  45. * etag: 'W/"1a-6HEOOYo/3j1gaZ0QSSux1FITqXI"',
  46. * date: 'Sun, 24 Sep 2017 18:19:49 GMT',
  47. * connection: 'close' }
  48. */
  49. router.get('/', requireAuth, roleFilter('all'), userController.listUsers);
  50.  
  51. /**
  52. * @api {post} /api/users create user
  53. * @apiVersion 0.0.1
  54. * @apiName create
  55. * @apiGroup users
  56. * @apiPermission none
  57. *
  58. * @apiParam {String} email user email
  59. * @apiParam {String} username user alias
  60. * @apiParam {String} password user password
  61. * @apiParam {Object} profile profile object
  62. * @apiParam {String} profile.fistName user first name
  63. * @apiParam {String} profile.lastName user last name
  64. * @apiParam {String} profile.avatar user avatar image url
  65. *
  66. * @apiSuccess {Object} body response body
  67. *
  68. * @apiSuccessExample response
  69. * HTTP/1.1 201 OK
  70. * { message: 'User Created' }
  71. *
  72. * @apiSuccessExample headers
  73. * HTTP/1.1 201 OK
  74. * { location: '/api/users/59c7f74541e37d6e51f43eff',
  75. * etag: 'W/"1a-6HEOOYo/3j1gaZ0QSSux1FITqXI"',
  76. * date: 'Sun, 24 Sep 2017 18:19:49 GMT',
  77. * connection: 'close' }
  78. */
  79. router.post('/', userController.createUser);
  80.  
  81. /**
  82. * @api {post} /api/users/forgot forgot password
  83. * @apiVersion 0.0.1
  84. * @apiName forgot
  85. * @apiGroup users
  86. * @apiPermission none
  87. *
  88. * @apiParam {String} email user email
  89. *
  90. * @apiSuccess {Object} body response body
  91. *
  92. * @apiSuccessExample response
  93. * HTTP/1.1 200 OK
  94. * { message: 'Reset link sent to email' }
  95. */
  96. router.post('/forgot', userController.forgotPassword);
  97.  
  98. /**
  99. * @api {get} /api/users/me get logged in user info
  100. * @apiVersion 0.0.1
  101. * @apiName me
  102. * @apiGroup users
  103. * @apiPermission user
  104. *
  105. * @apiSuccess {Object} body response logged in user
  106. *
  107. * @apiSuccessExample Success-Response:
  108. * HTTP/1.1 200 OK
  109. * { reset: { token: null, expires: null },
  110. * ban: { since: null, until: null, times: 0 },
  111. * verify:
  112. * { token: '8fd2f03e-169b-460f-bf22-8c470182f497',
  113. * generation: '2017-09-24T18:16:11.892Z',
  114. * execution: null },
  115. * role: 'user',
  116. * passwordChanged: false,
  117. * profile:
  118. * { avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/rodnylobos/128.jpg',
  119. * firstName: 'Luther',
  120. * lastName: 'Homenick' },
  121. * lastLogin: '2017-09-24T18:16:14.422Z',
  122. * __v: 0,
  123. * email: 'dawn_kuhic@gmail.com',
  124. * username: 'Brady_Hahn',
  125. * createdAt: '2017-09-24T18:16:14.180Z',
  126. * updatedAt: '2017-09-24T18:16:14.423Z',
  127. * _id: '59c7f66efda2166df63cf452' }
  128. */
  129. router.get('/me', requireAuth, roleFilter('all'), userController.meUser);
  130. router.get('/count', requireAuth, roleFilter('all'), userController.countUsers);
  131.  
  132. /**
  133. * @api {get} /api/users/:id get user
  134. * @apiVersion 0.0.1
  135. * @apiName get
  136. * @apiGroup users
  137. * @apiPermission user
  138. *
  139. * @apiSuccess {Object} body response logged in user
  140. *
  141. * @apiSuccessExample Success-Response:
  142. * HTTP/1.1 200 OK
  143. * { reset: { token: null, expires: null },
  144. * ban: { since: null, until: null, times: 0 },
  145. * verify:
  146. * { token: '8fd2f03e-169b-460f-bf22-8c470182f497',
  147. * generation: '2017-09-24T18:16:11.892Z',
  148. * execution: null },
  149. * role: 'user',
  150. * passwordChanged: false,
  151. * profile:
  152. * { avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/rodnylobos/128.jpg',
  153. * firstName: 'Luther',
  154. * lastName: 'Homenick' },
  155. * lastLogin: '2017-09-24T18:16:14.422Z',
  156. * __v: 0,
  157. * email: 'dawn_kuhic@gmail.com',
  158. * username: 'Brady_Hahn',
  159. * createdAt: '2017-09-24T18:16:14.180Z',
  160. * updatedAt: '2017-09-24T18:16:14.423Z',
  161. * _id: '59c7f66efda2166df63cf452' }
  162. */
  163. router.get('/:id', requireAuth, roleFilter('all'), userController.getUser);
  164.  
  165. /**
  166. * @api {put} /api/users/:id update user
  167. * @apiVersion 0.0.1
  168. * @apiName update
  169. * @apiGroup users
  170. * @apiPermission user
  171. *
  172. * @apiParam {String} fistName user first name
  173. * @apiParam {String} lastName user last name
  174. * @apiParam {String} avatar user avatar image url
  175. *
  176. * @apiSuccess {Object} body response body
  177. *
  178. * @apiSuccessExample response
  179. * HTTP/1.1 200 OK
  180. * { message: 'User updated' }
  181. *
  182. * @apiSuccessExample headers
  183. * HTTP/1.1 200 OK
  184. * { location: '/api/users/59c7f74541e37d6e51f43eff',
  185. * etag: 'W/"1a-6HEOOYo/3j1gaZ0QSSux1FITqXI"',
  186. * date: 'Sun, 24 Sep 2017 18:19:49 GMT',
  187. * connection: 'close' }
  188. */
  189. router.put('/:id', requireAuth, roleFilter('all'), userController.updateUser);
  190.  
  191. /**
  192. * @api {get} /api/users/:id/reset reset password
  193. * @apiVersion 0.0.1
  194. * @apiName reset
  195. * @apiGroup users
  196. * @apiPermission none
  197. *
  198. * @apiParam {String} token user reset password token
  199. *
  200. * @apiSuccess {Object} body response body
  201. *
  202. * @apiSuccessExample response
  203. * HTTP/1.1 200 OK
  204. * { message: 'Password changed' }
  205. */
  206. router.get('/:id/reset', userController.resetPassword);
  207.  
  208. /**
  209. * @api {get} /api/users/:id/verify verify email
  210. * @apiVersion 0.0.1
  211. * @apiName verify
  212. * @apiGroup users
  213. * @apiPermission none
  214. *
  215. * @apiParam {String} token user reset password token
  216. *
  217. * @apiSuccess {Object} body response body
  218. *
  219. * @apiSuccessExample response
  220. * HTTP/1.1 200 OK
  221. * { message: 'Email verified' }
  222. */
  223. router.get('/:id/verify', userController.verifyEmail);
  224.  
  225. /**
  226. * @api {post} /api/users/:id/verify ask verify email
  227. * @apiVersion 0.0.1
  228. * @apiName ask
  229. * @apiGroup users
  230. * @apiPermission user
  231. *
  232. * @apiSuccess {Object} body response body
  233. *
  234. * @apiSuccessExample response
  235. * HTTP/1.1 200 OK
  236. * { message: 'Verification email sent' }
  237. */
  238. router.post('/:id/verify', requireAuth, roleFilter('all'), userController.askVerification);
  239.  
  240. /**
  241. * @api {post} /api/users/:id/change update user
  242. * @apiVersion 0.0.1
  243. * @apiName change
  244. * @apiGroup users
  245. * @apiPermission user
  246. *
  247. * @apiParam {String} oldPassword user old password
  248. * @apiParam {String} newPassword user new password
  249. *
  250. * @apiSuccess {Object} body response body
  251. *
  252. * @apiSuccessExample response
  253. * HTTP/1.1 200 OK
  254. * { message: 'Password changed' }
  255. */
  256. router.post('/:id/change', requireAuth, roleFilter('all'), userController.changePassword);
  257.  
  258. export default router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement