const User = require('../models/index').user
const axios = require('axios')
const { isDev } = require('../util')

class UserService {
  async find (where) {
    let data = await User.findOne({ where })
    return data
  }

  async create (params) {
    let data = await User.create(params)
    return data
  }

  async update (values, where) {
    let data = await User.update(values, {
      where
    })
    return data
  }

  // 后台管理员校验
  checkRight (params) {
    let dev = isDev()
    let host = dev ? 'http://test.admin.duowan.com' : 'http://admin.duowan.com'
    params.nodeId = dev ? 7244 : 8092

    return axios.get(`${host}/open/checkRight2`, { params: params })
  }
}

module.exports = new UserService()
