register.js 884 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
const { preRegister, postRegister } = require('../../lib/utils/register')

module.exports = async function (params = {}) {
  const schema = {
    unieid: 'username',
    nickname: {
      required: false,
      type: 'nickname'
    },
    gender: {
      required: false,
      type: 'number'
    },
    avatar: {
      required: false,
      type: 'string'
    }
  }

  this.middleware.validate(params, schema)

  const {
    unieid,
    avatar,
    gender,
    nickname
  } = params

  await preRegister.call(this, {
    user: {
      username: unieid
    }
  })

  const result = await postRegister.call(this, {
    user: {
      username: unieid,
      avatar,
      gender,
      nickname
    }
  })

  return {
    errCode: result.errCode,
    newToken: result.newToken,
    unieid,
    avatar,
    gender,
    nickname
  }
}