Created
April 20, 2019 18:36
-
-
Save victorsteven/825aa23f21757550acb402f5b0c904d8 to your computer and use it in GitHub Desktop.
Utils.js file
This file contains hidden or 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
| export default class Util { | |
| constructor() { | |
| this.statusCode = null; | |
| this.type = null; | |
| this.data = null; | |
| this.message = null; | |
| } | |
| setSuccess(statusCode, message, data) { | |
| this.statusCode = statusCode; | |
| this.message = message; | |
| this.data = data; | |
| this.type = 'success'; | |
| } | |
| setError(statusCode, message) { | |
| this.statusCode = statusCode; | |
| this.message = message; | |
| this.type = 'error'; | |
| } | |
| send(res) { | |
| const result = { | |
| status: this.type, | |
| message: this.message, | |
| data: this.data, | |
| }; | |
| if (this.type === 'success') { | |
| return res.status(this.statusCode).json(result); | |
| } | |
| return res.status(this.statusCode).json({ | |
| status: this.type, | |
| message: this.message, | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment