server_response.js 802 Bytes
/*
 * @Author: huyue 
 * @Date: 2021-09-06 15:04:10 
 * @Last Modified by: huyue
 * @Last Modified time: 2021-09-06 15:04:30
 */
const { SUCCESS, ERROR } = require("./server_response_code");

module.exports = class ServerResponse {
  constructor(status, msg, data) {
    this.status = status;
    this.msg = msg;
    this.data = data;
  }

  isSuccess() {
    return this.status === SUCCESS;
  }

  getStatus() {
    return this.status;
  }

  getData() {
    return this.data;
  }

  getMsg() {
    return this.msg;
  }

  static Success(data = null,respo = SUCCESS) {
    const { code,message } = respo
    return new ServerResponse(code,message, data);
  }

  static Error(respo = ERROR) {
    const { code=ERROR.code,message,data } = respo
    return new ServerResponse(code,message, data);
  }
};