mirror of
https://github.com/strapi/strapi.git
synced 2025-09-28 01:40:11 +00:00
Fix api token service, to use lodash fp insead of lodash
This commit is contained in:
parent
7d20788ff4
commit
08d0d484cb
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
const { stringEquals } = require('@strapi/utils/lib');
|
const { stringEquals } = require('@strapi/utils/lib');
|
||||||
const { ApplicationError } = require('@strapi/utils').errors;
|
const { ApplicationError } = require('@strapi/utils').errors;
|
||||||
const { trim } = require('lodash/fp');
|
const { trim, has } = require('lodash/fp');
|
||||||
const has = require('lodash/has');
|
|
||||||
const { getService } = require('../utils');
|
const { getService } = require('../utils');
|
||||||
const {
|
const {
|
||||||
validateApiTokenCreationInput,
|
validateApiTokenCreationInput,
|
||||||
@ -93,11 +92,11 @@ module.exports = {
|
|||||||
* - having a space at the end or start of the value.
|
* - having a space at the end or start of the value.
|
||||||
* - having only spaces as value;
|
* - having only spaces as value;
|
||||||
*/
|
*/
|
||||||
if (has(attributes, 'name')) {
|
if (has('name', attributes)) {
|
||||||
attributes.name = trim(body.name);
|
attributes.name = trim(body.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has(attributes, 'description') || attributes.description === null) {
|
if (has('description', attributes) || attributes.description === null) {
|
||||||
attributes.description = trim(body.description);
|
attributes.description = trim(body.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ module.exports = {
|
|||||||
return ctx.notFound('API Token not found');
|
return ctx.notFound('API Token not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has(attributes, 'name')) {
|
if (has('name', attributes)) {
|
||||||
const nameAlreadyTaken = await apiTokenService.getByName(attributes.name);
|
const nameAlreadyTaken = await apiTokenService.getByName(attributes.name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,6 +116,7 @@ module.exports = {
|
|||||||
* as a string. This way we avoid issues with integers in the db.
|
* as a string. This way we avoid issues with integers in the db.
|
||||||
*/
|
*/
|
||||||
if (!!nameAlreadyTaken && !stringEquals(nameAlreadyTaken.id, id)) {
|
if (!!nameAlreadyTaken && !stringEquals(nameAlreadyTaken.id, id)) {
|
||||||
|
console.log('here');
|
||||||
throw new ApplicationError('Name already taken');
|
throw new ApplicationError('Name already taken');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user