Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix find one cant have multiple parameters when there is a primary key #5452

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 7 additions & 21 deletions packages/strapi-admin/controllers/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const PLUGIN_NAME_REGEX = /^[A-Za-z][A-Za-z0-9-_]+$/;
* Validates a plugin name format
*/
const isValidPluginName = plugin => {
return (
_.isString(plugin) && !_.isEmpty(plugin) && PLUGIN_NAME_REGEX.test(plugin)
);
return _.isString(plugin) && !_.isEmpty(plugin) && PLUGIN_NAME_REGEX.test(plugin);
};

/**
Expand Down Expand Up @@ -48,9 +46,7 @@ module.exports = {
const strapiVersion = _.get(strapi.config, 'info.strapi', null);
return ctx.send({ strapiVersion });
} catch (err) {
return ctx.badRequest(null, [
{ messages: [{ id: 'The version is not available' }] },
]);
return ctx.badRequest(null, [{ messages: [{ id: 'The version is not available' }] }]);
}
},

Expand All @@ -68,9 +64,7 @@ module.exports = {

return ctx.send({ layout });
} catch (err) {
return ctx.badRequest(null, [
{ messages: [{ id: 'An error occurred' }] },
]);
return ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
}
},

Expand Down Expand Up @@ -179,9 +173,7 @@ module.exports = {
);
}

const adminsWithSameEmail = await strapi
.query('administrator', 'admin')
.findOne({ email });
const adminsWithSameEmail = await strapi.query('administrator', 'admin').findOne({ email });

const adminsWithSameUsername = await strapi
.query('administrator', 'admin')
Expand Down Expand Up @@ -264,18 +256,14 @@ module.exports = {
})
);
}
const admin = await strapi
.query('administrator', 'admin')
.findOne(ctx.params);
const admin = await strapi.query('administrator', 'admin').findOne({ id });

// check the user exists
if (!admin) return ctx.notFound('Administrator not found');

// check there are not user with requested email
if (email !== admin.email) {
const adminsWithSameEmail = await strapi
.query('administrator', 'admin')
.findOne({ email });
const adminsWithSameEmail = await strapi.query('administrator', 'admin').findOne({ email });

if (adminsWithSameEmail && adminsWithSameEmail.id !== admin.id) {
return ctx.badRequest(
Expand Down Expand Up @@ -317,9 +305,7 @@ module.exports = {
user.password = await strapi.admin.services.auth.hashPassword(password);
}

const data = await strapi
.query('administrator', 'admin')
.update({ id }, user);
const data = await strapi.query('administrator', 'admin').update({ id }, user);

// Send 200 `ok`
ctx.send(data);
Expand Down