添加获取玩家可用卡牌和英雄的接口
This commit is contained in:
parent
9e4719eadb
commit
e03e28e5e8
@ -6,7 +6,7 @@
|
|||||||
通用返回JSON结构, 接口Response的数据结构说明只包含data部分
|
通用返回JSON结构, 接口Response的数据结构说明只包含data部分
|
||||||
``` JSON
|
``` JSON
|
||||||
{
|
{
|
||||||
"errcode": 0, //0:成功 4: 帐号被封, 100: 所有未定义的错误
|
"errcode": 0, //0:成功 2: 缺少必要参数(accountid, sessionid) 4: 帐号被封, 5: 帐号未找到 100: 所有未定义的错误
|
||||||
"errmsg": "", //错误描述
|
"errmsg": "", //错误描述
|
||||||
"data": {}, // 数据
|
"data": {}, // 数据
|
||||||
}
|
}
|
||||||
@ -78,6 +78,9 @@
|
|||||||
```
|
```
|
||||||
|
|
||||||
### 3. 可用英雄列表
|
### 3. 可用英雄列表
|
||||||
|
|
||||||
|
> 这个接口用户信息中的英雄列表最大的不同, 这里返回所有可用英雄, 用户信息中只返回永久免费和玩家拥有的英雄
|
||||||
|
|
||||||
1. Method: POST
|
1. Method: POST
|
||||||
2. URI: /api/:accountid/heros
|
2. URI: /api/:accountid/heros
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import {role, router} from "../decorators/router";
|
|||||||
import {Account} from "../models/Account";
|
import {Account} from "../models/Account";
|
||||||
import {ZError} from "../common/ZError";
|
import {ZError} from "../common/ZError";
|
||||||
import {Hero} from "../models/subdoc/Hero";
|
import {Hero} from "../models/subdoc/Hero";
|
||||||
|
import {Card} from "../models/subdoc/Card";
|
||||||
|
|
||||||
export default class AccountController extends BaseController {
|
export default class AccountController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@ -27,7 +28,6 @@ export default class AccountController extends BaseController {
|
|||||||
free_expire: 0
|
free_expire: 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//TODO:: 添加限免英雄和免费英雄
|
|
||||||
result.heros = heros;
|
result.heros = heros;
|
||||||
// let hero = new Hero();
|
// let hero = new Hero();
|
||||||
// hero.free = true;
|
// hero.free = true;
|
||||||
@ -44,4 +44,42 @@ export default class AccountController extends BaseController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@router('post /api/:accountid/cards')
|
||||||
|
async cardlist(req: any) {
|
||||||
|
let account = req.user;
|
||||||
|
let result: Card[] = [];
|
||||||
|
for (let cardid of account.cards) {
|
||||||
|
let card = new Card();
|
||||||
|
card.cardid = cardid;
|
||||||
|
card.owned = true;
|
||||||
|
card.ban = false;
|
||||||
|
card.usetype = 0;
|
||||||
|
card.free = false;
|
||||||
|
result.push(card);
|
||||||
|
}
|
||||||
|
//TODO:: 添加限免英雄和免费英雄
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@router('post /api/:accountid/heros')
|
||||||
|
async herolist(req: any) {
|
||||||
|
let account = req.user;
|
||||||
|
let heros: any[] = [];
|
||||||
|
for(let [key, hero] of account.heros) {
|
||||||
|
heros.push({
|
||||||
|
heroid: hero.heroid,
|
||||||
|
owned: true,
|
||||||
|
usetype: 0,
|
||||||
|
level: hero.level,
|
||||||
|
exp: hero.exp,
|
||||||
|
free: hero.free,
|
||||||
|
free_expire: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//TODO:: 添加限免英雄和免费英雄
|
||||||
|
return heros;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
} from 'fastify';
|
} from 'fastify';
|
||||||
import fastifyPlugin from 'fastify-plugin';
|
import fastifyPlugin from 'fastify-plugin';
|
||||||
import {Account} from '../models/Account';
|
import {Account} from '../models/Account';
|
||||||
|
import {ZError} from "../common/ZError";
|
||||||
|
|
||||||
declare module 'fastify' {
|
declare module 'fastify' {
|
||||||
interface FastifyInstance {
|
interface FastifyInstance {
|
||||||
@ -34,18 +35,20 @@ const apiAuthPlugin: FastifyPluginAsync = async function(
|
|||||||
// return reply.send({code: 11, msg: 'need accountid and sessionid'});
|
// return reply.send({code: 11, msg: 'need accountid and sessionid'});
|
||||||
// }
|
// }
|
||||||
if (!accountid) {
|
if (!accountid) {
|
||||||
return reply.send({code: 11, msg: 'need accountid and sessionid'});
|
return reply.send({code: 2, msg: 'need accountid and sessionid'});
|
||||||
}
|
}
|
||||||
// const data = this.jwt.verify(request.token);
|
// const data = this.jwt.verify(request.token);
|
||||||
// if (!data || !data.id) {
|
// if (!data || !data.id) {
|
||||||
// return reply.send({code: 10, msg: 'need login'});
|
// return reply.send({code: 10, msg: 'need login'});
|
||||||
// }
|
// }
|
||||||
// let account = await Account.findById(data.id);
|
let account = await Account.findById(accountid);
|
||||||
// if (!account) {
|
if (!account) {
|
||||||
// return reply.send({code: 10, msg: 'need login'});
|
return reply.send({code: 5, msg: 'account not found'});
|
||||||
// }
|
}
|
||||||
// request.user = account;
|
if (account.locked) {
|
||||||
|
return reply.send({code: 4, msg: 'account locked'});
|
||||||
|
}
|
||||||
|
request.user = account;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return reply.send({code: 401, msg: 'need auth'})
|
return reply.send({code: 401, msg: 'need auth'})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user