90 lines
1.9 KiB
TypeScript
90 lines
1.9 KiB
TypeScript
import {dbconn} from "../decorators/dbconn";
|
|
import {
|
|
getModelForClass,
|
|
index,
|
|
modelOptions, mongoose,
|
|
prop, Severity
|
|
} from "@typegoose/typegoose";
|
|
import {Base, TimeStamps} from "@typegoose/typegoose/lib/defaultClasses";
|
|
|
|
interface GameRecordClass extends TimeStamps {
|
|
}
|
|
|
|
@modelOptions({
|
|
options: {allowMixed: Severity.ALLOW}
|
|
})
|
|
class GamePlayer {
|
|
@prop()
|
|
public playerid: string;
|
|
@prop()
|
|
public accountid: string
|
|
@prop()
|
|
public index: number;
|
|
@prop()
|
|
public team: number;
|
|
@prop()
|
|
public heroid: number;
|
|
@prop()
|
|
public mvpscore: number;
|
|
@prop()
|
|
public cardgroup: string;
|
|
@prop({ type: () => [Number] })
|
|
public cards: [number];
|
|
@prop({type: mongoose.Schema.Types.Mixed})
|
|
public statdata: {};
|
|
@prop()
|
|
public score: number;
|
|
@prop()
|
|
public scoreChange: number;
|
|
}
|
|
/**
|
|
* 对战记录
|
|
*/
|
|
@dbconn()
|
|
@index({'players.accountid': 1}, {unique: false})
|
|
@modelOptions({
|
|
schemaOptions:
|
|
{collection: "game_record", timestamps: true},
|
|
options: {allowMixed: Severity.ALLOW}
|
|
})
|
|
class GameRecordClass extends Base<string>{
|
|
@prop()
|
|
public roomid: string;
|
|
@prop()
|
|
public round: number;
|
|
@prop()
|
|
public winner: number;
|
|
@prop()
|
|
public mvp: string;
|
|
/**
|
|
* 赛季
|
|
* @type {number} 0: 匹配, 1: 对应赛季
|
|
*/
|
|
@prop()
|
|
public season: number;
|
|
|
|
@prop()
|
|
public matchid: string;
|
|
|
|
|
|
@prop({_id: false, type: () => [GamePlayer]})
|
|
public players: GamePlayer[];
|
|
|
|
public toJson() {
|
|
return {
|
|
roomid: this.roomid,
|
|
round: this.round,
|
|
winner: this.winner,
|
|
season: this.season,
|
|
match: this.matchid,
|
|
players: '',
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
export const GameRecord = getModelForClass(GameRecordClass,
|
|
// @ts-ignore
|
|
{existingConnection: GameRecordClass['db']})
|