增加上报和获取游戏记录的接口
This commit is contained in:
parent
b39bb08048
commit
f979259e49
26
src/controllers/RecordController.ts
Normal file
26
src/controllers/RecordController.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import {GameRecord} from "../models/GameRecord";
|
||||||
|
import BaseController from "../common/base.controller";
|
||||||
|
import {role, router} from "../decorators/router";
|
||||||
|
|
||||||
|
|
||||||
|
export default class RecordController extends BaseController {
|
||||||
|
@role('anon')
|
||||||
|
@router('post /api/:accountid/records')
|
||||||
|
async recordList(req: any) {
|
||||||
|
let {accountid} = req.params;
|
||||||
|
let records = await GameRecord.find({'players.accountid': accountid});
|
||||||
|
let results: any = [];
|
||||||
|
for (let record of records) {
|
||||||
|
results.push(record.toJSON());
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
@role('anon')
|
||||||
|
@router('post /api/record/save')
|
||||||
|
async upload(req: any) {
|
||||||
|
let record = new GameRecord(req.params);
|
||||||
|
await record.save();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
@ -7,26 +7,56 @@ import {
|
|||||||
} from "@typegoose/typegoose";
|
} from "@typegoose/typegoose";
|
||||||
import {Base, TimeStamps} from "@typegoose/typegoose/lib/defaultClasses";
|
import {Base, TimeStamps} from "@typegoose/typegoose/lib/defaultClasses";
|
||||||
|
|
||||||
interface GameRecordClass extends Base<string>, TimeStamps {
|
interface GameRecordClass extends TimeStamps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class GamePlayer {
|
||||||
|
@prop()
|
||||||
|
public playerid: string;
|
||||||
|
@prop()
|
||||||
|
public accountid: string
|
||||||
|
@prop()
|
||||||
|
public index: number;
|
||||||
|
@prop()
|
||||||
|
public team: number;
|
||||||
|
@prop()
|
||||||
|
public heroid: number;
|
||||||
|
@prop()
|
||||||
|
public cardgroup: string;
|
||||||
|
@prop()
|
||||||
|
public cards: [number];
|
||||||
|
@prop()
|
||||||
|
public statdata: {};
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 对战记录
|
* 对战记录
|
||||||
*/
|
*/
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@index({accountid: 1}, {unique: false})
|
@index({'players.accountid': 1}, {unique: false})
|
||||||
@modelOptions({
|
@modelOptions({
|
||||||
schemaOptions:
|
schemaOptions:
|
||||||
{collection: "game_record", timestamps: true}
|
{collection: "game_record", timestamps: true}
|
||||||
})
|
})
|
||||||
class GameRecordClass {
|
class GameRecordClass extends Base<string>{
|
||||||
@prop()
|
@prop()
|
||||||
public accountid: string;
|
public roomid: string;
|
||||||
|
@prop()
|
||||||
|
public round: number;
|
||||||
|
@prop()
|
||||||
|
public winner: number;
|
||||||
|
|
||||||
toJson() {
|
@prop({_id: false, type: () => [GamePlayer]})
|
||||||
|
public players: GamePlayer[];
|
||||||
|
|
||||||
|
public toJson() {
|
||||||
return {
|
return {
|
||||||
accountid: this.accountid,
|
roomid: this.roomid,
|
||||||
|
round: this.round,
|
||||||
|
winner: this.winner,
|
||||||
|
players: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user