|
@@ -20,10 +20,13 @@ const router = express.Router()
|
|
* @apiDescription Collect user's data
|
|
* @apiDescription Collect user's data
|
|
*
|
|
*
|
|
* @apiParam {String} uuid The unique user identifier
|
|
* @apiParam {String} uuid The unique user identifier
|
|
|
|
+ * @apiParam {String} userId The user ID
|
|
|
|
+ * @apiParam {String} experimentId The experiment ID
|
|
|
|
+ * @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
|
|
* @apiParam {Object} screen Screen data, `window.screen` @see https://developer.mozilla.org/en-US/docs/Web/API/Screen
|
|
*
|
|
*
|
|
* @apiExample Usage example
|
|
* @apiExample Usage example
|
|
- * 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}}
|
|
|
|
|
|
+ * curl -i -L -H "Content-Type: application/json" -X POST "http://diran.univ-littoral.fr/api/dataCollect" -d {"uuid":"test","userId":"rigwild","experimentId":"expe-test","screen":{"width":1920,"height":1024}}
|
|
*
|
|
*
|
|
* @apiSuccessExample {string} Success response example
|
|
* @apiSuccessExample {string} Success response example
|
|
* HTTP/1.1 200 OK /api/dataCollect
|
|
* HTTP/1.1 200 OK /api/dataCollect
|
|
@@ -33,7 +36,7 @@ const router = express.Router()
|
|
* @apiErrorExample {json} Missing parameter
|
|
* @apiErrorExample {json} Missing parameter
|
|
* HTTP/1.1 400 Bad Request
|
|
* HTTP/1.1 400 Bad Request
|
|
* {
|
|
* {
|
|
- * "message": "Missing parameter(s). Required parameters : uuid, screen."
|
|
|
|
|
|
+ * "message": "Missing parameter(s). Required parameters : uuid, userId, experimentId, screen."
|
|
* }
|
|
* }
|
|
*
|
|
*
|
|
* @apiError (Error 4xx) 400_[2] Invalid query parameter
|
|
* @apiError (Error 4xx) 400_[2] Invalid query parameter
|
|
@@ -43,6 +46,8 @@ const router = express.Router()
|
|
* "message": "Invalid body parameter(s).",
|
|
* "message": "Invalid body parameter(s).",
|
|
* "data": [
|
|
* "data": [
|
|
* "\"uuid\" must be a string.",
|
|
* "\"uuid\" must be a string.",
|
|
|
|
+ * "\"userId\" must be a string.",
|
|
|
|
+ * "\"experimentId\" must be a string.",
|
|
* "\"screen\" must be a valid object."
|
|
* "\"screen\" must be a valid object."
|
|
* ]
|
|
* ]
|
|
* }
|
|
* }
|
|
@@ -52,13 +57,19 @@ const router = express.Router()
|
|
router.post('/', asyncMiddleware(async (req, res) => {
|
|
router.post('/', asyncMiddleware(async (req, res) => {
|
|
// Check the request contains all the required body parameters
|
|
// Check the request contains all the required body parameters
|
|
const b = req.body
|
|
const b = req.body
|
|
- checkRequiredParameters(['uuid', 'screen'], b)
|
|
|
|
|
|
+ checkRequiredParameters(['uuid', 'screen', 'userId', 'experimentId'], b)
|
|
|
|
|
|
let errorList = []
|
|
let errorList = []
|
|
|
|
|
|
if (typeof b.uuid !== 'string')
|
|
if (typeof b.uuid !== 'string')
|
|
errorList.push('"uuid" must be a string.')
|
|
errorList.push('"uuid" must be a string.')
|
|
|
|
|
|
|
|
+ if (b.userId && typeof b.userId !== 'string')
|
|
|
|
+ errorList.push('"userId" must be a string.')
|
|
|
|
+
|
|
|
|
+ if (b.experimentId && typeof b.experimentId !== 'string')
|
|
|
|
+ errorList.push('"experimentId" must be a string.')
|
|
|
|
+
|
|
if (typeof b.screen !== 'object' || Object.keys(b.screen).length > 30)
|
|
if (typeof b.screen !== 'object' || Object.keys(b.screen).length > 30)
|
|
errorList.push('"screen" must be a valid object.')
|
|
errorList.push('"screen" must be a valid object.')
|
|
|
|
|
|
@@ -76,7 +87,9 @@ router.post('/', asyncMiddleware(async (req, res) => {
|
|
screen: b.screen,
|
|
screen: b.screen,
|
|
userAgent,
|
|
userAgent,
|
|
ip: req.ip
|
|
ip: req.ip
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ userid: b.userId || null,
|
|
|
|
+ experimentId: b.experimentId || null
|
|
}
|
|
}
|
|
|
|
|
|
if (!TEST_MODE) await DataController.add(data)
|
|
if (!TEST_MODE) await DataController.add(data)
|