Skip to content

Commit d9292db

Browse files
authored
Merge pull request #36 from Linkurious/develop
Release 1.0.8 [ci:run]
2 parents 06e41e8 + c717354 commit d9292db

8 files changed

Lines changed: 81 additions & 21 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.7
2+
current_version = 1.0.8
33
commit = False
44
tag = False
55
serialize =

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.7
1+
1.0.8

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ This plugin supports the following URL parameters in the query string:
3838

3939
| Param | Type | Description | Example |
4040
| :-- | :-- | :-- | :-- |
41-
| `queryId` | integer (**required**) | ID of the query to run. | `queryId=87` |
41+
| `queryId` | integer (**required**, forbidden if `queryName` is used) | ID of the query to run. | `queryId=87` |
42+
| `queryName` | string (**required**, forbidden if `queryId` is used) | Name of the query to run. | `queryName=getTransactions` |
4243
| `sourceKey` | string (**required**) | Key of the data-source to run the query on. | `sourceKey=b16e9ed5` |
4344
| `limit` | integer (**optional**) | Maximum number of results to display. | `limit=500` |
4445
| `param_number_{{Encoded field name}}` | number (**optional**) | *For query templates*, any numerical parameter of the template. | `param_number_age=30` |

backend/routeHandler.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,53 @@ module.exports = function configureRoutes(options) {
7474
res.send(JSON.stringify(query));
7575
});
7676

77+
options.router.post('/getQueryByName', async (req, res) => {
78+
try {
79+
// Checking templates
80+
const getQueryParams = {
81+
sourceKey: req.body.sourceKey,
82+
type: "template"
83+
};
84+
85+
let response = (await options.getRestClient(req).graphQuery.getQueries(getQueryParams));
86+
87+
let queries = response.body.filter((q) => {
88+
return q.name.toLowerCase() === req.body.name.toLowerCase();
89+
});
90+
91+
// Checking statics
92+
getQueryParams.type = "static"
93+
94+
response = (await options.getRestClient(req).graphQuery.getQueries(getQueryParams));
95+
96+
queries = queries.concat(response.body.filter((q) => {
97+
return q.name.toLowerCase() === req.body.name.toLowerCase();
98+
}));
99+
100+
if (queries.length === 0) {
101+
throw new Error(`Query ${req.body.name} either does not exist or you do not have access to it.`);
102+
}
103+
else if (queries.length === 1) {
104+
response.body = queries[0]
105+
res.status(200);
106+
res.contentType('application/json');
107+
res.send(JSON.stringify({body: queries[0]}));
108+
}
109+
else {
110+
throw new Error(`Multiple queries named ${req.body.name} exist. The query name must be unique.`);
111+
}
112+
} catch (error) {
113+
res.status(400);
114+
res.contentType('application/json');
115+
res.send(JSON.stringify({ status: 400, body: { error: {message: error.message } }}));
116+
}
117+
118+
});
119+
120+
77121
options.router.post('/runQueryByIDPlugin', async (req, res) => {
78122
const data = {
79-
id: +req.body.queryParams.global.queryId,
123+
id: +req.body.query.id,
80124
sourceKey: req.body.queryParams.global.sourceKey,
81125
limit: +req.body.queryParams.global.limit
82126
};

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "data-table",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"pluginApiVersion": "1.0.0",
55
"publicRoute": "public",
66
"singlePageAppIndex": "index.html",

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@linkurious/lke-plugin-data-table",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Data-table plugin for Linkurious Enterprise",
55
"main": "index.js",
66
"homepage": "https://github.com/Linkurious/lke-plugin-data-table#readme",

public/js/main.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ function getParameter(item) {
137137
oneOf: [
138138
'sourceKey',
139139
'limit',
140-
'queryId'
140+
'queryId',
141+
'queryName'
141142
],
142143
startWith: [
143144
'param_number_',
@@ -187,12 +188,14 @@ function validateTemplateFieldsParams(query) {
187188
* @returns {boolean|void}
188189
*/
189190
function validateGlobalQueryParams(params) {
190-
if (params.queryId === undefined) {
191-
return handleError({body: {message: 'Missing URL parameter “query_id”'}});
192-
} else if (!Number.isInteger(+params.queryId)) {
193-
return handleError({body: {message: 'URL parameter “query_id” must be a number'}});
191+
if (params.queryId === undefined && params.queryName === undefined) {
192+
return handleError({body: {message: 'Missing URL parameter: a “queryId” (number) or a “queryName” (string) is mandatory'}});
193+
} else if (params.queryId !== undefined && params.queryName !== undefined) {
194+
return handleError({body: {message: 'Only one query parameter is allowed: impossible to use “queryId” and “queryName” at the same moment'}});
195+
} else if (params.queryId !== undefined && !Number.isInteger(+params.queryId)) {
196+
return handleError({body: {message: 'URL parameter “queryId” must be a number'}});
194197
} else if (params.sourceKey === undefined) {
195-
return handleError({body: {message: 'Missing URL parameter “source_key” (must be a string)'}});
198+
return handleError({body: {message: 'Missing URL parameter “sourceKey” (must be a string)'}});
196199
}
197200
return true;
198201
}
@@ -682,14 +685,26 @@ function escapeDotCharacters(value) {
682685
*/
683686
async function getQuery() {
684687
try {
685-
return await makeRequest(
686-
'POST',
687-
`api/getQuery`,
688-
{
689-
id: queryParams.global.queryId,
690-
sourceKey: queryParams.global.sourceKey
691-
}
692-
);
688+
if (queryParams.global.queryId !== undefined){
689+
return await makeRequest(
690+
'POST',
691+
`api/getQuery`,
692+
{
693+
id: queryParams.global.queryId,
694+
sourceKey: queryParams.global.sourceKey
695+
}
696+
);
697+
} else {
698+
return await makeRequest(
699+
'POST',
700+
`api/getQueryByName`,
701+
{
702+
name: queryParams.global.queryName,
703+
sourceKey: queryParams.global.sourceKey
704+
}
705+
);
706+
}
707+
693708
} catch(e) {
694709
handleError(e);
695710
}

0 commit comments

Comments
 (0)