-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(manager Can Reject User's Requests)
- Loading branch information
1 parent
bcc8dd5
commit 1cb85e8
Showing
27 changed files
with
404 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import models from '../db/models'; | ||
import sender from '../services/email.service'; | ||
|
||
const { Request, User } = models; | ||
/** | ||
* 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 request = await Request.update( | ||
{ | ||
status: 'declined' | ||
}, { returning: true, where: { id: req.params.id } } | ||
); | ||
const requestResult = request[1][0]; | ||
|
||
const user = await User.findOne({ where: { id: requestResult.user_id } }); | ||
const { first_name: firstName, email } = user; | ||
|
||
// parameter(s) to be passed to the sendgrid email template | ||
await sender.sendEmail(process.env.SENDER_EMAIL, email, 'request_rejected', { firstName, email }); | ||
return res.status(201).json({ | ||
status: 'success', | ||
data: requestResult | ||
}); | ||
} catch (error) { | ||
return res.status(500) | ||
.json({ | ||
status: 'error', | ||
error: 'Error accessing the request route', | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import models from '../db/models'; | ||
|
||
const { Request } = models; | ||
|
||
const requestChecks = { | ||
async validateRequests(req, res, next) { | ||
const request = await Request.count({ where: { id: req.params.id } }); | ||
if (request < 1) { | ||
return res.status(404).json({ | ||
status: 'error', | ||
error: 'This request does not exist' | ||
}); | ||
} | ||
return next(); | ||
} | ||
}; | ||
|
||
export default requestChecks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import express from 'express'; | ||
|
||
import authRouter from './auth.router'; | ||
import requestRouter from './requests.router'; | ||
|
||
|
||
const router = express.Router(); | ||
|
||
router.use('/auth', authRouter); | ||
router.use('/', requestRouter); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import express from 'express'; | ||
import auth from '../../middlewares/auth'; | ||
import RequestsController from '../../controllers/requests.controller'; | ||
import requestChecks from '../../middlewares/requests.middleware'; | ||
import validateRequests from '../../validation/request.validation'; | ||
|
||
const router = express.Router(); | ||
|
||
/* Requests Routes Here */ | ||
router.patch('/request/:id', | ||
auth.verifyUserToken, | ||
auth.verifyManager, | ||
validateRequests.validateRequestsID, | ||
requestChecks.validateRequests, | ||
RequestsController.rejectRequest); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.