Skip to content

Commit

Permalink
chore: release beta branch (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentMolinie authored Nov 9, 2022
2 parents ade816e + e8e7b95 commit c2a80d0
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 100 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# [9.0.0-beta.4](https://github.com/ForestAdmin/forest-express-mongoose/compare/v9.0.0-beta.3...v9.0.0-beta.4) (2022-11-02)


### Features

* **chart:** add support for context variables used by Workspaces ([#957](https://github.com/ForestAdmin/forest-express-mongoose/issues/957)) ([39e7c4a](https://github.com/ForestAdmin/forest-express-mongoose/commit/39e7c4aa8cc7750da0cc15af4d5211ae5f650f32))

# [9.0.0-beta.3](https://github.com/ForestAdmin/forest-express-mongoose/compare/v9.0.0-beta.2...v9.0.0-beta.3) (2022-10-31)


### Bug Fixes

* **chart:** improve security on chart and rename charts' properties ([#956](https://github.com/ForestAdmin/forest-express-mongoose/issues/956)) ([8b1891f](https://github.com/ForestAdmin/forest-express-mongoose/commit/8b1891f836b303a19fa9a61346e69dc0046dadb3))

# [9.0.0-beta.2](https://github.com/ForestAdmin/forest-express-mongoose/compare/v9.0.0-beta.1...v9.0.0-beta.2) (2022-10-28)


### Features

* **chart:** add support for objective chart ([#955](https://github.com/ForestAdmin/forest-express-mongoose/issues/955)) ([7b8a3aa](https://github.com/ForestAdmin/forest-express-mongoose/commit/7b8a3aa5efceced2b6b3c0296ed18d2d97ba30ac))

# [9.0.0-beta.1](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.7.9...v9.0.0-beta.1) (2022-10-28)


### Bug Fixes

* **security:** validate that smart action approvals are launched with the same parameters than the initial trigger ([#954](https://github.com/ForestAdmin/forest-express-mongoose/issues/954)) ([05be76d](https://github.com/ForestAdmin/forest-express-mongoose/commit/05be76da5092f4008fb1cc85c0a5b30adc7874c7))


### BREAKING CHANGES

* **security:** drop support of projects that are not using roles

Co-authored-by: Guillaume Gautreau <[email protected]>, Morgan Perre <[email protected]>

## [8.7.9](https://github.com/ForestAdmin/forest-express-mongoose/compare/v8.7.8...v8.7.9) (2022-10-25)


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "forest-express-mongoose",
"description": "Official Express/Mongoose Liana for Forest",
"version": "8.7.9",
"version": "9.0.0-beta.4",
"author": "Sandro Munda <[email protected]>",
"contributors": [
"Arnaud Besnier <[email protected]>",
Expand All @@ -27,7 +27,7 @@
"dependencies": {
"@babel/runtime": "7.15.4",
"bluebird": "2.9.25",
"forest-express": "9.5.6",
"forest-express": "10.0.0",
"http-errors": "1.7.2",
"lodash": "4.17.21",
"moment": "2.29.4",
Expand Down
5 changes: 3 additions & 2 deletions src/services/filters-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ function FiltersParser(model, timezone, options) {
const parseInteger = (value) => Number.parseInt(value, 10);
const parseDate = (value) => new Date(value);
const parseBoolean = (value) => {
if (value === 'true') { return true; }
if (value === 'false') { return false; }
if (['true', 'yes', '1'].includes(value)) { return true; }
if (['false', 'no', '0'].includes(value)) { return false; }

return typeof value === 'boolean' ? value : null;
};
const parseObjectId = (value) => {
Expand Down
45 changes: 17 additions & 28 deletions src/services/line-stat-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,84 +105,73 @@ class LineStatGetter {
const timezoneOffset = timezone * 60 * 60 * 1000;
const queryBuilder = new QueryBuilder(this._model, params, this._opts);

const populateGroupByField = this._getReference(params.group_by_field);
const groupByFieldName = populateGroupByField
? params.group_by_field.replace(':', '.') : params.group_by_field;

const jsonQuery = await queryBuilder.getQueryWithFiltersAndJoins(null);
if (populateGroupByField) {
queryBuilder.addJoinToQuery(populateGroupByField, jsonQuery);
}

const groupBy = {};
const sort = {};

if (groupByFieldName) {
groupBy._id = `$${groupByFieldName}`;
}

if (params.group_by_date_field) {
switch (params.time_range) {
if (params.groupByFieldName) {
switch (params.timeRange) {
case 'Day':
groupBy.year = {
$year: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
groupBy.month = {
$month: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
groupBy.day = {
$dayOfMonth: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
break;
case 'Week':
groupBy.week = {
$week: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
groupBy.year = {
$year: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
break;
case 'Year':
groupBy.year = {
$year: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
break;
default: // Month
groupBy.month = {
$month: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
groupBy.year = {
$year: [{
$subtract: [`$${params.group_by_date_field}`, timezoneOffset],
$subtract: [`$${params.groupByFieldName}`, timezoneOffset],
}],
};
}
sort[params.group_by_date_field] = 1;
sort[params.groupByFieldName] = 1;
}

let sum = 1;
if (params.aggregate_field) {
sum = `$${params.aggregate_field}`;
if (params.aggregateFieldName) {
sum = `$${params.aggregateFieldName}`;
}

if (params.group_by_date_field) {
if (params.groupByFieldName) {
jsonQuery.push({
$match: {
[params.group_by_date_field]: { $ne: null },
[params.groupByFieldName]: { $ne: null },
},
});
}
Expand All @@ -191,7 +180,7 @@ class LineStatGetter {
jsonQuery.push({
$group: {
_id: groupBy,
[params.group_by_date_field]: { $first: `$${params.group_by_date_field}` },
[params.groupByFieldName]: { $first: `$${params.groupByFieldName}` },
count: { $sum: sum },
},
});
Expand All @@ -204,7 +193,7 @@ class LineStatGetter {
.exec();

if (!records.length) { return { value: [] }; }
const momentRange = params.time_range.toLowerCase();
const momentRange = params.timeRange.toLowerCase();
const firstDate = LineStatGetter._setDate(records[0], momentRange);
const lastDate = LineStatGetter._setDate(records[records.length - 1], momentRange);

Expand Down
10 changes: 5 additions & 5 deletions src/services/pie-stat-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class PieStatGetter {

async perform() {
const params = await getScopedParams(this._params, this._model, this._user);
const field = _.find(this._schema.fields, { field: params.group_by_field });
const field = _.find(this._schema.fields, { field: params.groupByFieldName });
const queryBuilder = new QueryBuilder(this._model, params, this._opts);
const populateGroupByField = this._getReference(params.group_by_field);
const populateGroupByField = this._getReference(params.groupByFieldName);
const groupByFieldName = populateGroupByField
? params.group_by_field.replace(':', '.') : params.group_by_field;
? params.groupByFieldName.replace(':', '.') : params.groupByFieldName;

const jsonQuery = await queryBuilder.getQueryWithFiltersAndJoins(null);
if (populateGroupByField) {
Expand All @@ -36,8 +36,8 @@ class PieStatGetter {
const query = this._model.aggregate(jsonQuery);

let sum = 1;
if (params.aggregate_field) {
sum = `$${params.aggregate_field}`;
if (params.aggregateFieldName) {
sum = `$${params.aggregateFieldName}`;
}

const records = {
Expand Down
8 changes: 4 additions & 4 deletions src/services/value-stat-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ValueStatGetter {
const queryBuilder = new QueryBuilder(this._model, params, this._opts);

let sum = 1;
if (params.aggregate_field) {
sum = `$${params.aggregate_field}`;
if (params.aggregateFieldName) {
sum = `$${params.aggregateFieldName}`;
}

const jsonQuery = await queryBuilder.getQueryWithFiltersAndJoins(null);
Expand All @@ -25,10 +25,10 @@ class ValueStatGetter {
.exec();

if (!records || !records.length) {
return { value: 0 };
return { value: { countCurrent: 0 } };
}

return { value: records[0].total };
return { value: { countCurrent: records[0].total } };
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import utils from './schema';
*/
export default async function getScopedParams(params, model, user) {
const scopedFilters = await Interface.scopeManager.appendScopeForUser(
params.filters,
params.filters || (params.filter && JSON.stringify(params.filter)),
user,
utils.getModelName(model),
);
Expand Down
10 changes: 9 additions & 1 deletion test/tests/services/filters-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,20 @@ describe('service > filters-parser', () => {
});

it('should cast values to boolean', () => {
expect.assertions(5);
expect.assertions(9);

expect(defaultParser.getParserForType(Boolean)('true'))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)('false'))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)('yes'))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)('no'))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)('1'))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)('0'))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)(true))
.toBeBoolean();
expect(defaultParser.getParserForType(Boolean)(false))
Expand Down
38 changes: 8 additions & 30 deletions test/tests/services/line-stat-getter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import mongooseConnect from '../../utils/mongoose-connect';
const user = { renderingId: 1 };
const options = { Mongoose: mongoose, connections: { mongoose } };
const baseParams = {
aggregate: 'Sum',
aggregate_field: 'rating',
group_by_date_field: 'createdAt',
time_range: 'Month',
aggregator: 'Sum',
aggregateFieldName: 'rating',
groupByFieldName: 'createdAt',
timeRange: 'Month',
timezone: 'Europe/Paris',
};

Expand Down Expand Up @@ -82,7 +82,7 @@ describe('service > line-stat-getter', () => {
{ rating: 15, createdAt: new Date('2016-11-13') },
]);

const params = { ...baseParams, time_range: 'Day' };
const params = { ...baseParams, timeRange: 'Day' };
const getter = new LineStatGetter(ReviewModel, params, options, user);
expect(await getter.perform()).toStrictEqual({
value: [
Expand All @@ -103,7 +103,7 @@ describe('service > line-stat-getter', () => {
{ rating: 15, createdAt: new Date('2016-11-17') },
]);

const params = { ...baseParams, time_range: 'Week' };
const params = { ...baseParams, timeRange: 'Week' };
const getter = new LineStatGetter(ReviewModel, params, options, user);
expect(await getter.perform()).toStrictEqual({
value: [
Expand All @@ -122,7 +122,7 @@ describe('service > line-stat-getter', () => {
{ rating: 15, createdAt: new Date('2017-01-01') },
]);

const params = { ...baseParams, time_range: 'Month' };
const params = { ...baseParams, timeRange: 'Month' };
const getter = new LineStatGetter(ReviewModel, params, options, user);
expect(await getter.perform()).toStrictEqual({
value: [
Expand All @@ -142,7 +142,7 @@ describe('service > line-stat-getter', () => {
{ rating: 15, createdAt: new Date('2017-01-01') },
]);

const params = { ...baseParams, time_range: 'Year' };
const params = { ...baseParams, timeRange: 'Year' };
const getter = new LineStatGetter(ReviewModel, params, options, user);
expect(await getter.perform()).toStrictEqual({
value: [
Expand All @@ -152,26 +152,4 @@ describe('service > line-stat-getter', () => {
});
});
});

describe('with a group_by_field', () => {
it('should work grouping by color', async () => {
expect.assertions(1);

await loadFixture(ReviewModel, [
{ rating: 10, createdAt: new Date('2016-11-10'), color: 'green' },
{ rating: 10, createdAt: new Date('2016-11-14'), color: 'green' },
{ rating: 15, createdAt: new Date('2017-01-01'), color: 'red' },
]);

const params = { ...baseParams, group_by_field: 'color' };
const getter = new LineStatGetter(ReviewModel, params, options, user);
expect(await getter.perform()).toStrictEqual({
value: [
{ label: 'Nov 16', values: { value: 20 } },
{ label: 'Dec 16', values: { value: 0 } },
{ label: 'Jan 17', values: { value: 15 } },
],
});
});
});
});
10 changes: 5 additions & 5 deletions test/tests/services/pie-stat-getter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import mongooseConnect from '../../utils/mongoose-connect';
const user = { renderingId: 1 };
const options = { Mongoose: mongoose, connections: { mongoose } };
const baseParams = {
aggregate: 'Count',
group_by_field: 'rating',
aggregator: 'Count',
groupByFieldName: 'rating',
timezone: 'Europe/Paris',
};

Expand Down Expand Up @@ -88,7 +88,7 @@ describe('service > pie-stat-getter', () => {
{ rating: 66 },
]);

const params = { ...baseParams, aggregate_field: 'rating' };
const params = { ...baseParams, aggregateFieldName: 'rating' };
const getter = new PieStatGetter(ReviewModel, params, options, user);
expect(await getter.perform()).toStrictEqual({
value: [
Expand All @@ -108,8 +108,8 @@ describe('service > pie-stat-getter', () => {

const params = {
...baseParams,
group_by_field: 'createdAt',
aggregate_field: 'rating',
groupByFieldName: 'createdAt',
aggregateFieldName: 'rating',
};

const getter = new PieStatGetter(ReviewModel, params, options, user);
Expand Down
Loading

0 comments on commit c2a80d0

Please sign in to comment.