From 0f6753060f6f06393cf542049b8a224976d26846 Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Tue, 6 Nov 2018 16:17:05 +0300 Subject: [PATCH 1/2] get fog list params in query --- package.json | 3 +- src/controllers/iofog-controller.js | 8 +-- src/routes/iofog.js | 4 +- ...Controller Testing.postman_collection.json | 49 +++++++++++-------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 2d32ad068..f3ba2e25d 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,8 @@ "umzug": "^2.1.0", "underscore": "^1.9.1", "winston": "^3.1.0", - "xss-clean": "^0.1.1" + "xss-clean": "^0.1.1", + "qs": "^6.5.2" }, "devDependencies": { "eslint": "^5.6.1" diff --git a/src/controllers/iofog-controller.js b/src/controllers/iofog-controller.js index 99832bc59..a037cbd15 100644 --- a/src/controllers/iofog-controller.js +++ b/src/controllers/iofog-controller.js @@ -14,6 +14,8 @@ const logger = require('../logger'); const AuthDecorator = require('../decorators/authorization-decorator'); const FogService = require('../services/iofog-service'); +const querystring = require('querystring'); +const qs = require('qs'); async function _createFog(req, user) { logger.info("Parameters:" + JSON.stringify(req.body)); @@ -43,9 +45,9 @@ async function _getFog(req, user) { } async function _getFogList(req, user) { - logger.info("Parameters:" + JSON.stringify(req.body)); - const filters = Array.from(req.body); - return await FogService.getFogListWithTransaction(filters, user, false) + logger.info("Parameters:" + JSON.stringify(req.query)); + const query = qs.parse(req.query) + return await FogService.getFogListWithTransaction(query.filters, user, false) } async function _generateProvisioningKey(req, user) { diff --git a/src/routes/iofog.js b/src/routes/iofog.js index 9f987cd3a..2853e97ed 100644 --- a/src/routes/iofog.js +++ b/src/routes/iofog.js @@ -17,7 +17,7 @@ const Errors = require('../helpers/errors'); module.exports = [ { - method: 'post', + method: 'get', path: '/api/v3/iofog-list', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_SUCCESS; @@ -154,7 +154,7 @@ module.exports = [ code: 404, errors: [Errors.NotFoundError] } - ] + ]; const generateFogProvisioningKey = ResponseDecorator.handleErrors(FogController.generateProvisioningKey, successCode, errCodes); const responseObject = await generateFogProvisioningKey(req); diff --git a/tests/Controller Testing.postman_collection.json b/tests/Controller Testing.postman_collection.json index f81b2f80b..05258cdf6 100644 --- a/tests/Controller Testing.postman_collection.json +++ b/tests/Controller Testing.postman_collection.json @@ -1,12 +1,13 @@ { "info": { - "_postman_id": "0c412a3a-7328-4c9e-8919-d2836adccfa1", + "_postman_id": "b585aece-cb86-4f3b-93f3-12552c1c90c5", "name": "Controller Testing", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "User", + "description": null, "item": [ { "name": "Create user", @@ -509,6 +510,7 @@ }, { "name": "General", + "description": null, "item": [ { "name": "Status", @@ -631,6 +633,7 @@ }, { "name": "Agent", + "description": null, "item": [ { "name": "Create user", @@ -856,7 +859,6 @@ "method": "POST", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" } @@ -906,7 +908,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -954,7 +955,6 @@ "method": "PATCH", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1008,7 +1008,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1057,7 +1056,6 @@ "method": "PUT", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1108,7 +1106,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1159,7 +1156,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1211,7 +1207,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1262,7 +1257,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1310,7 +1304,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1361,7 +1354,6 @@ "method": "PUT", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1412,7 +1404,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1559,7 +1550,6 @@ "method": "GET", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1657,7 +1647,6 @@ "method": "DELETE", "header": [ { - "disabled": false, "key": "Content-Type", "value": "application/json" }, @@ -1735,6 +1724,7 @@ }, { "name": "Flow", + "description": null, "item": [ { "name": "Create user", @@ -2121,6 +2111,7 @@ }, { "name": "Catalog", + "description": null, "item": [ { "name": "Create user", @@ -2516,6 +2507,7 @@ }, { "name": "Tunnel", + "description": null, "item": [ { "name": "Create user", @@ -2859,6 +2851,7 @@ }, { "name": "Microservices", + "description": null, "item": [ { "name": "Create user", @@ -3795,6 +3788,7 @@ }, { "name": "Diagnostics", + "description": null, "item": [ { "name": "Create user", @@ -4589,6 +4583,7 @@ }, { "name": "ioFog", + "description": null, "item": [ { "name": "Create user", @@ -4809,7 +4804,7 @@ } ], "request": { - "method": "POST", + "method": "GET", "header": [ { "key": "Content-Type", @@ -4817,16 +4812,15 @@ }, { "key": "Authorization", - "value": "{{user-token}}", - "type": "text" + "value": "{{user-token}}" } ], "body": { "mode": "raw", - "raw": "[\n {\n \"key\": \"uuid\",\n \"value\": \"{{node-id}}\",\n \"condition\": \"equals\"\n }\n]" + "raw": "" }, "url": { - "raw": "{{host}}/api/v3/iofog-list", + "raw": "{{host}}/api/v3/iofog-list?filters[0][key]=uuid&filters[0][value]={{node-id}}&filters[0][condition]=equals", "host": [ "{{host}}" ], @@ -4834,6 +4828,20 @@ "api", "v3", "iofog-list" + ], + "query": [ + { + "key": "filters[0][key]", + "value": "uuid" + }, + { + "key": "filters[0][value]", + "value": "{{node-id}}" + }, + { + "key": "filters[0][condition]", + "value": "equals" + } ] } }, @@ -5282,6 +5290,7 @@ }, { "name": "Registries", + "description": null, "item": [ { "name": "Create user", From 21979ff2fd7690f856031601a4b0bb89b83e875f Mon Sep 17 00:00:00 2001 From: maksimchepelev Date: Fri, 9 Nov 2018 16:41:41 +0300 Subject: [PATCH 2/2] transaction validation --- src/decorators/transaction-decorator.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/decorators/transaction-decorator.js b/src/decorators/transaction-decorator.js index e51902491..4408ad532 100644 --- a/src/decorators/transaction-decorator.js +++ b/src/decorators/transaction-decorator.js @@ -14,16 +14,21 @@ const db = require('./../sequelize/models'); const retry = require('retry-as-promised'); const sequelize = db.sequelize; +// const Transaction = require('sequelize/lib/transaction'); function transaction(f) { - return function () { + return async function() { const fArgs = Array.prototype.slice.call(arguments); // To be removed when transactions concurrency issue fixed + // if (fArgs[fArgs.length - 1] instanceof Transaction) { + // return await f.apply(this, fArgs); + // } else { return f.apply(this, fArgs) - // return sequelize.transaction(async (t) => { - // fArgs.push(t); - // return await f.apply(this, fArgs); - // }) + // return sequelize.transaction(async (t) => { + // fArgs.push(t); + // return await f.apply(this, fArgs); + // }) + // } } }