const { LoginService } = require('../service/index')
const Response = require('../util/response')

class Controller {
  /**
     * 用户信息校验
     * @param {object} ctx http上下文
     * @return {boolean}
     */
  async authUser (ctx) {
    let { userId, token } = ctx.request.query

    console.log('userId, token', userId, token, ctx.request.query)

    if (
      !(userId && token) ||
      (await LoginService.authUser(userId, token)) == null
    ) {
      new Response(ctx, {
        msg: CODE_MSG_MAP['CODE_USER_LOGIN_FAIL'],
        code: CODE_USER_LOGIN_FAIL
      })
      return false
    }

    return true
  }
}

module.exports = Controller
