Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
where: {
email: { _eq: $email }
}
) {
id
}
}
`;
try {
var hasura_data = await graphql_client.request(query, {
email,
});
} catch (e) {
console.log(e);
return next(Boom.badImplementation('Unable to check for duplicates'));
}
if (hasura_data.users.length !== 0) {
return next(Boom.unauthorized('The email is already in use'));
}
// generate password_hash
try {
var password_hash = await bcrypt.hash(password, 10);
} catch(e) {
return next(Boom.badImplementation('Unable to generate password hash'));
}
// insert user
var query = `
mutation insert_user($user: users_insert_input!) {
public async index(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
// @ts-ignore
const data = await request.server.methods.v1.delegates.index(request);
return super.respondWithCache(data, h);
} catch (error) {
return Boom.badImplementation(error);
}
}
server.ext('onPreAuth', (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
const selfTest = this.selfTest
const config = this.config
if (selfTest.selfTestSuccess) {
return h.continue
}
if (!selfTest) {
log.error('self test stats missing from plugin context')
throw Boom.badImplementation('self test stats missing from plugin context')
}
if (request.headers['authorization']) {
const token = request.headers['authorization'].split(' ')[1]
if (token === config.bearerToken) {
log.debug('Route authenticated using bearer token')
return h.continue
}
}
const stats = selfTest.getTestStats()
return h.response({
message: stats.running ? 'Self Test Running' : 'Self Test Failed',
stats: stats
}, (err, wreckResponse, payload) => {
if (err) {
const error = Boom.badImplementation('Error calling duckling to parse text');
return callback(error, null);
}
//The value in the result is not formatted as JSON. This formats that value
payload = _.map(payload, (ducklingResult) => {
//ducklingResult.value = JSON.parse(ducklingResult.value);
return ducklingResult;
});
payload = DucklingOutputToIntervals(payload, timezone);
return callback(null, payload);
});
};
redis.hmset(`agent:${agentId}`, { status: Status.outOfDate }, (err) => {
if (err){
const error = Boom.badImplementation('An error occurred updating the agent status.');
return callback(error);
}
redis.hmset(`domain:${domainId}`, { status: Status.outOfDate }, (err) => {
if (err){
const error = Boom.badImplementation('An error occurred updating the domain status.');
return callback(error);
}
return callback(null, resultIntent);
});
});
});
request.seneca.act(msg, (err, resp) => {
if (err) return reply(Boom.badImplementation());
let isCDFAdmin = false;
let code = 200;
const roles = _.deepHas(user, 'user.roles')
? request.user.user.roles
: [];
if (_.includes(roles, 'cdf-admin')) {
isCDFAdmin = true;
}
if (!resp.userIsDojoAdmin && !isCDFAdmin) {
code = 401;
return reply({
ok: false,
why:
'You must be a dojo admin or ticketing admin to access this data',
}).code(code);
}
if (!id) {
return next(boom.badRequest('no local lead id provided'));
}
try {
const results = await getPINsRespondedToGroupSessions(id);
const PINs = results[0] && results[0].PIN;
return getTrainerBehavioral(PINs)
.then(result => {
const calculatedFormulae = trainerBehavioralFormulae(result);
res.json({ ...calculatedFormulae });
})
.catch(err => {
return next(boom.badImplementation('error in getting the data'));
});
} catch (error) {
return next(boom.badImplementation());
}
};
redis.zscore('agents', postFormat.agent, (err, id) => {
if (err){
const error = Boom.badImplementation('An error occurred checking if the agent exists.');
return callback(error);
}
if (id){
agentId = id;
return callback(null);
}
const error = Boom.badRequest(`The agent ${postFormat.agent} doesn't exist`);
return callback(error, null);
});
},
redis.zscore('agents', currentScenario.agent, (err, agentId) => {
if (err){
const error = Boom.badImplementation('An error occurred checking if the agent exists.');
return callback(error);
}
if (agentId){
return callback(null, agentId);
}
const error = Boom.badRequest(`The agent ${currentScenario.agent} doesn't exist`);
return callback(error, null);
});
},
server.methods.account.requestMigrateEmail(request, function(err, json) {
if ( err ) {
return reply(Boom.badImplementation(err));
}
reply({ status: 'migration email sent' });
});
}