Skip to content

Commit

Permalink
fix(queue-config): cleanup queue config module (#2792)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Feb 7, 2024
1 parent f2f8585 commit bb86e7e
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/game-configs/services/game-configs.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tf2ClassName } from '@/shared/models/tf2-class-name';
import { Test, TestingModule } from '@nestjs/testing';
import { GameConfigsService } from './game-configs.service';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

describe('GameConfigsService', () => {
let service: GameConfigsService;
Expand Down
4 changes: 2 additions & 2 deletions src/game-configs/services/game-configs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { join } from 'path';
import { compile } from 'handlebars';
import { readFile } from 'fs/promises';
import { isEmpty } from 'lodash';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

@Injectable()
export class GameConfigsService implements OnModuleInit {
Expand Down
2 changes: 1 addition & 1 deletion src/games/services/games-configuration.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConfigurationService } from '@/configuration/services/configuration.service';
import { Test, TestingModule } from '@nestjs/testing';
import { GamesConfigurationService } from './games-configuration.service';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('@/configuration/services/configuration.service');

Expand Down
4 changes: 2 additions & 2 deletions src/games/services/games-configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { milliseconds } from 'date-fns';
import { z } from 'zod';
import { LogsTfUploadMethod } from '../types/logs-tf-upload-method';
import { VoiceServerType } from '../types/voice-server-type';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

@Injectable()
export class GamesConfigurationService implements OnModuleInit {
Expand Down
4 changes: 2 additions & 2 deletions src/players/controllers/players.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { LinkedProfileProviderName } from '../types/linked-profile-provider-name
import { Types } from 'mongoose';
import { ImportExportSkillService } from '../services/import-export-skill.service';
import { PlayerSkillRecordMalformedError } from '../errors/player-skill-record-malformed.error';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { PlayerId } from '../types/player-id';
import { CacheModule } from '@nestjs/cache-manager';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('../services/linked-profiles.service');
jest.mock('../services/import-export-skill.service');
Expand Down
2 changes: 1 addition & 1 deletion src/players/pipes/validate-skill.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { Tf2ClassName } from '@/shared/models/tf2-class-name';
import { BadRequestException } from '@nestjs/common';
import { ValidateSkillPipe } from './validate-skill.pipe';
Expand Down
4 changes: 2 additions & 2 deletions src/players/pipes/validate-skill.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';
import { Tf2ClassName } from '@/shared/models/tf2-class-name';
import {
BadRequestException,
Expand Down
2 changes: 1 addition & 1 deletion src/players/services/import-export-skill.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { PlayerSkillRecordMalformedError } from '../errors/player-skill-record-malformed.error';
import { FuturePlayerSkillService } from './future-player-skill.service';
import { ImportExportSkillService } from './import-export-skill.service';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('./future-player-skill.service');

Expand Down
4 changes: 2 additions & 2 deletions src/players/services/import-export-skill.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { Inject, Injectable } from '@nestjs/common';
import { PlayerSkillRecordMalformedError } from '../errors/player-skill-record-malformed.error';
import { FuturePlayerSkillService } from './future-player-skill.service';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

@Injectable()
export class ImportExportSkillService {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discord/services/queue-prompts.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { QueueService } from '@/queue/services/queue.service';
import { Tf2ClassName } from '@/shared/models/tf2-class-name';
import { Cache } from 'cache-manager';
import { DISCORD_CLIENT } from '../discord-client.token';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('@/configuration/services/configuration.service');
jest.mock('@/players/services/players.service');
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/discord/services/queue-prompts.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Environment } from '@/environment/environment';
import { Events } from '@/events/events';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { catchError, concatMap, debounceTime, from, map, of } from 'rxjs';
import { queuePreview } from '../notifications';
Expand All @@ -21,7 +21,7 @@ import { Cron, CronExpression } from '@nestjs/schedule';
import { QueueService } from '@/queue/services/queue.service';
import { QueueSlot } from '@/queue/queue-slot';
import { DISCORD_CLIENT } from '../discord-client.token';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

const queuePromptMessageIdCacheKey = (guildId: string) =>
`queue-prompt-message-id/${guildId}`;
Expand Down
2 changes: 1 addition & 1 deletion src/profile/services/profile.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Types } from 'mongoose';
import { Subject } from 'rxjs';
import { RestrictionReason } from '../interfaces/restriction';
import { ProfileService } from './profile.service';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('@/players/services/online-players.service');
jest.mock('@/players/services/linked-profiles.service');
Expand Down
4 changes: 2 additions & 2 deletions src/profile/services/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Player } from '@/players/models/player';
import { LinkedProfilesService } from '@/players/services/linked-profiles.service';
import { OnlinePlayersService } from '@/players/services/online-players.service';
import { PlayerBansService } from '@/players/services/player-bans.service';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { MapVoteService } from '@/queue/services/map-vote.service';
import { WebsocketEvent } from '@/websocket-event';
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
Expand All @@ -14,7 +14,7 @@ import { ProfileDto } from '../dto/profile.dto';
import { Restriction, RestrictionReason } from '../interfaces/restriction';
import { serialize } from '@/shared/serialize';
import { isUndefined } from 'lodash';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

const playersEqual = (a: Player, b: Player) => {
return a.name === b.name;
Expand Down
7 changes: 0 additions & 7 deletions src/queue-config/interfaces/game-class.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/queue-config/interfaces/queue-config.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/queue-config/parse-queue-config.ts

This file was deleted.

10 changes: 7 additions & 3 deletions src/queue-config/queue-config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { Environment } from '@/environment/environment';
import { Module, Provider } from '@nestjs/common';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { parseQueueConfig } from './parse-queue-config';
import { QUEUE_CONFIG_JSON } from './queue-config-json.token';
import { QUEUE_CONFIG } from './queue-config.token';
import { QUEUE_CONFIG_JSON } from './tokens/queue-config-json.token';
import { QUEUE_CONFIG } from './tokens/queue-config.token';
import { QueueConfig } from './types/queue-config';
import { queueConfigSchema } from './schemas/queue-config.schema';

const parseQueueConfig = (json: string): QueueConfig =>
queueConfigSchema.parse(JSON.parse(json));

const queueConfigJsonProvider: Provider = {
provide: QUEUE_CONFIG_JSON,
Expand Down
48 changes: 0 additions & 48 deletions src/queue-config/queue-config.schema.json

This file was deleted.

13 changes: 13 additions & 0 deletions src/queue-config/schemas/queue-config.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Tf2ClassName } from '@/shared/models/tf2-class-name';
import { z } from 'zod';

export const queueConfigSchema = z.object({
teamCount: z.literal(2),
classes: z.array(
z.object({
name: z.nativeEnum(Tf2ClassName),
count: z.number().gte(1),
canMakeFriendsWith: z.array(z.nativeEnum(Tf2ClassName)).optional(),
}),
),
});
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/queue-config/types/queue-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { z } from 'zod';
import { queueConfigSchema } from '../schemas/queue-config.schema';

export type QueueConfig = z.infer<typeof queueConfigSchema>;
2 changes: 1 addition & 1 deletion src/queue/controllers/queue-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Serializable } from '@/shared/serializable';
import { QueueDto } from '../dto/queue.dto';
import { MapVoteResult } from '../map-vote-result';
import { QueueConfig } from '../../queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { QueueSlot } from '../queue-slot';
import { QueueState } from '../queue-state';
import { Friendship } from '../services/friends.service';
Expand Down
2 changes: 1 addition & 1 deletion src/queue/controllers/queue.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MapPoolEntry } from '../models/map-pool-entry';
import { Player } from '@/players/models/player';
import { Types } from 'mongoose';
import { PlayerId } from '@/players/types/player-id';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('../services/queue.service');
jest.mock('../services/map-vote.service');
Expand Down
4 changes: 2 additions & 2 deletions src/queue/controllers/queue.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { QueueWrapper } from './queue-wrapper';
import { MapPoolEntryDto } from '../dto/map-pool-item.dto';
import { User } from '@/auth/decorators/user.decorator';
import { Player } from '@/players/models/player';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { MongoDbErrorFilter } from '@/shared/filters/mongo-db-error.filter';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

@Controller('queue')
export class QueueController {
Expand Down
2 changes: 1 addition & 1 deletion src/queue/services/queue.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { QueueSlot } from '../queue-slot';
import { ConfigurationService } from '@/configuration/services/configuration.service';
import { PlayerBanId } from '@/players/types/player-ban-id';
import { PlayerId } from '@/players/types/player-id';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

jest.mock('@/configuration/services/configuration.service', () => ({
ConfigurationService: jest.fn().mockImplementation(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/queue/services/queue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { PlayerNotInTheQueueError } from '../errors/player-not-in-the-queue.erro
import { WrongQueueStateError } from '../errors/wrong-queue-state.error';
import { CannotJoinAtThisQueueStateError } from '../errors/cannot-join-at-this-queue-state.error';
import { Cache } from 'cache-manager';
import { QueueConfig } from '@/queue-config/interfaces/queue-config';
import { QueueConfig } from '@/queue-config/types/queue-config';
import { ConfigurationService } from '@/configuration/services/configuration.service';
import { PlayerId } from '@/players/types/player-id';
import { Tf2ClassName } from '@/shared/models/tf2-class-name';
import { Types } from 'mongoose';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { QUEUE_CONFIG } from '@/queue-config/queue-config.token';
import { QUEUE_CONFIG } from '@/queue-config/tokens/queue-config.token';

interface Queue {
slots: {
Expand Down

0 comments on commit bb86e7e

Please sign in to comment.