Skip to content

Commit

Permalink
Merge pull request #552 from SprocketBot/staging
Browse files Browse the repository at this point in the history
Staging to Main
  • Loading branch information
gankoji authored Aug 28, 2024
2 parents 17097b6 + aa46c90 commit ef2ebcb
Show file tree
Hide file tree
Showing 18 changed files with 639 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"typescript.preferences.importModuleSpecifier": "relative"
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.tsdk": "node_modules/typescript/lib"
}
5 changes: 5 additions & 0 deletions core/src/elo/elo-connector/elo-connector.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum EloEndpoint {
AddPlayerBySalary = "AddPlayerBySalary",
SGChange = "SGChange",
EloChange = "EloChange",
CompactGraph = "CompactGraph",
}

export const EloSchemas = {
Expand Down Expand Up @@ -43,6 +44,10 @@ export const EloSchemas = {
input: Schemas.EloChange_Input,
output: Schemas.EloChange_Output,
},
[EloEndpoint.CompactGraph]: {
input: Schemas.CompactGraph_Input,
output: Schemas.CompactGraph_Output,
},
};

export type EloInput<T extends EloEndpoint> = z.infer<typeof EloSchemas[T]["input"]>;
Expand Down
4 changes: 4 additions & 0 deletions core/src/elo/elo-connector/schemas/CompactGraph.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {z} from "zod";

export const CompactGraph_Input = z.object({});
export const CompactGraph_Output = z.object({});
1 change: 1 addition & 0 deletions core/src/elo/elo-connector/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./CalculateEloForNcp.schema";
export * from "./CalculateSalaries.schema";
export * from "./ManualEloChange.schema";
export * from "./ManualRankout.schema";
export * from "./CompactGraph.schema";
6 changes: 6 additions & 0 deletions core/src/elo/elo.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export class EloConsumer {
await this.playerService.saveSalaries(salaryData);
}

async compactGraph(): Promise<void> {
this.logger.debug("Compacting the elo graph");

await this.eloConnectorService.createJobAndWait(EloEndpoint.CompactGraph, {});
}

async onApplicationBootstrap(): Promise<void> {
const repeatableJobs = await this.eloQueue.getRepeatableJobs();

Expand Down
7 changes: 7 additions & 0 deletions core/src/elo/elo.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ export class EloResolver {
await this.eloConsumer.runSalaries();
return true;
}

@Mutation(() => Boolean)
@UseGuards(GqlJwtGuard, MLEOrganizationTeamGuard(MLE_OrganizationTeam.MLEDB_ADMIN))
async compactGraph(): Promise<boolean> {
await this.eloConsumer.compactGraph();
return true;
}
}
23 changes: 21 additions & 2 deletions core/src/franchise/franchise/franchise.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {CoreEndpoint, CoreOutput} from "@sprocketbot/common";
import type {FindOneOptions} from "typeorm";
import {Repository} from "typeorm";

import type {FranchiseProfile} from "../../database";
import {FranchiseProfile} from "../../database";
import {Franchise} from "../../database";
import {MledbPlayerService} from "../../mledb";
import {MemberService} from "../../organization";
Expand All @@ -20,7 +20,8 @@ export class FranchiseService {
@Inject(forwardRef(() => MledbPlayerService))
private readonly mledbPlayerService: MledbPlayerService,
private readonly sprocketMemberService: MemberService,
private readonly sprocketPlayerService: PlayerService,
@InjectRepository(FranchiseProfile)
private readonly franchiseProfileRepository: Repository<FranchiseProfile>,
) {}

async getFranchiseProfile(franchiseId: number): Promise<FranchiseProfile> {
Expand All @@ -41,6 +42,24 @@ export class FranchiseService {
return this.franchiseRepository.findOneOrFail(query);
}

async getFranchiseByName(name: string): Promise<Franchise> {
const profile = await this.franchiseProfileRepository.findOneOrFail({
where: {
title: name,
},
relations: {
franchise: true,
}
});

// Have to go back to the DB to get the franchise object with its
// profile, rather than the profile with the franchise we had above
return this.getFranchise({
where: { id: profile.franchise.id },
relations: { profile: true }
});
}

async getPlayerFranchisesByMemberId(memberId: number): Promise<CoreOutput<CoreEndpoint.GetPlayerFranchises>> {
const member = await this.sprocketMemberService.getMemberById(memberId);
const {userId} = member;
Expand Down
36 changes: 33 additions & 3 deletions core/src/franchise/player/player.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import {Repository} from "typeorm";

import type {GameSkillGroup} from "../../database";
import {
Member, Player, UserAuthenticationAccount, UserAuthenticationAccountType,
Member, Player, User, UserAuthenticationAccount, UserAuthenticationAccountType,
} from "../../database";
import {
League, LeagueOrdinals, MLE_OrganizationTeam, MLE_Platform, ModePreference, Timezone,
} from "../../database/mledb";
import type {ManualEloChange, ManualSkillGroupChange} from "../../elo/elo-connector";
import {EloConnectorService, EloEndpoint} from "../../elo/elo-connector";
import {CreatePlayerTuple} from "../../franchise/player/player.types";
import {GqlJwtGuard} from "../../identity/auth/gql-auth-guard";
import {MLEOrganizationTeamGuard} from "../../mledb/mledb-player/mle-organization-team.guard";
import {OrganizationService} from "../../organization";
Expand Down Expand Up @@ -65,6 +66,9 @@ export class IntakePlayerAccount {

@Resolver(() => Player)
export class PlayerResolver {

private readonly logger = new Logger(PlayerResolver.name);

constructor(
private readonly popService: PopulateService,
private readonly playerService: PlayerService,
Expand All @@ -77,8 +81,6 @@ export class PlayerResolver {
@Inject(forwardRef(() => OrganizationService)) private readonly organizationService: OrganizationService,
) {}

private readonly logger = new Logger(PlayerResolver.name);

@ResolveField()
async skillGroup(@Root() player: Player): Promise<GameSkillGroup> {
return this.popService.populateOneOrFail(Player, player, "skillGroup");
Expand Down Expand Up @@ -348,4 +350,32 @@ export class PlayerResolver {

return imported;
}

@Mutation(() => Player)
@UseGuards(GqlJwtGuard, MLEOrganizationTeamGuard([MLE_OrganizationTeam.MLEDB_ADMIN, MLE_OrganizationTeam.LEAGUE_OPERATIONS]))
async updatePlayer(
@Args("mleid") mleid: number,
@Args("name") name: string,
@Args("skillGroup", {type: () => League}) league: League,
@Args("salary", {type: () => Float}) salary: number,
@Args("preferredPlatform") platform: string,
@Args("timezone", {type: () => Timezone}) timezone: Timezone,
@Args("preferredMode", {type: () => ModePreference}) mode: ModePreference,
@Args("accounts", {type: () => [IntakePlayerAccount]}) accounts: IntakePlayerAccount[],
): Promise<Player> {
const sg = await this.skillGroupService.getGameSkillGroup({where: {ordinal: LeagueOrdinals.indexOf(league) + 1} });
return this.playerService.updatePlayer(mleid, name, sg.id, salary, platform, accounts, timezone, mode);
}

@Mutation(() => [User])
@UseGuards(GqlJwtGuard, MLEOrganizationTeamGuard([MLE_OrganizationTeam.MLEDB_ADMIN, MLE_OrganizationTeam.LEAGUE_OPERATIONS]))
async intakeUser(
@Args("name", {type: () => String}) name: string,
@Args("discord_id", {type: () => String}) d_id: string,
@Args("playersToLink", {type: () => [CreatePlayerTuple]}) ptl: CreatePlayerTuple[],
@Args("platformAccounts", {type: () => [IntakePlayerAccount] }) platformAccounts: IntakePlayerAccount[] = [],
): Promise<User | string> {
return this.playerService.intakeUser(name, d_id, ptl, platformAccounts);
}

}
Loading

0 comments on commit ef2ebcb

Please sign in to comment.