Skip to content

Commit

Permalink
ft(Manager Reject User's Request)
Browse files Browse the repository at this point in the history
  • Loading branch information
chiomadans1759 committed Aug 28, 2019
1 parent 53c3b2c commit cb31e75
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
41 changes: 41 additions & 0 deletions src/controllers/requests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import models from '../db/models';
import sender from '../services/email';

/**
* This class creates the user controller
*/
export default class UserController {
/**
* @param {object} req The user's signup details
* @param {object} res The user's details returned after signup
* @returns {object} A signed up user
*/
static async rejectRequest(req, res) {
try {
const user = await models.Request.update(
{
role: 'rejected'
},
{
where: {
id: req.params.id
}
}
);

// parameter(s) to be passed to the sendgrid email template
const payload = { user };
await sender.sendEmail(process.env.SENDER_EMAIL, user.email, 'signup_template', payload);
return res.status(201).json({
status: 'success',
data: {}
});
} catch (error) {
return res.status(500)
.json({
status: 'error',
error: 'Error accessing request route',
});
}
}
}
6 changes: 3 additions & 3 deletions src/services/email.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sgMail from '@sendgrid/mail';

// Setup this key on your .env usDrVXltTtqz6NnsAornNQ.WsLmjMfrwEin01Dj7aQ6xZ14eLqgC5o6lzS_Qw77yFw
// Setup this key on your .env
sgMail.setApiKey(process.env.SEND_GRID_API);

const templates = {
travel_request_notification: 'd-052f3ce066de4a92aa33d254d678e34d',
signup_template: 'd-9f73a2f3606c4dbcacb03cdb46df8948'
travel_request_notification: 'd-963a476c77a34f318895713712b4d6bb',
signup_template: 'd-1ae0bd2e62c742e9a78009512bd1b5b8'
};

/**
Expand Down

0 comments on commit cb31e75

Please sign in to comment.