✨ feat(db): 给hero表增加只读节点
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, Ref, mongoose, DocumentType } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, Ref, mongoose, DocumentType, ReturnModelType } from '@typegoose/typegoose';
|
||||||
// import Equip, { } from './Equip';
|
// import Equip, { } from './Equip';
|
||||||
import { DEFAULT_HERO_LV } from '../consts';
|
import { DEFAULT_HERO_LV } from '../consts';
|
||||||
import Skin, { SkinUpdate } from './Skin';
|
import Skin, { SkinUpdate } from './Skin';
|
||||||
@@ -179,27 +179,27 @@ export default class Hero extends BaseModel {
|
|||||||
for (let { field, sortBy } of sort) {
|
for (let { field, sortBy } of sort) {
|
||||||
sortParam[field] = sortBy;
|
sortParam[field] = sortBy;
|
||||||
}
|
}
|
||||||
const heros: HeroType[] = await HeroModel.find({ roleId }).sort(sortParam).select(select).lean({ getters });
|
const heros: HeroType[] = await HeroROModel.find({ roleId }).sort(sortParam).select(select).lean({ getters });
|
||||||
return heros;
|
return heros;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findAndSortByCe(roleId: string) {
|
public static async findAndSortByCe(roleId: string) {
|
||||||
const heroes: HeroType[] = await HeroModel.find({ roleId }).sort({ ce: -1 }).lean();
|
const heroes: HeroType[] = await HeroROModel.find({ roleId }).sort({ ce: -1 }).lean();
|
||||||
return heroes
|
return heroes
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findBySeqIdRange(seqIds: Array<number>, roleId: string, lean = true) {
|
public static async findBySeqIdRange(seqIds: Array<number>, roleId: string, lean = true) {
|
||||||
const hero: HeroType[] = await HeroModel.find({ seqId: { $in: seqIds }, roleId }).lean(lean);
|
const hero: HeroType[] = await HeroROModel.find({ seqId: { $in: seqIds }, roleId }).lean(lean);
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findByHidRange(hids: Array<number>, roleId: string, select?: string, getters = false) {
|
public static async findByHidRange(hids: Array<number>, roleId: string, select?: string, getters = false) {
|
||||||
const hero: HeroType[] = await HeroModel.find({ hid: { $in: hids }, roleId }).select(select).lean({ getters });
|
const hero: HeroType[] = await HeroROModel.find({ hid: { $in: hids }, roleId }).select(select).lean({ getters });
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async checkEquipByQuality(roleId: string, quality: number) {
|
public static async checkEquipByQuality(roleId: string, quality: number) {
|
||||||
const result = await HeroModel.exists({ roleId, 'ePlace.quality': { $gte: quality } });
|
const result = await HeroROModel.exists({ roleId, 'ePlace.quality': { $gte: quality } });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,16 +213,16 @@ export default class Hero extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async findBySeqIdAndRole(seqId: number, roleId: string, lean = true) {
|
public static async findBySeqIdAndRole(seqId: number, roleId: string, lean = true) {
|
||||||
const hero: HeroType = await HeroModel.findOne({ seqId, roleId }).lean(lean);
|
const hero: HeroType = await HeroROModel.findOne({ seqId, roleId }).lean(lean);
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
public static async findByHidAndRole(hid: number, roleId: string, select?: string, getters = false) {
|
public static async findByHidAndRole(hid: number, roleId: string, select?: string, getters = false) {
|
||||||
const hero: HeroType = await HeroModel.findOne({ hid, roleId }).select(select).lean({ getters });
|
const hero: HeroType = await HeroROModel.findOne({ hid, roleId }).select(select).lean({ getters });
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findSubHero(roleId: string, subHid: number) {
|
public static async findSubHero(roleId: string, subHid: number) {
|
||||||
const hero: HeroType = await HeroModel.findOne({ roleId, subHid }).lean();
|
const hero: HeroType = await HeroROModel.findOne({ roleId, subHid }).lean();
|
||||||
return hero;
|
return hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ export default class Hero extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getTopHero(roleId: string, num: number, lean = true) {
|
public static async getTopHero(roleId: string, num: number, lean = true) {
|
||||||
const heroes: HeroType[] = await HeroModel.find({ roleId }).limit(num).sort({ ce: -1 }).lean(lean);
|
const heroes: HeroType[] = await HeroROModel.find({ roleId }).limit(num).sort({ ce: -1 }).lean(lean);
|
||||||
return heroes;
|
return heroes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,17 +313,17 @@ export default class Hero extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getAllRank(serverId: number, select?: string, limit = 200) {
|
public static async getAllRank(serverId: number, select?: string, limit = 200) {
|
||||||
let result: HeroType[] = await HeroModel.find({ serverId }, { _id: false }).select(select).limit(limit).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
|
let result: HeroType[] = await HeroROModel.find({ serverId }, { _id: false }).select(select).limit(limit).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getMyTopHero(roleId: string, select?: string) {
|
public static async getMyTopHero(roleId: string, select?: string) {
|
||||||
let result: HeroType = await HeroModel.findOne({ roleId }, { _id: false }).select(select).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
|
let result: HeroType = await HeroROModel.findOne({ roleId }, { _id: false }).select(select).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getRank(hid: number, serverId: number, select?: string, limit = 200) {
|
public static async getRank(hid: number, serverId: number, select?: string, limit = 200) {
|
||||||
let result: HeroType[] = await HeroModel.find({ serverId, hid }, { _id: false }).select(select).limit(limit).lean({ getters: true });
|
let result: HeroType[] = await HeroROModel.find({ serverId, hid }, { _id: false }).select(select).limit(limit).lean({ getters: true });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ export default class Hero extends BaseModel {
|
|||||||
sort[sortField] = -1;
|
sort[sortField] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const result: HeroType[] = await HeroModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
const result: HeroType[] = await HeroROModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -354,12 +354,19 @@ export default class Hero extends BaseModel {
|
|||||||
public static async countByCondition(form: SearchHeroParam = {}) {
|
public static async countByCondition(form: SearchHeroParam = {}) {
|
||||||
|
|
||||||
let searchObj = this.getSearchObj(form);
|
let searchObj = this.getSearchObj(form);
|
||||||
const result = await HeroModel.count(searchObj);
|
const result = await HeroROModel.count(searchObj);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HeroModel = getModelForClass(Hero);
|
export const HeroModel = getModelForClass(Hero);
|
||||||
|
|
||||||
|
export let HeroROModel: ReturnModelType<typeof Hero, {}>;
|
||||||
|
export function loadHeroROModel(connect: mongoose.Connection) {
|
||||||
|
HeroROModel = getModelForClass(Hero, {
|
||||||
|
existingConnection: connect
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export interface HeroType extends Pick<DocumentType<Hero>, keyof Hero> { };
|
export interface HeroType extends Pick<DocumentType<Hero>, keyof Hero> { };
|
||||||
export type HeroUpdate = Partial<HeroType>; // 将所有字段变成可选项
|
export type HeroUpdate = Partial<HeroType>; // 将所有字段变成可选项
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { loadChannelInfo } from "./ChannelInfo";
|
|||||||
import { loadPackageModel } from "./Package";
|
import { loadPackageModel } from "./Package";
|
||||||
import { loadUserLog } from "./UserLog";
|
import { loadUserLog } from "./UserLog";
|
||||||
import { loadRoleROModel } from "./Role";
|
import { loadRoleROModel } from "./Role";
|
||||||
|
import { loadHeroROModel } from "./Hero";
|
||||||
|
|
||||||
export function loadGmDb(connect: mongoose.Connection) {
|
export function loadGmDb(connect: mongoose.Connection) {
|
||||||
// console.log('************')
|
// console.log('************')
|
||||||
@@ -41,4 +42,5 @@ export function loadSubDb(connect: mongoose.Connection) {
|
|||||||
// dbro
|
// dbro
|
||||||
export function loadRODb(connect: mongoose.Connection) {
|
export function loadRODb(connect: mongoose.Connection) {
|
||||||
loadRoleROModel(connect);
|
loadRoleROModel(connect);
|
||||||
|
loadHeroROModel(connect);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user