text: const UserModel = require("./user.model");
  
  class User {
    constructor(body) {
      this.body = body;
    }
  
    async login() {
      try {
        const { id, password } = await UserModel.getUserInfo(this.body.id);
  
        if (id) {
          if (id === this.body.id && password === this.body.password) {
            return { success: true };
          } else {
            return { success: false, message: "failed to login, password miss." };
          }
        } else {
          return { success: false, message: "failed to login, id not existed." };
        }
      } catch (err) {
        return { success: false, message: err };
      }
    }
  
    async register() {
      try {
        const response = await UserModel.save(this.body);
        return response;
      } catch (err) {
        return { success: false, message: err };
      }
    }
  }
  
  module.exports = User;
  