rename findOneWithUsersCount

Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
Pierre Noël 2020-06-01 09:56:53 +02:00 committed by Alexandre Bodin
parent 77eec454ff
commit 9cfc34e19f
3 changed files with 5 additions and 5 deletions

View File

@ -5,7 +5,7 @@ const { validateRoleUpdateInput } = require('../validation/role');
module.exports = { module.exports = {
async findOne(ctx) { async findOne(ctx) {
const { id } = ctx.params; const { id } = ctx.params;
const role = await strapi.admin.services.role.findOneWithUsersCounts({ id }); const role = await strapi.admin.services.role.findOneWithUsersCount({ id });
if (!role) { if (!role) {
return ctx.notFound('role.notFound'); return ctx.notFound('role.notFound');

View File

@ -54,7 +54,7 @@ describe('Role', () => {
query: () => ({ findOne: dbFindOne, count: dbCount }), query: () => ({ findOne: dbFindOne, count: dbCount }),
}; };
const foundRole = await roleService.findOneWithUsersCounts({ id: role.id }); const foundRole = await roleService.findOneWithUsersCount({ id: role.id });
expect(dbFindOne).toHaveBeenCalledWith({ id: role.id }, []); expect(dbFindOne).toHaveBeenCalledWith({ id: role.id }, []);
expect(dbCount).toHaveBeenCalledWith({ 'roles.id': role.id }); expect(dbCount).toHaveBeenCalledWith({ 'roles.id': role.id });

View File

@ -36,7 +36,7 @@ const findOne = (params = {}, populate = []) => {
* @param params query params to find the role * @param params query params to find the role
* @returns {Promise<role>} * @returns {Promise<role>}
*/ */
const findOneWithUsersCounts = async (params = {}, populate = []) => { const findOneWithUsersCount = async (params = {}, populate = []) => {
const role = await strapi.query('role', 'admin').findOne(params, populate); const role = await strapi.query('role', 'admin').findOne(params, populate);
if (role) { if (role) {
@ -130,7 +130,7 @@ const deleteByIds = async (ids = []) => {
/** Count the number of users for some roles /** Count the number of users for some roles
* @param rolesIds * @param rolesIds
* @returns {Promise<array>} * @returns {Promise<integer>}
*/ */
const getUsersCount = async roleId => { const getUsersCount = async roleId => {
return strapi.query('user', 'admin').count({ 'roles.id': roleId }); return strapi.query('user', 'admin').count({ 'roles.id': roleId });
@ -140,7 +140,7 @@ module.exports = {
sanitizeRole, sanitizeRole,
create, create,
findOne, findOne,
findOneWithUsersCounts, findOneWithUsersCount,
find, find,
findAllWithUsersCount, findAllWithUsersCount,
update, update,