.
This commit is contained in:
1 parent
30dfb7ce58
commit
5af2c80cd1
33 files changed
+3806
-1440
No files matched your search
@@ -10,6 +10,7 @@ import {
|
||||
MatchDocument,
|
||||
MatchStatus,
|
||||
PositionPreference,
|
||||
TierInfo,
|
||||
} from '../global/database/schema';
|
||||
|
||||
interface CreateMatchParams {
|
||||
@@ -51,7 +52,10 @@ export class MatchService {
|
||||
|
||||
public async list(query: ListMatchesQuery): Promise<MatchDocument[]> {
|
||||
const MatchModel = await this.connectionService.getModel('match');
|
||||
const filter: mongoose.FilterQuery<Match> = {
|
||||
const filter: {
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
status?: MatchStatus;
|
||||
} = {
|
||||
communityId: query.communityId,
|
||||
};
|
||||
if (query.status) filter.status = query.status;
|
||||
@@ -123,16 +127,34 @@ export class MatchService {
|
||||
}
|
||||
|
||||
const primaryRiot = user.riotAccounts.find((a) => a.isPrimary);
|
||||
const primaryTier = this.selectParticipantTier(primaryRiot?.tiers ?? []);
|
||||
match.participants.push({
|
||||
userId: user._id,
|
||||
puuid: primaryRiot?.puuid,
|
||||
gameName: primaryRiot?.gameName,
|
||||
tagLine: primaryRiot?.tagLine,
|
||||
profileIconId: primaryRiot?.profileIconId,
|
||||
tier: primaryTier,
|
||||
preferredPositions: params.preferredPositions,
|
||||
joinedAt: new Date(),
|
||||
});
|
||||
await match.save();
|
||||
return match;
|
||||
}
|
||||
|
||||
private selectParticipantTier(tiers: TierInfo[]): TierInfo | undefined {
|
||||
const tier =
|
||||
tiers.find((entry) => entry.queueType === 'RANKED_SOLO_5x5') ?? tiers[0];
|
||||
if (!tier) return undefined;
|
||||
|
||||
return {
|
||||
queueType: tier.queueType,
|
||||
tier: tier.tier,
|
||||
rank: tier.rank,
|
||||
leaguePoints: tier.leaguePoints,
|
||||
wins: tier.wins,
|
||||
losses: tier.losses,
|
||||
fetchedAt: tier.fetchedAt,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user