(envConfig)
| 206 | */ |
| 207 | |
| 208 | export default function adminRouter(envConfig) { |
| 209 | /** |
| 210 | * @swagger |
| 211 | * |
| 212 | * security: |
| 213 | * - APIKeyHeader: [] |
| 214 | * |
| 215 | * tags: |
| 216 | * - name: Admin - Retrieve your own user record |
| 217 | * description: Retrieve the user record of the current user |
| 218 | * |
| 219 | * /api/v1.0/admin/self: |
| 220 | * get: |
| 221 | * # Operation-specific security: |
| 222 | * security: |
| 223 | * - APIKeyHeader: [] |
| 224 | * description: Retrieves the information of the currently logged in user. Admin privileges not required. |
| 225 | * tags: [Admin - Retrieve your own user record] |
| 226 | * produces: |
| 227 | * - application/json |
| 228 | * responses: |
| 229 | * 200: |
| 230 | * description: An individual user record for the current user. |
| 231 | * type: object |
| 232 | * schema: |
| 233 | * $ref: '#/definitions/UserRecord' |
| 234 | * 404: |
| 235 | * description: Results not found. |
| 236 | * schema: |
| 237 | * $ref: '#/definitions/ResultsNotFound' |
| 238 | * 500: |
| 239 | * description: Server error. |
| 240 | * schema: |
| 241 | * $ref: '#/definitions/ServerError' |
| 242 | */ |
| 243 | router.route('/admin/self') |
| 244 | .get(function (req, res) { |
| 245 | let userPromise; |
| 246 | if (typeof req.session.userid !== 'undefined') { |
| 247 | userPromise = user.getUserIdPromise(req.session.userid, true); |
| 248 | } else { |
| 249 | userPromise = user.getUserIdPromise(req.session.passport.user.userid, true); |
| 250 | } |
| 251 | userPromise.then( |
| 252 | function (userInDB) { |
| 253 | if (!userInDB) { |
| 254 | res.status(404).json({ |
| 255 | 'message': 'User not found!', |
| 256 | }); |
| 257 | return; |
| 258 | } |
| 259 | res.status(200).json(userInDB); |
| 260 | return; |
| 261 | }); |
| 262 | }); |
| 263 | |
| 264 | /** |
| 265 | * @swagger |
no test coverage detected