summaryrefslogtreecommitdiff
path: root/src/api/endpoints/auth/session/show.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 19:39:41 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 19:39:41 +0900
commitd1557bcae8abc45ea655d2fe0cdb6732a0207aa0 (patch)
tree56bb4b981df8d00c3d684352f3ee5b5057ee2a7e /src/api/endpoints/auth/session/show.ts
parentwip (diff)
downloadsharkey-d1557bcae8abc45ea655d2fe0cdb6732a0207aa0.tar.gz
sharkey-d1557bcae8abc45ea655d2fe0cdb6732a0207aa0.tar.bz2
sharkey-d1557bcae8abc45ea655d2fe0cdb6732a0207aa0.zip
wip
Diffstat (limited to 'src/api/endpoints/auth/session/show.ts')
-rw-r--r--src/api/endpoints/auth/session/show.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/api/endpoints/auth/session/show.ts b/src/api/endpoints/auth/session/show.ts
new file mode 100644
index 0000000000..55641929d8
--- /dev/null
+++ b/src/api/endpoints/auth/session/show.ts
@@ -0,0 +1,75 @@
+'use strict';
+
+/**
+ * Module dependencies
+ */
+import it from '../../../it';
+import AuthSess from '../../../models/auth-session';
+import serialize from '../../../serializers/auth-session';
+
+/**
+ * @swagger
+ * /auth/session/show:
+ * post:
+ * summary: Show a session information
+ * parameters:
+ * -
+ * name: token
+ * description: Session Token
+ * in: formData
+ * required: true
+ * type: string
+ *
+ * responses:
+ * 200:
+ * description: OK
+ * schema:
+ * type: object
+ * properties:
+ * created_at:
+ * type: string
+ * format: date-time
+ * description: Date and time of the session creation
+ * app_id:
+ * type: string
+ * description: Application ID
+ * token:
+ * type: string
+ * description: Session Token
+ * user_id:
+ * type: string
+ * description: ID of user who create the session
+ * app:
+ * $ref: "#/definitions/Application"
+ * default:
+ * description: Failed
+ * schema:
+ * $ref: "#/definitions/Error"
+ */
+
+/**
+ * Show a session
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise<any>}
+ */
+module.exports = (params, user) =>
+ new Promise(async (res, rej) =>
+{
+ // Get 'token' parameter
+ const [token, tokenErr] = it(params.token).expect.string().required().qed();
+ if (tokenErr) return rej('invalid token param');
+
+ // Lookup session
+ const session = await AuthSess.findOne({
+ token: token
+ });
+
+ if (session == null) {
+ return rej('session not found');
+ }
+
+ // Response
+ res(await serialize(session, user));
+});