forest-express-sequelize 8.5.13 → 8.5.15-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/services/leaderboard-stat-getter.js +7 -6
- package/dist/services/line-stat-getter.js +7 -7
- package/dist/services/pie-stat-getter.js +10 -10
- package/dist/services/query-options.js +0 -3
- package/dist/services/query-stat-getter.js +0 -3
- package/dist/services/value-stat-getter.js +7 -7
- package/package.json +2 -2
- package/test/databases.test.js +45 -45
- package/test/integration/leaderboard-stat-getter.test.js +10 -10
- package/test/services/filters-parser.test.js +15 -14
- package/types/index.d.ts +4 -4
- package/dist/services/live-query-checker.js +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [8.5.15-beta.1](https://github.com/ForestAdmin/forest-express-sequelize/compare/v8.5.14...v8.5.15-beta.1) (2022-10-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **chart:** improve security on chart and rename keys ([#1020](https://github.com/ForestAdmin/forest-express-sequelize/issues/1020)) ([fbfe2cf](https://github.com/ForestAdmin/forest-express-sequelize/commit/fbfe2cf8a38151c3e700a42a701d8445caabc37e))
|
|
7
|
+
|
|
8
|
+
## [8.5.14](https://github.com/ForestAdmin/forest-express-sequelize/compare/v8.5.13...v8.5.14) (2022-10-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **type:** add generic for SmartActionRequestBody ([#1024](https://github.com/ForestAdmin/forest-express-sequelize/issues/1024)) ([bcd16af](https://github.com/ForestAdmin/forest-express-sequelize/commit/bcd16af41f70d953258f8f5b745eab30e89d08bb))
|
|
14
|
+
|
|
1
15
|
## [8.5.13](https://github.com/ForestAdmin/forest-express-sequelize/compare/v8.5.12...v8.5.13) (2022-09-28)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -38,16 +38,17 @@ async function getSequelizeOptionsForModel(model, user, timezone) {
|
|
|
38
38
|
* @param {import('sequelize').Model} childModel
|
|
39
39
|
* @param {import('sequelize').Model} parentModel
|
|
40
40
|
* @param {{
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* labelFieldName: string;
|
|
42
|
+
* aggregator: string;
|
|
43
|
+
* aggregateFieldName: string;
|
|
44
|
+
* limit: number;
|
|
44
45
|
* }} params
|
|
45
46
|
*/
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
function LeaderboardStatGetter(childModel, parentModel, params, user) {
|
|
49
|
-
const labelField = params.
|
|
50
|
-
const aggregate = params.
|
|
50
|
+
const labelField = params.labelFieldName;
|
|
51
|
+
const aggregate = params.aggregator.toUpperCase();
|
|
51
52
|
const {
|
|
52
53
|
limit
|
|
53
54
|
} = params;
|
|
@@ -60,7 +61,7 @@ function LeaderboardStatGetter(childModel, parentModel, params, user) {
|
|
|
60
61
|
});
|
|
61
62
|
|
|
62
63
|
const aggregateField = getAggregateField({
|
|
63
|
-
aggregateField: params.
|
|
64
|
+
aggregateField: params.aggregateFieldName,
|
|
64
65
|
parentSchema,
|
|
65
66
|
parentModel
|
|
66
67
|
});
|
|
@@ -30,16 +30,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
30
30
|
|
|
31
31
|
function LineStatGetter(model, params, options, user) {
|
|
32
32
|
const schema = _forestExpress.Schemas.schemas[model.name];
|
|
33
|
-
const timeRange = params.
|
|
33
|
+
const timeRange = params.timeRange.toLowerCase();
|
|
34
34
|
|
|
35
35
|
function getAggregateField() {
|
|
36
36
|
// NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'.
|
|
37
|
-
const fieldName = params.
|
|
37
|
+
const fieldName = params.aggregateFieldName || schema.primaryKeys[0] || schema.fields[0].field;
|
|
38
38
|
return `${schema.name}.${_orm.default.getColumnName(schema, fieldName)}`;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function getGroupByDateField() {
|
|
42
|
-
return `${schema.name}.${_orm.default.getColumnName(schema, params.
|
|
42
|
+
return `${schema.name}.${_orm.default.getColumnName(schema, params.groupByFieldName)}`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const groupByDateField = getGroupByDateField();
|
|
@@ -128,7 +128,7 @@ ${groupByDateFieldFormated}), 'yyyy-MM-dd 00:00:00')`);
|
|
|
128
128
|
return [getGroupByDateFieldFormatedForSQLite(timeRange), 'date'];
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
return [options.Sequelize.fn('to_char', options.Sequelize.fn('date_trunc', params.
|
|
131
|
+
return [options.Sequelize.fn('to_char', options.Sequelize.fn('date_trunc', params.timeRange, options.Sequelize.literal(`"${getGroupByDateField().replace('.', '"."')}" at time zone '${params.timezone}'`)), 'YYYY-MM-DD 00:00:00'), 'date'];
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
function getFormat() {
|
|
@@ -189,7 +189,7 @@ ${groupByDateFieldFormated}), 'yyyy-MM-dd 00:00:00')`);
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
function getAggregate() {
|
|
192
|
-
return [options.Sequelize.fn(params.
|
|
192
|
+
return [options.Sequelize.fn(params.aggregator.toLowerCase(), options.Sequelize.col(getAggregateField())), 'value'];
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
function getGroupBy() {
|
|
@@ -202,14 +202,14 @@ ${groupByDateFieldFormated}), 'yyyy-MM-dd 00:00:00')`);
|
|
|
202
202
|
|
|
203
203
|
this.perform = async function () {
|
|
204
204
|
const {
|
|
205
|
-
|
|
205
|
+
filter,
|
|
206
206
|
timezone
|
|
207
207
|
} = params;
|
|
208
208
|
const scopeFilters = await _forestExpress.scopeManager.getScopeForUser(user, model.name, true);
|
|
209
209
|
const queryOptions = new _queryOptions.default(model, {
|
|
210
210
|
includeRelations: true
|
|
211
211
|
});
|
|
212
|
-
await queryOptions.filterByConditionTree(
|
|
212
|
+
await queryOptions.filterByConditionTree(filter, timezone);
|
|
213
213
|
await queryOptions.filterByConditionTree(scopeFilters, timezone);
|
|
214
214
|
|
|
215
215
|
const sequelizeOptions = _objectSpread(_objectSpread({}, queryOptions.sequelizeOptions), {}, {
|
|
@@ -43,12 +43,12 @@ function PieStatGetter(model, params, options, user) {
|
|
|
43
43
|
let associationSchema;
|
|
44
44
|
let field;
|
|
45
45
|
|
|
46
|
-
if (params.
|
|
46
|
+
if (params.groupByFieldName.indexOf(':') === -1) {
|
|
47
47
|
field = _lodash.default.find(schema.fields, function (currentField) {
|
|
48
|
-
return currentField.field === params.
|
|
48
|
+
return currentField.field === params.groupByFieldName;
|
|
49
49
|
});
|
|
50
50
|
} else {
|
|
51
|
-
associationSplit = params.
|
|
51
|
+
associationSplit = params.groupByFieldName.split(':');
|
|
52
52
|
associationCollection = model.associations[associationSplit[0]].target.name;
|
|
53
53
|
[, associationField] = associationSplit;
|
|
54
54
|
associationSchema = _forestExpress.Schemas.schemas[associationCollection];
|
|
@@ -58,23 +58,23 @@ function PieStatGetter(model, params, options, user) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function getGroupByField() {
|
|
61
|
-
if (params.
|
|
62
|
-
const [associationName, fieldName] = params.
|
|
61
|
+
if (params.groupByFieldName.includes(':')) {
|
|
62
|
+
const [associationName, fieldName] = params.groupByFieldName.split(':');
|
|
63
63
|
return `${associationName}.${_orm.default.getColumnName(associationSchema, fieldName)}`;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
return `${schema.name}.${_orm.default.getColumnName(schema, params.
|
|
66
|
+
return `${schema.name}.${_orm.default.getColumnName(schema, params.groupByFieldName)}`;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const groupByField = getGroupByField();
|
|
70
70
|
|
|
71
71
|
function getAggregate() {
|
|
72
|
-
return params.
|
|
72
|
+
return params.aggregator.toLowerCase();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function getAggregateField() {
|
|
76
76
|
// NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'.
|
|
77
|
-
const fieldName = params.
|
|
77
|
+
const fieldName = params.aggregateFieldName || schema.primaryKeys[0] || schema.fields[0].field;
|
|
78
78
|
return `${schema.name}.${_orm.default.getColumnName(schema, fieldName)}`;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -107,14 +107,14 @@ function PieStatGetter(model, params, options, user) {
|
|
|
107
107
|
|
|
108
108
|
this.perform = async function () {
|
|
109
109
|
const {
|
|
110
|
-
|
|
110
|
+
filter,
|
|
111
111
|
timezone
|
|
112
112
|
} = params;
|
|
113
113
|
const scopeFilters = await _forestExpress.scopeManager.getScopeForUser(user, model.name, true);
|
|
114
114
|
const queryOptions = new _queryOptions.default(model, {
|
|
115
115
|
includeRelations: true
|
|
116
116
|
});
|
|
117
|
-
await queryOptions.filterByConditionTree(
|
|
117
|
+
await queryOptions.filterByConditionTree(filter, timezone);
|
|
118
118
|
await queryOptions.filterByConditionTree(scopeFilters, timezone);
|
|
119
119
|
|
|
120
120
|
const sequelizeOptions = _objectSpread(_objectSpread({}, queryOptions.sequelizeOptions), {}, {
|
|
@@ -26,8 +26,6 @@ var _errors = require("./errors");
|
|
|
26
26
|
|
|
27
27
|
var _filtersParser = _interopRequireDefault(require("./filters-parser"));
|
|
28
28
|
|
|
29
|
-
var _liveQueryChecker = _interopRequireDefault(require("./live-query-checker"));
|
|
30
|
-
|
|
31
29
|
var _primaryKeysManager = _interopRequireDefault(require("./primary-keys-manager"));
|
|
32
30
|
|
|
33
31
|
var _queryBuilder = _interopRequireDefault(require("./query-builder"));
|
|
@@ -296,7 +294,6 @@ class QueryOptions {
|
|
|
296
294
|
const primaryKey = _lodash.default.values(this._model.primaryKeys)[0].field;
|
|
297
295
|
|
|
298
296
|
const queryToFilterRecords = query.trim();
|
|
299
|
-
new _liveQueryChecker.default().perform(queryToFilterRecords);
|
|
300
297
|
|
|
301
298
|
try {
|
|
302
299
|
const options = {
|
|
@@ -8,8 +8,6 @@ require("core-js/modules/es.string.replace.js");
|
|
|
8
8
|
|
|
9
9
|
require("core-js/modules/es.regexp.constructor.js");
|
|
10
10
|
|
|
11
|
-
const LiveQueryChecker = require('./live-query-checker');
|
|
12
|
-
|
|
13
11
|
function QueryStatGetter(params, opts) {
|
|
14
12
|
const QUERY_OPTIONS_SELECT = {
|
|
15
13
|
type: opts.Sequelize.QueryTypes.SELECT
|
|
@@ -17,7 +15,6 @@ function QueryStatGetter(params, opts) {
|
|
|
17
15
|
|
|
18
16
|
this.perform = function perform() {
|
|
19
17
|
let rawQuery = params.query.trim();
|
|
20
|
-
new LiveQueryChecker().perform(rawQuery);
|
|
21
18
|
|
|
22
19
|
if (params.record_id) {
|
|
23
20
|
rawQuery = rawQuery.replace(new RegExp('\\?', 'g'), params.record_id);
|
|
@@ -41,27 +41,27 @@ class ValueStatGetter {
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
get _aggregateFunction() {
|
|
44
|
-
return this._params.
|
|
44
|
+
return this._params.aggregator.toLowerCase();
|
|
45
45
|
}
|
|
46
46
|
/** Column name we're aggregating on */
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
get _aggregateField() {
|
|
50
50
|
// NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'.
|
|
51
|
-
const fieldName = this._params.
|
|
51
|
+
const fieldName = this._params.aggregateFieldName || this._schema.primaryKeys[0] || this._schema.fields[0].field;
|
|
52
52
|
return `${this._schema.name}.${_orm.default.getColumnName(this._schema, fieldName)}`;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
async perform() {
|
|
56
56
|
const {
|
|
57
|
-
|
|
57
|
+
filter,
|
|
58
58
|
timezone
|
|
59
59
|
} = this._params;
|
|
60
60
|
const scopeFilters = await _forestExpress.scopeManager.getScopeForUser(this._user, this._model.name, true);
|
|
61
61
|
const queryOptions = new _queryOptions.default(this._model, {
|
|
62
62
|
includeRelations: true
|
|
63
63
|
});
|
|
64
|
-
await queryOptions.filterByConditionTree(
|
|
64
|
+
await queryOptions.filterByConditionTree(filter, timezone);
|
|
65
65
|
await queryOptions.filterByConditionTree(scopeFilters, timezone); // No attributes should be retrieved from relations for the group by to work.
|
|
66
66
|
|
|
67
67
|
const options = queryOptions.sequelizeOptions;
|
|
@@ -94,16 +94,16 @@ class ValueStatGetter {
|
|
|
94
94
|
|
|
95
95
|
async _getCountPrevious(options) {
|
|
96
96
|
const {
|
|
97
|
-
|
|
97
|
+
filter,
|
|
98
98
|
timezone
|
|
99
99
|
} = this._params;
|
|
100
100
|
|
|
101
|
-
if (!
|
|
101
|
+
if (!filter) {
|
|
102
102
|
return undefined;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
const conditionsParser = new _filtersParser.default(this._schema, timezone, this._options);
|
|
106
|
-
const rawInterval = conditionsParser.getPreviousIntervalCondition(
|
|
106
|
+
const rawInterval = conditionsParser.getPreviousIntervalCondition(filter);
|
|
107
107
|
|
|
108
108
|
if (!rawInterval) {
|
|
109
109
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forest-express-sequelize",
|
|
3
3
|
"description": "Official Express/Sequelize Liana for Forest",
|
|
4
|
-
"version": "8.5.
|
|
4
|
+
"version": "8.5.15-beta.1",
|
|
5
5
|
"author": "Sandro Munda <sandro@munda.me>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Arnaud Besnier <arnaudibesnier@gmail.com>",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@babel/runtime": "7.15.4",
|
|
29
29
|
"bluebird": "2.9.25",
|
|
30
30
|
"core-js": "3.6.5",
|
|
31
|
-
"forest-express": "
|
|
31
|
+
"forest-express": "10.0.0-beta.2",
|
|
32
32
|
"http-errors": "1.6.1",
|
|
33
33
|
"lodash": "4.17.21",
|
|
34
34
|
"moment": "2.29.4",
|
package/test/databases.test.js
CHANGED
|
@@ -552,11 +552,11 @@ const user = { renderingId: 1 };
|
|
|
552
552
|
const stat = await new PieStatGetter(models.user, {
|
|
553
553
|
...baseParams,
|
|
554
554
|
type: 'Pie',
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
555
|
+
sourceCollectionName: 'user',
|
|
556
|
+
groupByFieldName: 'firstName',
|
|
557
|
+
aggregator: 'Count',
|
|
558
|
+
timeRange: null,
|
|
559
|
+
filter: null,
|
|
560
560
|
}, options, user).perform();
|
|
561
561
|
expect(stat.value).toHaveLength(3);
|
|
562
562
|
} finally {
|
|
@@ -575,11 +575,11 @@ const user = { renderingId: 1 };
|
|
|
575
575
|
const stat = await new PieStatGetter(models.addressWithUserAlias, {
|
|
576
576
|
...baseParams,
|
|
577
577
|
type: 'Pie',
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
578
|
+
sourceCollectionName: 'addressWithUserAlias',
|
|
579
|
+
groupByFieldName: 'userAlias:primaryId',
|
|
580
|
+
aggregator: 'Count',
|
|
581
|
+
timeRange: null,
|
|
582
|
+
filter: null,
|
|
583
583
|
}, options, user).perform();
|
|
584
584
|
expect(stat.value).toBeEmpty();
|
|
585
585
|
} finally {
|
|
@@ -601,11 +601,11 @@ const user = { renderingId: 1 };
|
|
|
601
601
|
const stat = await new LineStatGetter(models.user, {
|
|
602
602
|
...baseParams,
|
|
603
603
|
type: 'Line',
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
604
|
+
sourceCollectionName: 'user',
|
|
605
|
+
groupByFieldName: 'createdAt',
|
|
606
|
+
aggregator: 'Count',
|
|
607
|
+
timeRange: 'Day',
|
|
608
|
+
filter: null,
|
|
609
609
|
}, options, user).perform();
|
|
610
610
|
expect(stat.value).toHaveLength(1);
|
|
611
611
|
} finally {
|
|
@@ -624,11 +624,11 @@ const user = { renderingId: 1 };
|
|
|
624
624
|
const stat = await new LineStatGetter(models.user, {
|
|
625
625
|
...baseParams,
|
|
626
626
|
type: 'Line',
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
627
|
+
sourceCollectionName: 'user',
|
|
628
|
+
groupByFieldName: 'createdAt',
|
|
629
|
+
aggregator: 'Count',
|
|
630
|
+
timeRange: 'Week',
|
|
631
|
+
filter: null,
|
|
632
632
|
}, options, user).perform();
|
|
633
633
|
expect(stat.value).toHaveLength(1);
|
|
634
634
|
} finally {
|
|
@@ -647,11 +647,11 @@ const user = { renderingId: 1 };
|
|
|
647
647
|
const stat = await new LineStatGetter(models.user, {
|
|
648
648
|
...baseParams,
|
|
649
649
|
type: 'Line',
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
650
|
+
sourceCollectionName: 'user',
|
|
651
|
+
groupByFieldName: 'createdAt',
|
|
652
|
+
aggregator: 'Count',
|
|
653
|
+
timeRange: 'Month',
|
|
654
|
+
filter: null,
|
|
655
655
|
}, options, user).perform();
|
|
656
656
|
expect(stat.value).toHaveLength(1);
|
|
657
657
|
} finally {
|
|
@@ -670,11 +670,11 @@ const user = { renderingId: 1 };
|
|
|
670
670
|
const stat = await new LineStatGetter(models.user, {
|
|
671
671
|
...baseParams,
|
|
672
672
|
type: 'Line',
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
673
|
+
sourceCollectionName: 'user',
|
|
674
|
+
groupByFieldName: 'createdAt',
|
|
675
|
+
aggregator: 'Count',
|
|
676
|
+
timeRange: 'Year',
|
|
677
|
+
filter: null,
|
|
678
678
|
}, options, user).perform();
|
|
679
679
|
expect(stat.value).toHaveLength(1);
|
|
680
680
|
} finally {
|
|
@@ -693,11 +693,11 @@ const user = { renderingId: 1 };
|
|
|
693
693
|
const stat = await new LineStatGetter(models.address, {
|
|
694
694
|
...baseParams,
|
|
695
695
|
type: 'Line',
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
696
|
+
sourceCollectionName: 'address',
|
|
697
|
+
groupByFieldName: 'createdAt',
|
|
698
|
+
aggregator: 'Count',
|
|
699
|
+
timeRange: 'Year',
|
|
700
|
+
filter: { field: 'user:primaryId', operator: 'equal', value: 100 },
|
|
701
701
|
}, options, user).perform();
|
|
702
702
|
expect(stat.value).toHaveLength(1);
|
|
703
703
|
} finally {
|
|
@@ -718,8 +718,8 @@ const user = { renderingId: 1 };
|
|
|
718
718
|
const stat = await new ValueStatGetter(models.user, {
|
|
719
719
|
...baseParams,
|
|
720
720
|
type: 'Value',
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
aggregator: 'Sum',
|
|
722
|
+
aggregateFieldName: 'primaryId',
|
|
723
723
|
}, options, user).perform();
|
|
724
724
|
|
|
725
725
|
expect(stat.value).toStrictEqual({ countCurrent: 305, countPrevious: undefined });
|
|
@@ -738,9 +738,9 @@ const user = { renderingId: 1 };
|
|
|
738
738
|
const stat = await new ValueStatGetter(models.user, {
|
|
739
739
|
...baseParams,
|
|
740
740
|
type: 'Value',
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
741
|
+
aggregator: 'Sum',
|
|
742
|
+
aggregateFieldName: 'primaryId',
|
|
743
|
+
filter: '{"field":"createdAt","operator":"previous_month_to_date","value":null}',
|
|
744
744
|
}, options, user).perform();
|
|
745
745
|
|
|
746
746
|
expect(stat.value).toStrictEqual({ countCurrent: 305, countPrevious: 0 });
|
|
@@ -759,9 +759,9 @@ const user = { renderingId: 1 };
|
|
|
759
759
|
const stat = await new ValueStatGetter(models.user, {
|
|
760
760
|
...baseParams,
|
|
761
761
|
type: 'Value',
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
762
|
+
aggregator: 'Sum',
|
|
763
|
+
aggregateFieldName: 'primaryId',
|
|
764
|
+
filter: JSON.stringify({
|
|
765
765
|
aggregator: 'and',
|
|
766
766
|
conditions: [
|
|
767
767
|
{ field: 'createdAt', operator: 'previous_month_to_date', value: null },
|
|
@@ -786,8 +786,8 @@ const user = { renderingId: 1 };
|
|
|
786
786
|
const stat = await new ValueStatGetter(models.address, {
|
|
787
787
|
...baseParams,
|
|
788
788
|
type: 'Value',
|
|
789
|
-
|
|
790
|
-
|
|
789
|
+
aggregator: 'Count',
|
|
790
|
+
filter: { field: 'user:primaryId', operator: 'greater_than', value: 0 },
|
|
791
791
|
}, options, user).perform();
|
|
792
792
|
|
|
793
793
|
expect(stat.value).toStrictEqual({ countCurrent: 4, countPrevious: undefined });
|
|
@@ -137,8 +137,8 @@ describe('integration > LeaderboardStatGetter', () => {
|
|
|
137
137
|
const { models } = await setup(sequelize);
|
|
138
138
|
|
|
139
139
|
const params = {
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
labelFieldName: 'firstName',
|
|
141
|
+
aggregator: 'count',
|
|
142
142
|
limit: 10,
|
|
143
143
|
};
|
|
144
144
|
|
|
@@ -169,9 +169,9 @@ describe('integration > LeaderboardStatGetter', () => {
|
|
|
169
169
|
const { models } = await setup(sequelize);
|
|
170
170
|
|
|
171
171
|
const params = {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
labelFieldName: 'firstName',
|
|
173
|
+
aggregator: 'sum',
|
|
174
|
+
aggregateFieldName: 'sellingAmount',
|
|
175
175
|
limit: 10,
|
|
176
176
|
};
|
|
177
177
|
|
|
@@ -204,8 +204,8 @@ describe('integration > LeaderboardStatGetter', () => {
|
|
|
204
204
|
const { models } = await setup(sequelize);
|
|
205
205
|
|
|
206
206
|
const params = {
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
labelFieldName: 'firstName',
|
|
208
|
+
aggregator: 'count',
|
|
209
209
|
limit: 10,
|
|
210
210
|
};
|
|
211
211
|
|
|
@@ -236,9 +236,9 @@ describe('integration > LeaderboardStatGetter', () => {
|
|
|
236
236
|
const { models } = await setup(sequelize);
|
|
237
237
|
|
|
238
238
|
const params = {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
labelFieldName: 'firstName',
|
|
240
|
+
aggregator: 'sum',
|
|
241
|
+
aggregateFieldName: 'objectiveScore',
|
|
242
242
|
limit: 10,
|
|
243
243
|
};
|
|
244
244
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import Sequelize from 'sequelize';
|
|
3
|
-
import { SchemaUtils } from 'forest-express';
|
|
3
|
+
import { Schemas, SchemaUtils } from 'forest-express';
|
|
4
4
|
import FiltersParser from '../../src/services/filters-parser';
|
|
5
5
|
import Operators from '../../src/utils/operators';
|
|
6
6
|
import { NoMatchingOperatorError } from '../../src/services/errors';
|
|
@@ -227,7 +227,8 @@ describe('services > filters-parser', () => {
|
|
|
227
227
|
const schemaWithFields = {
|
|
228
228
|
fields: [{ field: 'car', reference: 'car.id' }],
|
|
229
229
|
};
|
|
230
|
-
|
|
230
|
+
Schemas.schemas = { car: { fields: [{ field: 'id', type: 'Number' }] } };
|
|
231
|
+
const filters = { field: 'car:brandName', operator: 'starts_with', value: 'Ferrari' };
|
|
231
232
|
const filtersParser = new FiltersParser(schemaWithFields, timezone, sequelizeOptions);
|
|
232
233
|
|
|
233
234
|
it('should not be null', async () => {
|
|
@@ -246,10 +247,10 @@ describe('services > filters-parser', () => {
|
|
|
246
247
|
describe('getPreviousIntervalCondition function', () => {
|
|
247
248
|
describe('working scenarii', () => {
|
|
248
249
|
describe('with \'and\' aggregator + flat conditions + 1 previous interval', () => {
|
|
249
|
-
const aggregator =
|
|
250
|
+
const aggregator = {
|
|
250
251
|
aggregator: 'and',
|
|
251
252
|
conditions: [defaultCondition, defaultCondition2, defaultDateCondition],
|
|
252
|
-
}
|
|
253
|
+
};
|
|
253
254
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
254
255
|
|
|
255
256
|
it('should generate the right condition', () => {
|
|
@@ -260,7 +261,7 @@ describe('services > filters-parser', () => {
|
|
|
260
261
|
});
|
|
261
262
|
|
|
262
263
|
describe('with no aggregator + flat conditions + 1 previous interval', () => {
|
|
263
|
-
const aggregator =
|
|
264
|
+
const aggregator = defaultDateCondition;
|
|
264
265
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
265
266
|
|
|
266
267
|
it('should generate the right condition', () => {
|
|
@@ -273,10 +274,10 @@ describe('services > filters-parser', () => {
|
|
|
273
274
|
|
|
274
275
|
describe('not working scenarii', () => {
|
|
275
276
|
describe('with \'and\' aggregator + flat conditions + 2 previous intervals', () => {
|
|
276
|
-
const aggregator =
|
|
277
|
+
const aggregator = {
|
|
277
278
|
aggregator: 'and',
|
|
278
279
|
conditions: [defaultCondition, defaultDateCondition, defaultDateCondition],
|
|
279
|
-
}
|
|
280
|
+
};
|
|
280
281
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
281
282
|
|
|
282
283
|
it('should not generate conditions', () => {
|
|
@@ -286,10 +287,10 @@ describe('services > filters-parser', () => {
|
|
|
286
287
|
});
|
|
287
288
|
|
|
288
289
|
describe('with \'or\' aggregator + flat conditions + 1 previous interval', () => {
|
|
289
|
-
const aggregator =
|
|
290
|
+
const aggregator = {
|
|
290
291
|
aggregator: 'or',
|
|
291
292
|
conditions: [defaultCondition, defaultCondition2, defaultDateCondition],
|
|
292
|
-
}
|
|
293
|
+
};
|
|
293
294
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
294
295
|
|
|
295
296
|
it('should not generate conditions', () => {
|
|
@@ -299,10 +300,10 @@ describe('services > filters-parser', () => {
|
|
|
299
300
|
});
|
|
300
301
|
|
|
301
302
|
describe('with \'and\' aggregator + flat conditions + 0 previous interval', () => {
|
|
302
|
-
const aggregator =
|
|
303
|
+
const aggregator = {
|
|
303
304
|
aggregator: 'and',
|
|
304
305
|
conditions: [defaultCondition, defaultCondition2],
|
|
305
|
-
}
|
|
306
|
+
};
|
|
306
307
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
307
308
|
|
|
308
309
|
it('should not generate conditions', () => {
|
|
@@ -312,10 +313,10 @@ describe('services > filters-parser', () => {
|
|
|
312
313
|
});
|
|
313
314
|
|
|
314
315
|
describe('with \'and\' aggregator + nested conditions + 1 previous interval', () => {
|
|
315
|
-
const aggregator =
|
|
316
|
+
const aggregator = {
|
|
316
317
|
aggregator: 'and',
|
|
317
318
|
conditions: [{ aggregator: 'or', conditions: [defaultCondition, defaultCondition2] }, defaultDateCondition],
|
|
318
|
-
}
|
|
319
|
+
};
|
|
319
320
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
320
321
|
|
|
321
322
|
it('should not generate conditions', () => {
|
|
@@ -325,7 +326,7 @@ describe('services > filters-parser', () => {
|
|
|
325
326
|
});
|
|
326
327
|
|
|
327
328
|
describe('with no aggregator + flat conditions + 0 previous interval', () => {
|
|
328
|
-
const aggregator =
|
|
329
|
+
const aggregator = defaultCondition;
|
|
329
330
|
const filtersParser = new FiltersParser(schema, timezone, sequelizeOptions);
|
|
330
331
|
|
|
331
332
|
it('should not generate conditions', () => {
|
package/types/index.d.ts
CHANGED
|
@@ -72,9 +72,9 @@ interface ActionRequestBody {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Base body from requests for classic smart action routes
|
|
75
|
-
interface SmartActionRequestBody {
|
|
75
|
+
interface SmartActionRequestBody<T extends Record<string, any> = Record<string, any>> {
|
|
76
76
|
data: {
|
|
77
|
-
attributes: ActionRequestAttributes & { values:
|
|
77
|
+
attributes: ActionRequestAttributes & { values: T },
|
|
78
78
|
type: 'custom-action-requests',
|
|
79
79
|
},
|
|
80
80
|
}
|
|
@@ -91,8 +91,8 @@ interface SmartActionHookRequestBody {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// Concrete smart action request for classic smart action routes
|
|
94
|
-
export interface SmartActionRequest extends ForestRequest {
|
|
95
|
-
body: SmartActionRequestBody
|
|
94
|
+
export interface SmartActionRequest<T extends Record<string, any> = Record<string, any>> extends ForestRequest {
|
|
95
|
+
body: SmartActionRequestBody<T>,
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// Request passed to smart action load hooks
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
ErrorHTTP422
|
|
5
|
-
} = require('./errors');
|
|
6
|
-
|
|
7
|
-
function LiveQueryChecker() {
|
|
8
|
-
const QUERY_SELECT = /^SELECT\s[^]*FROM\s[^]*$/i;
|
|
9
|
-
|
|
10
|
-
this.perform = function perform(query) {
|
|
11
|
-
if (!query) {
|
|
12
|
-
throw new ErrorHTTP422('You cannot execute an empty SQL query.');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (query.includes(';') && query.indexOf(';') < query.length - 1) {
|
|
16
|
-
throw new ErrorHTTP422('You cannot chain SQL queries.');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!QUERY_SELECT.test(query)) {
|
|
20
|
-
throw new ErrorHTTP422('Only SELECT queries are allowed.');
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = LiveQueryChecker;
|