Skip to content

Commit

Permalink
feat(apis): limit history size ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Apr 8, 2020
1 parent e036f67 commit 3a098e4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions modules/apis/repositories/apis.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Api = mongoose.model('Api');
* @desc Function to get all api in db
* @return {Array} All apis
*/
exports.list = () => Api.find().sort('-createdAt').exec();
exports.list = () => Api.find().select('-history').sort('-createdAt').exec();

/**
* @desc Function to create a api in db
Expand All @@ -25,15 +25,27 @@ exports.create = (api) => new Api(api).save();
*/
exports.get = (id) => {
if (!mongoose.Types.ObjectId.isValid(id)) return null;
return Api.findOne({ _id: id }).populate('history').exec();
return Api.findOne({ _id: id }).populate([{
path: 'history',
options: {
limit: 100,
sort: { createdAt: -1 },
},
}]).exec();
};

/**
* @desc Function to update a api in db
* @param {Object} api
* @return {Object} api
*/
exports.update = (api) => new Api(api).save().then((a) => a.populate('history').execPopulate());
exports.update = (api) => new Api(api).save().then((a) => a.populate([{
path: 'history',
options: {
limit: 100,
sort: { createdAt: -1 },
},
}]).execPopulate());

/**
* @desc Function to delete a api in db
Expand Down

0 comments on commit 3a098e4

Please sign in to comment.