Skip to content

Commit b732c7c

Browse files
authored
Merge pull request #327 from mixmaxhq/jordi/COMM-78-remove-spread-operator
fix: remove uses of the spread operator
2 parents c410f05 + 7e8a8c9 commit b732c7c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/aggregate.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,23 @@ module.exports = async function aggregate(collection, params) {
4747
const $sort = generateSort(params);
4848
const $limit = params.limit + 1;
4949

50-
let addFields = [];
51-
let cleanUp = [];
50+
let aggregation;
5251
if (params.sortCaseInsensitive) {
53-
addFields = [{ $addFields: { __lc: { $toLower: '$' + params.paginatedField } } }];
54-
cleanUp = [{ $project: { __lc: 0 } }];
52+
aggregation = params.aggregation.concat([
53+
{ $addFields: { __lc: { $toLower: '$' + params.paginatedField } } },
54+
{ $match },
55+
{ $sort },
56+
{ $limit },
57+
{ $project: { __lc: 0 } },
58+
]);
59+
} else {
60+
aggregation = params.aggregation.concat([{ $match }, { $sort }, { $limit }]);
5561
}
56-
const aggregation = params.aggregation.concat([
57-
...addFields,
58-
{ $match },
59-
{ $sort },
60-
{ $limit },
61-
...cleanUp,
62-
]);
6362

6463
// Aggregation options:
6564
// https://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#aggregate
6665
// https://mongodb.github.io/node-mongodb-native/4.0/interfaces/aggregateoptions.html
67-
const options = { ...params.options };
66+
const options = Object.assign({}, params.options);
6867
/**
6968
* IMPORTANT
7069
*

src/find.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ module.exports = async function(collection, params) {
3939
let response;
4040
if (params.sortCaseInsensitive) {
4141
// For case-insensitive sorting, we need to work with an aggregation:
42-
response = aggregate(collection, {
43-
...params,
44-
aggregation: params.query ? [{ $match: params.query }] : [],
45-
});
42+
response = aggregate(
43+
collection,
44+
Object.assign({}, params, {
45+
aggregation: params.query ? [{ $match: params.query }] : [],
46+
})
47+
);
4648
} else {
4749
// Need to repeat `params.paginatedField` default value ('_id') since it's set in 'sanitizeParams()'
4850
params = _.defaults(await sanitizeParams(collection, params), { query: {} });

0 commit comments

Comments
 (0)