mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 06:35:47 +00:00
Added count to api template
This commit is contained in:
parent
11bab474ed
commit
89c97e6cae
@ -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,
|
||||
|
||||
@ -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.
|
||||
*
|
||||
|
||||
@ -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 %>.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user