Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Add maxLimit as default limit for queries (#138)
Browse files Browse the repository at this point in the history
* add maxLimit as default limit for queries

* fix maxLimit config reference
  • Loading branch information
Henni authored May 1, 2017
1 parent ab08812 commit f6e4717
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
10 changes: 9 additions & 1 deletion api/dsap/artists.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var config = require('../../config.js.template');

module.exports = function(context) {
// Imports
var artists = context.models.artists;
Expand All @@ -18,13 +20,19 @@ module.exports = function(context) {
}
}

let limit = config.api.maxLimit;

if (options && options.limit && options.limit < limit) {
limit = options.limit;
}

return artists.findAndCountAll({
attributes: ['name', 'id', 'artist_type', 'dateOfBirth', 'placeOfBirth', 'dateOfDeath',
'placeOfDeath', 'nationality', 'tags', 'pseudonym', 'source_link', 'wiki_link', 'wiki_pageid'
],
where: whereClause,
order: [['id', 'DESC']],
limit: options && options.limit,
limit: limit,
offset: options && options.offset
}).then(results => {
return {
Expand Down
11 changes: 10 additions & 1 deletion api/dsap/instruments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

var config = require('../../config.js.template');

module.exports = function (context) {
// Imports
var instruments = context.models.instruments;
Expand All @@ -14,11 +17,17 @@ module.exports = function (context) {
}
}

let limit = config.api.maxLimit;

if (options && options.limit && options.limit < limit) {
limit = options.limit;
}

return instruments.findAndCountAll({
attributes: ['name', 'id'],
where: whereClause,
order: [['id', 'DESC']],
limit: options && options.limit,
limit: limit,
offset: options && options.offset
}).then(results => {
return {
Expand Down
11 changes: 10 additions & 1 deletion api/dsap/releases.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

var config = require('../../config.js.template');

module.exports = function (context) {
// Imports
var releases = context.models.releases;
Expand All @@ -14,11 +17,17 @@ module.exports = function (context) {
}
}

let limit = config.api.maxLimit;

if (options && options.limit && options.limit < limit) {
limit = options.limit;
}

return releases.findAndCountAll({
attributes: ['title', 'id', 'format', 'date', 'country', 'label'],
where: whereClause,
order: [['id', 'DESC']],
limit: options && options.limit,
limit: limit,
offset: options && options.offset
}).then(results => {
return {
Expand Down
11 changes: 10 additions & 1 deletion api/dsap/works.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

var config = require('../../config.js.template');

module.exports = function(context) {
var works = context.models.works;
return {
Expand All @@ -13,11 +16,17 @@ module.exports = function(context) {
}
}

let limit = config.api.maxLimit;

if (options && options.limit && options.limit < limit) {
limit = options.limit;
}

return works.findAndCountAll({
attributes: ['title', 'id', 'compositionyear'],
where: whereClause,
order: [['id', 'DESC']],
limit: options && options.limit,
limit: limit,
offset: options && options.offset
}).then(results => {
return {
Expand Down
3 changes: 2 additions & 1 deletion config.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
"collection": process.env.databasecollection || "postgres",
},
"api" : {
"apiKey": process.env.apikey || "not so secret"
"apiKey": process.env.apikey || "not so secret",
"maxLimit": process.env.maxlimit || 50,
},
"general": {
"logging": process.env.logging ? console.log : false
Expand Down

0 comments on commit f6e4717

Please sign in to comment.