From 2099384e46b7c5ea4bdc1c05aff93f6f8bbe0713 Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 13 Jan 2021 15:36:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8D=A1=E7=BB=84=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CardController.ts | 25 ++++++++++++++++++++++++- src/plugins/apiauth.ts | 4 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/controllers/CardController.ts b/src/controllers/CardController.ts index 1ebcd6f..7a513d7 100644 --- a/src/controllers/CardController.ts +++ b/src/controllers/CardController.ts @@ -1,10 +1,11 @@ import BaseController from "../common/base.controller"; -import {router} from "../decorators/router"; +import {role, router} from "../decorators/router"; import {CardGroup} from "../models/CardGroup"; import {ZError} from "../common/ZError"; import {Card} from "../models/subdoc/Card"; import {MoneyTypeConst} from "../constants/MoneyTypeConst"; import {BaseConst} from "../constants/BaseConst"; +import {User} from "../models/User"; export default class CardController extends BaseController { @router('post /api/:accountid/card_group/:heroid') @@ -23,6 +24,28 @@ export default class CardController extends BaseController { return result; } + @role('svr') + @router('get /api/:accountid/group_info/:heroid/:gid') + async cardGroupInfo(req: any) { + let {accountid, heroid, gid} = req.params; + let record; + if (gid) { + record = await CardGroup.findById(gid); + } + if (!record) { + if (!heroid || !accountid) { + throw new ZError(101, 'not enough params'); + } + heroid = parseInt(heroid); + record = await CardGroup.findOne({accountid, heroid, deleted: false, isdefault: true}); + } + if (!record) { + throw new ZError(103, 'no card group found'); + } + return record.toJson(); + } + + @router('post /api/:accountid/card_group/save/:gid') async saveCardGroup(req: any) { let {accountid, gid, heroid, selected, cards} = req.params; diff --git a/src/plugins/apiauth.ts b/src/plugins/apiauth.ts index 79fc9fc..6eac69f 100644 --- a/src/plugins/apiauth.ts +++ b/src/plugins/apiauth.ts @@ -28,6 +28,10 @@ const apiAuthPlugin: FastifyPluginAsync = async function( fastify.decorate("apiAuth", async function(request: FastifyRequest, reply: FastifyReply) { if (!request.roles || request.roles.indexOf('anon') == -1) { try { + if (request.roles.indexOf('svr') >= 0) { + // TODO: check svr + return; + } // @ts-ignore let { accountid, sessionid } = request.params; //TODO: 增加sessionid的校验