egirlskey/src/api/endpoints/auth/session/show.ts

72 lines
1.7 KiB
TypeScript
Raw Normal View History

2016-12-28 22:49:51 +00:00
/**
* Module dependencies
*/
2017-03-05 03:00:39 +00:00
import it from 'cafy';
2016-12-28 22:49:51 +00:00
import AuthSess from '../../../models/auth-session';
import serialize from '../../../serializers/auth-session';
2017-01-05 10:01:37 +00:00
/**
* @swagger
* /auth/session/show:
* post:
* summary: Show a session information
* parameters:
* -
* name: token
2017-01-06 06:13:46 +00:00
* description: Session Token
2017-01-05 10:01:37 +00:00
* in: formData
* required: true
* type: string
2017-03-01 08:37:01 +00:00
*
2017-01-05 10:01:37 +00:00
* responses:
* 200:
* description: OK
2017-03-01 08:37:01 +00:00
* schema:
2017-01-05 10:01:37 +00:00
* type: object
* properties:
* created_at:
* type: string
2017-01-06 07:19:41 +00:00
* format: date-time
2017-01-06 06:13:46 +00:00
* description: Date and time of the session creation
2017-01-05 10:01:37 +00:00
* app_id:
* type: string
* description: Application ID
* token:
* type: string
2017-01-05 14:42:27 +00:00
* description: Session Token
2017-01-05 10:01:37 +00:00
* user_id:
* type: string
2017-01-06 06:13:46 +00:00
* description: ID of user who create the session
2017-01-05 10:01:37 +00:00
* app:
* $ref: "#/definitions/Application"
2017-01-05 15:39:56 +00:00
* default:
2017-01-05 10:01:37 +00:00
* description: Failed
* schema:
* $ref: "#/definitions/Error"
*/
2016-12-28 22:49:51 +00:00
/**
* Show a session
*
2017-03-01 08:37:01 +00:00
* @param {any} params
* @param {any} user
* @return {Promise<any>}
2016-12-28 22:49:51 +00:00
*/
2017-03-03 19:28:38 +00:00
module.exports = (params, user) => new Promise(async (res, rej) => {
2016-12-28 22:49:51 +00:00
// Get 'token' parameter
2017-03-05 03:00:39 +00:00
const [token, tokenErr] = it(params.token).expect.string().required().get();
2017-03-03 10:39:41 +00:00
if (tokenErr) return rej('invalid token param');
2016-12-28 22:49:51 +00:00
// Lookup session
const session = await AuthSess.findOne({
token: token
});
if (session == null) {
return rej('session not found');
}
// Response
res(await serialize(session, user));
});