-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import clientPromise from "@/lib/mongoose"; | ||
import HeroTier from "@/lib/mongoose/schema/heroes-tier"; | ||
|
||
export async function getHeroTier({ select }: { select?: string }) { | ||
try { | ||
await clientPromise("game-core"); | ||
const heroesData = await HeroTier.find() | ||
.select(select || "") | ||
.lean(); | ||
|
||
return heroesData; | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error("Failed to fetch hero tiers"); | ||
} | ||
} | ||
|
||
export async function getHeroTierWithNames({ select }: { select?: string }) { | ||
try { | ||
await clientPromise("game-core"); | ||
|
||
const heroesData = await HeroTier.aggregate([ | ||
{ | ||
$lookup: { | ||
from: "Heroes", | ||
localField: "heroId", | ||
foreignField: "_id", | ||
as: "hero", | ||
}, | ||
}, | ||
{ | ||
$unwind: "$hero", | ||
}, | ||
{ | ||
$project: { | ||
_id: 0, | ||
tier: 1, | ||
name: "$hero.heroName", | ||
...(select ? { [select]: 1 } : {}), | ||
}, | ||
}, | ||
]); | ||
console.log(heroesData); | ||
return heroesData; | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error("Failed to fetch hero tiers with names"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import mongoose, { Schema, Types, Model } from "mongoose"; | ||
|
||
interface Stats { | ||
pickRate: number; | ||
banRate: number; | ||
winRate: number; | ||
} | ||
|
||
export interface HeroTierDocument { | ||
heroId: Types.ObjectId; | ||
name: string; | ||
combinedScore: number; | ||
currentMetaScore: number; | ||
currentMetaStats: Stats; | ||
tier: string; | ||
tournamentScore: number; | ||
tournamentStats: Stats; | ||
updatedAt: Date; | ||
} | ||
|
||
const StatsSchema: Schema<Stats> = new Schema( | ||
{ | ||
pickRate: { type: Number, required: true }, | ||
banRate: { type: Number, required: true }, | ||
winRate: { type: Number, required: true }, | ||
}, | ||
{ _id: false } | ||
); | ||
|
||
const HeroTierSchema: Schema = new Schema( | ||
{ | ||
heroId: { type: Types.ObjectId, required: true, ref: "Heroes" }, | ||
combinedScore: { type: Number, required: true }, | ||
currentMetaScore: { type: Number, required: true }, | ||
currentMetaStats: { type: StatsSchema, required: true }, | ||
tier: { type: String, required: true }, | ||
tournamentScore: { type: Number, required: true }, | ||
tournamentStats: { type: StatsSchema, required: true }, | ||
updatedAt: { type: Date, default: Date.now }, | ||
}, | ||
{ | ||
collection: "TierList", | ||
timestamps: true, | ||
} | ||
); | ||
|
||
const HeroTier: Model<HeroTierDocument> = | ||
mongoose.models.TierList || | ||
mongoose.model<HeroTierDocument>("TierList", HeroTierSchema); | ||
|
||
export default HeroTier; |
d57e097
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for mlbb-fyi ready!
✅ Preview
https://mlbb-naj2g7r8p-jinjays.vercel.app
Built with commit d57e097.
This pull request is being automatically deployed with vercel-action