Skip to content

Instantly share code, notes, and snippets.

@victorsteven
Created April 20, 2019 18:36
Show Gist options
  • Select an option

  • Save victorsteven/825aa23f21757550acb402f5b0c904d8 to your computer and use it in GitHub Desktop.

Select an option

Save victorsteven/825aa23f21757550acb402f5b0c904d8 to your computer and use it in GitHub Desktop.
Utils.js file
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