Added count to api template

This commit is contained in:
Okaris 2018-05-29 15:48:07 +03:00
parent 11bab474ed
commit 89c97e6cae
3 changed files with 32 additions and 0 deletions

View File

@ -33,6 +33,13 @@ module.exports = scope => {
config: {
policies: []
}
}, {
method: 'GET',
path: '/' + scope.humanizeId + '/count',
handler: scope.globalID + '.count',
config: {
policies: []
}
}, {
method: 'POST',
path: '/' + scope.humanizeId,

View File

@ -32,6 +32,16 @@ module.exports = {
return strapi.services.<%= id %>.fetch(ctx.params);
},
/**
* Count <%= id %> records.
*
* @return {Number}
*/
count: async (ctx) => {
return strapi.services.<%= id %>.count(ctx.query);
},
/**
* Create a/an <%= id %> record.
*

View File

@ -53,6 +53,21 @@ module.exports = {
.populate(populate);
},
/**
* Promise to count <%= humanizeIdPluralized %>.
*
* @return {Promise}
*/
count: (params) => {
// Convert `params` object to filters compatible with Mongo.
const filters = strapi.utils.models.convertParams('<%= globalID.toLowerCase() %>', params);
return <%= globalID %>
.count()
.where(filters.where);
},
/**
* Promise to add a/an <%= id %>.
*