mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 06:35:47 +00:00
cleanup unnecessary code
This commit is contained in:
parent
3fb6b57808
commit
4d27d9de51
@ -1,23 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const pick = require('lodash/pick');
|
||||
|
||||
const { getService } = require('../utils');
|
||||
const { validateApiTokenCreationInput } = require('../validation/api-tokens');
|
||||
|
||||
module.exports = {
|
||||
async create(ctx) {
|
||||
const { body } = ctx.request;
|
||||
const { body: attributes } = ctx.request;
|
||||
const apiTokenService = getService('api-token');
|
||||
|
||||
try {
|
||||
await validateApiTokenCreationInput(body);
|
||||
await validateApiTokenCreationInput(attributes);
|
||||
} catch (err) {
|
||||
return ctx.badRequest('ValidationError', err);
|
||||
}
|
||||
|
||||
const attributes = pick(body, ['name', 'description', 'type']);
|
||||
|
||||
if (apiTokenService.exists({ name: attributes.name })) {
|
||||
return ctx.badRequest('Name already taken');
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ const apiTokenCreationSchema = yup
|
||||
})
|
||||
.noUnknown();
|
||||
|
||||
const validateApiTokenCreationInput = data => {
|
||||
const validateApiTokenCreationInput = async data => {
|
||||
return apiTokenCreationSchema
|
||||
.validate(data, { strict: true, abortEarly: false })
|
||||
.catch(handleReject);
|
||||
@ -27,8 +27,4 @@ const validateApiTokenCreationInput = data => {
|
||||
|
||||
module.exports = {
|
||||
validateApiTokenCreationInput,
|
||||
|
||||
schemas: {
|
||||
apiTokenCreationSchema,
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user