From 32665e4abb97827105475024b6b07581895710bd Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 13 May 2021 15:52:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=BA=97=E9=93=BA=E7=9A=84=E5=BA=A7?= =?UTF-8?q?=E6=A0=87=E5=90=88=E5=B9=B6=E6=88=90=E4=B8=80=E4=B8=AA=E5=AD=97?= =?UTF-8?q?=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/game_user.controller.ts | 4 ++++ src/models/shop/Shop.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/api/controllers/game_user.controller.ts b/src/api/controllers/game_user.controller.ts index 975a714..dcca123 100644 --- a/src/api/controllers/game_user.controller.ts +++ b/src/api/controllers/game_user.controller.ts @@ -1,12 +1,16 @@ import BaseController from '../../common/base.controller' import { role, router } from '../../decorators/router' import { GameUser } from '../../models/GameUser' +import { ZError } from '../../common/ZError' class GameUserController extends BaseController { @role('anon') @router('post /weapp/login') async gameUserLogin(req, res) { const {accountId} = req.params + if (!accountId) { + throw new ZError(11, 'accountId needed') + } let user = (await GameUser.findOrCreate({accountId})).doc user.updateFromReq(req.params) await user.save() diff --git a/src/models/shop/Shop.ts b/src/models/shop/Shop.ts index bd2a4da..467c7d9 100644 --- a/src/models/shop/Shop.ts +++ b/src/models/shop/Shop.ts @@ -1,4 +1,9 @@ -import { getModelForClass, modelOptions, prop } from '@typegoose/typegoose' +import { + getModelForClass, + index, + modelOptions, + prop +} from '@typegoose/typegoose' import { dbconn } from '../../decorators/dbconn' import { noJson } from '../../decorators/nojson' import { BaseModule } from '../Base' @@ -12,6 +17,7 @@ class GameInfo { } @dbconn() +@index({ location: '2dsphere' }) @modelOptions({ schemaOptions: { collection: 'shop', timestamps: true } }) class ShopClass extends BaseModule { @prop({ required: true }) @@ -54,6 +60,9 @@ class ShopClass extends BaseModule { */ @prop() public lat: number + + @prop({ type: () => [Number] }) + public location: number[] /** * 是否删除 * @type {boolean}