-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(rejectRequest): user(manager) can reject a request
- Loading branch information
1 parent
aa9ebf7
commit 2bd32b3
Showing
10 changed files
with
201 additions
and
16 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
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,45 @@ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
/** | ||
* | ||
* | ||
* @export | ||
* @class ResponseHandler | ||
*/ | ||
export default class ResponseHandler { | ||
/** | ||
* | ||
* | ||
* @static | ||
* @param {*} res HTTP response object | ||
* @param {*} data An object or array to send as a response | ||
* @param {number} [status=200] HTTP response status code. Default is 200 | ||
* @memberof ResponseHandler | ||
* @returns {void} | ||
*/ | ||
static success(res, data, status = 200) { | ||
return res.status(status).json({ | ||
success: true, | ||
status, | ||
data | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* | ||
* @static | ||
* @param {*} res HTTP response object | ||
* @param {string} [message='Bad request'] An error message | ||
* @param {number} [status=400] HTTP response status code. Default is 400 | ||
* @memberof ResponseHandler | ||
* @returns {void} | ||
*/ | ||
static error(res, message = 'Bad request', status = 400) { | ||
return res.status(status).json({ | ||
success: false, | ||
status, | ||
error: message | ||
}); | ||
} | ||
} |
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,42 @@ | ||
import bcrypt from 'bcrypt'; | ||
|
||
/** | ||
* @class CryptData | ||
* @description class defining the methods used to crypt and decrypt | ||
* sensitive information | ||
*/ | ||
class CryptData { | ||
/** | ||
* @param {string} dataToEncrypt - string to encrypt | ||
* @return {string} - hashed string | ||
* @memberof CryptData | ||
*/ | ||
static async encryptData(dataToEncrypt) { | ||
const salt = 6; | ||
try { | ||
const hashedData = await bcrypt.hash(dataToEncrypt, salt); | ||
return hashedData; | ||
} catch (err) { | ||
return Error('An error occurred while hashing'); | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} dataToDecrypt - string to decrypt | ||
* @param {string} dataBaseHash - hash used to compare the string against | ||
* @return {boolean} - result of the comparison. If the passed in string | ||
* is the same as the hash used to compare, then a boolean 'true' is | ||
* returned else 'false' is returned. | ||
* @memberof CryptData | ||
*/ | ||
static async decryptData(dataToDecrypt, dataBaseHash) { | ||
try { | ||
const isPasswordCorrect = await bcrypt | ||
.compare(dataToDecrypt, dataBaseHash); | ||
return isPasswordCorrect; | ||
} catch (err) { | ||
return Error('An error occurred while comparing the data sent'); | ||
} | ||
} | ||
} | ||
export default CryptData; |