UNPKG

yekonga-server

Version:
64 lines (52 loc) 2.13 kB
const H = Yekonga.Helper; const resolvers = require('../graphql/auth/resolvers'); class ControllerAuthResolver { params; query; uuid; input; action; method; secondaryKey; constructor(req, res) { this.defaultMethods = ['login', 'otp', 'registration', 'resetPassword', 'changePassword', 'profile']; this.params = req.params; this.query = req.query; this.input = req.body; this.method = (req.method) ? req.method.toUpperCase() : 'GET'; if (this.params.method) { this.action = H.getVariable(this.params.method); } this.uuid = this.params.uuid; } async execute() { /** @type {any} */ var data = { error: "Empty" }; var parent = {}, params = { where: {} }, context = {}; if (this.uuid) { params.where[this.secondaryKey] = { equalTo: this.uuid } } try { if (this.action == 'login') { data = await resolvers.Mutation.login(parent, params, context); } else if (this.action == 'otp') { data = await resolvers.Mutation.otp(parent, params, context); } else if (this.action == 'registration') { data = await resolvers.Mutation.registration(parent, params, context); } else if (this.action == 'resetPassword') { data = await resolvers.Mutation.resetPassword(parent, params, context); } else if (this.action == 'changePassword') { data = await resolvers.Mutation.changePassword(parent, params, context); } else if (this.action == 'profile' && this.method == 'POST') { data = await resolvers.Mutation.profile(parent, params, context); } else if (this.action == 'profile' && this.method == 'GET') { data = await resolvers.Query.profile(parent, params, context); } } catch (error) { } return data; } } module.exports = ControllerAuthResolver;