2016-12-28 15:49:51 -07:00
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
2017-03-08 11:50:09 -07:00
|
|
|
import $ from 'cafy';
|
2018-02-01 18:31:17 -07:00
|
|
|
import AuthSess, { pack } from '../../../models/auth-session';
|
2016-12-28 15:49:51 -07:00
|
|
|
|
2017-01-05 03:01:37 -07:00
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /auth/session/show:
|
|
|
|
* post:
|
|
|
|
* summary: Show a session information
|
|
|
|
* parameters:
|
|
|
|
* -
|
|
|
|
* name: token
|
2017-01-05 23:13:46 -07:00
|
|
|
* description: Session Token
|
2017-01-05 03:01:37 -07:00
|
|
|
* in: formData
|
|
|
|
* required: true
|
|
|
|
* type: string
|
2017-03-01 01:37:01 -07:00
|
|
|
*
|
2017-01-05 03:01:37 -07:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
2017-03-01 01:37:01 -07:00
|
|
|
* schema:
|
2017-01-05 03:01:37 -07:00
|
|
|
* type: object
|
|
|
|
* properties:
|
2018-03-28 23:48:47 -06:00
|
|
|
* createdAt:
|
2017-01-05 03:01:37 -07:00
|
|
|
* type: string
|
2017-01-06 00:19:41 -07:00
|
|
|
* format: date-time
|
2017-01-05 23:13:46 -07:00
|
|
|
* description: Date and time of the session creation
|
2018-03-28 23:48:47 -06:00
|
|
|
* appId:
|
2017-01-05 03:01:37 -07:00
|
|
|
* type: string
|
|
|
|
* description: Application ID
|
|
|
|
* token:
|
|
|
|
* type: string
|
2017-01-05 07:42:27 -07:00
|
|
|
* description: Session Token
|
2018-03-28 23:48:47 -06:00
|
|
|
* userId:
|
2017-01-05 03:01:37 -07:00
|
|
|
* type: string
|
2017-01-05 23:13:46 -07:00
|
|
|
* description: ID of user who create the session
|
2017-01-05 03:01:37 -07:00
|
|
|
* app:
|
|
|
|
* $ref: "#/definitions/Application"
|
2017-01-05 08:39:56 -07:00
|
|
|
* default:
|
2017-01-05 03:01:37 -07:00
|
|
|
* description: Failed
|
|
|
|
* schema:
|
|
|
|
* $ref: "#/definitions/Error"
|
|
|
|
*/
|
|
|
|
|
2016-12-28 15:49:51 -07:00
|
|
|
/**
|
|
|
|
* Show a session
|
|
|
|
*
|
2017-03-01 01:37:01 -07:00
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @return {Promise<any>}
|
2016-12-28 15:49:51 -07:00
|
|
|
*/
|
2017-03-03 12:28:38 -07:00
|
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
2016-12-28 15:49:51 -07:00
|
|
|
// Get 'token' parameter
|
2017-03-08 11:50:09 -07:00
|
|
|
const [token, tokenErr] = $(params.token).string().$;
|
2017-03-03 03:39:41 -07:00
|
|
|
if (tokenErr) return rej('invalid token param');
|
2016-12-28 15:49:51 -07:00
|
|
|
|
|
|
|
// Lookup session
|
|
|
|
const session = await AuthSess.findOne({
|
|
|
|
token: token
|
|
|
|
});
|
|
|
|
|
|
|
|
if (session == null) {
|
|
|
|
return rej('session not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Response
|
2018-02-01 16:21:30 -07:00
|
|
|
res(await pack(session, user));
|
2016-12-28 15:49:51 -07:00
|
|
|
});
|