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