Skip to content

Commit c9ca895

Browse files
authored
Add configuration for pagination and remove population for lastMeasurement (#774)
1 parent d0e04cd commit c9ca895

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/models/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ config.util.setModuleDefaults('openSenseMap-API-models', {
4444
amount: 1,
4545
unit: 'd',
4646
},
47+
pagination: {
48+
max_boxes: 3
49+
},
4750
image_folder: './userimages/',
4851
});
4952

packages/models/src/user/user.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { mongoose } = require('../db'),
1212
bcrypt = require('bcrypt'),
1313
crypto = require('crypto'),
1414
{ min_length: password_min_length, salt_factor: password_salt_factor } = require('config').get('openSenseMap-API-models.password'),
15+
{ max_boxes: pagination_max_boxes } = require('config').get('openSenseMap-API-models.pagination'),
1516
{ v4: uuidv4 } = require('uuid'),
1617
{ model: Box } = require('../box/box'),
1718
{ model: Claim } = require('../box/claim'),
@@ -551,8 +552,8 @@ userSchema.methods.updateUser = function updateUser ({ email, language, name, cu
551552

552553
userSchema.methods.getBoxes = function getBoxes (page) {
553554
return Box.find({ _id: { $in: this.boxes } })
554-
.limit(25)
555-
.skip(page * 25)
555+
.limit(pagination_max_boxes)
556+
.skip(page * pagination_max_boxes)
556557
.populate(Box.BOX_SUB_PROPS_FOR_POPULATION)
557558
.then(function (boxes) {
558559
return boxes.map(b => b.toJSON({ includeSecrets: true }));
@@ -566,7 +567,7 @@ userSchema.methods.getBox = function getBox (boxId) {
566567
user.checkBoxOwner(boxId);
567568

568569
return Box.findOne({ _id: boxId })
569-
.populate(Box.BOX_SUB_PROPS_FOR_POPULATION)
570+
// .populate(Box.BOX_SUB_PROPS_FOR_POPULATION)
570571
.then(function (box) {
571572
return box.toJSON({ includeSecrets: true });
572573
});

0 commit comments

Comments
 (0)