Update path to contextBody attributes in schema.graphql.js@checkBadRequest()

Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
Convly 2020-03-27 12:19:44 +01:00
parent 4a8de29100
commit 2d8e55838e

View File

@ -6,10 +6,10 @@ const _ = require('lodash');
* @throws ApolloError if the body is a bad request * @throws ApolloError if the body is a bad request
*/ */
function checkBadRequest(contextBody) { function checkBadRequest(contextBody) {
if (_.get(contextBody, 'output.payload.statusCode', 200) !== 200) { if (_.get(contextBody, 'statusCode', 200) !== 200) {
const statusCode = _.get(contextBody, 'output.payload.statusCode', 400); const statusCode = _.get(contextBody, 'statusCode', 400);
const message = _.get(contextBody, 'output.payload.message', 'Bad Request'); const message = _.get(contextBody, 'message[0].messages[0].message', 'Bad Request');
throw new Error(message, statusCode, _.omit(contextBody, ['output'])); throw new Error(message, statusCode, contextBody);
} }
} }
@ -44,7 +44,7 @@ module.exports = {
jwt: String! jwt: String!
user: UsersPermissionsMe! user: UsersPermissionsMe!
} }
type ForgotPassword { type ForgotPassword {
ok: Boolean ok: Boolean
} }
@ -218,9 +218,9 @@ module.exports = {
checkBadRequest(output); checkBadRequest(output);
return { return {
ok: output.ok || output ok: output.ok || output,
}; };
} },
}, },
changePassword: { changePassword: {
description: 'Change your password based on a code', description: 'Change your password based on a code',
@ -235,9 +235,9 @@ module.exports = {
return { return {
user: output.user || output, user: output.user || output,
jwt: output.jwt jwt: output.jwt,
}; };
} },
}, },
emailConfirmation: { emailConfirmation: {
description: 'Confirm an email users email address', description: 'Confirm an email users email address',
@ -245,17 +245,20 @@ module.exports = {
resolver: async (obj, options, { context }) => { resolver: async (obj, options, { context }) => {
context.query = _.toPlainObject(options); context.query = _.toPlainObject(options);
await strapi.plugins['users-permissions'].controllers.auth.emailConfirmation(context, true); await strapi.plugins['users-permissions'].controllers.auth.emailConfirmation(
context,
true
);
let output = context.body.toJSON ? context.body.toJSON() : context.body; let output = context.body.toJSON ? context.body.toJSON() : context.body;
checkBadRequest(output); checkBadRequest(output);
return { return {
user: output.user || output, user: output.user || output,
jwt: output.jwt jwt: output.jwt,
}; };
} },
} },
}, },
}, },
}; };