Browse Source

Collect more data, added DataCollect route doc

rigwild 1 year ago
parent
commit
94610236d9

+ 1 - 1
.eslintrc.js

@@ -92,7 +92,7 @@ module.exports = {
     'no-redeclare': 2,
     'no-script-url': 2,
     'no-self-compare': 2,
-    'no-sequences': 2,
+    'no-sequences': 0,
     'no-throw-literal': 2,
     'no-void': 2,
     'no-warning-comments': [0, { terms: ['todo', 'fixme'], location: 'start' }],

+ 27 - 5
server/routes/dataCollect.js

@@ -18,26 +18,48 @@ const router = express.Router()
  *
  * @apiDescription Collect user's data
  *
+ * @apiParam {String} uuid The unique user identifier
+ * @apiParam {Object} screen Screen data, `window.screen` @see https://developer.mozilla.org/en-US/docs/Web/API/Screen
+ *
  * @apiExample Usage example
- * curl -i -L -H "Content-Type: application/json" -X POST "http://diran.univ-littoral.fr/api/dataCollect" -d '{"uuid":"test","viewport":{"x":1920,"y":1024}}'
+ * curl -i -L -H "Content-Type: application/json" -X POST "http://diran.univ-littoral.fr/api/dataCollect" -d {"uuid":"test","screen":{"width":1920,"height":1024}}
  *
  * @apiSuccessExample {string} Success response example
  * HTTP/1.1 200 OK /api/dataCollect
  * OK
+ *
+ * @apiError (Error 4xx) 400_[1] Missing parameter(s)
+ * @apiErrorExample {json} Missing parameter
+ * HTTP/1.1 400 Bad Request
+ * {
+ *   "message": "Missing parameter(s). Required parameters : uuid, screen."
+ * }
+ *
+ * @apiError (Error 4xx) 400_[2] Invalid query parameter
+ * @apiErrorExample {json} Invalid query parameter(s)
+ * HTTP/1.1 400 Bad Request
+ * {
+ *   "message": "Invalid body parameter(s).",
+ *   "data": [
+ *     "\"uuid\" must be a string.",
+ *     "\"screen\" must be a valid object."
+ *   ]
+ * }
+ *
  */
 
 router.post('/', asyncMiddleware(async (req, res) => {
   // Check the request contains all the required body parameters
   const b = req.body
-  checkRequiredParameters(['uuid', 'viewport'], b)
+  checkRequiredParameters(['uuid', 'screen'], b)
 
   let errorList = []
 
   if (typeof b.uuid !== 'string')
     errorList.push('"uuid" must be a string.')
 
-  if (!Number.isInteger(b.viewport.x) || !Number.isInteger(b.viewport.y))
-    errorList.push('"viewport.x" and "viewport.y" must be integers.')
+  if (!Object.isObject(b.screen) || Object.keys(b.screen).length > 30)
+    errorList.push('"screen" must be a valid object.')
 
   // Check there is no errors with parameters
   if (errorList.length > 0)
@@ -50,7 +72,7 @@ router.post('/', asyncMiddleware(async (req, res) => {
     uuid: b.uuid,
     msgId: COLLECT_DATA,
     msg: {
-      viewport: b.viewport,
+      screen: b.screen,
       userAgent,
       ip: req.ip
     }

+ 1 - 1
server/webSocket/messageHandler.js

@@ -21,7 +21,7 @@ const messageHandler = ws => async data => {
   catch (err) {
     throw new Error('Invalid JSON data.')
   }
-  if (!json.uuid)
+  if (!TEST_MODE && !json.uuid)
     throw new Error('"uuid" was not provided.')
 
   await DataController.add(json)

+ 1 - 1
src/mixins/ExperimentBase/index.vue

@@ -31,7 +31,7 @@ export default {
   },
   mounted() {
     if (!this.getExperimentProgress({ experimentName: this.experimentName, sceneName: this.sceneName }).experimentName)
-      this.sendMessage({ msgId: experimentMsgId.STARTED })
+      this.sendMessage({ msgId: experimentMsgId.STARTED, experimentName: this.experimentName, sceneName: this.sceneName })
 
     // Check if the experiment is already finished
     if (this.experimentName && this.sceneName && this.isExperimentDone({ experimentName: this.experimentName, sceneName: this.sceneName })) {

+ 1 - 4
src/store/actions.js

@@ -71,10 +71,7 @@ export default {
       },
       body: JSON.stringify({
         uuid: state.uuid,
-        viewport: {
-          x: window.innerWidth,
-          y: window.innerHeight
-        }
+        viewport: Object.keys(Object.getPrototypeOf(window.screen)).reduce((acc, x) => ((acc[x] = window.screen[x]), acc), {})
       })
     })
   },