优化游戏帐号的创建和更新
This commit is contained in:
parent
f1b199b16c
commit
641be4f782
@ -23,17 +23,16 @@ class GameUserController extends BaseController {
|
||||
if (!accountId) {
|
||||
throw new ZError(11, 'accountId needed')
|
||||
}
|
||||
let user = (await GameUser.findOrCreate({ accountId })).doc
|
||||
user.updateFromReq(req.params)
|
||||
let sid = req.params.shop
|
||||
if (sid) {
|
||||
const shop = await Shop.fetchByID(sid)
|
||||
if (shop) {
|
||||
user.shop = shop.id
|
||||
user.shops.pushOnce(shop.id)
|
||||
}
|
||||
req.params.shop = shop.id
|
||||
}
|
||||
let user = await GameUser.findOneAndUpdate({ accountId }, req.params, { upsert: true, new: true })
|
||||
if (sid) {
|
||||
user.shops.pushOnce(req.params.shop)
|
||||
await user.save()
|
||||
}
|
||||
await user.save()
|
||||
const token = await res.jwtSign({ id: user.id, accountId })
|
||||
return { token }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user