Skip to content

Commit

Permalink
Merge pull request #110 from game-node-app/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Lamarcke authored Nov 6, 2024
2 parents 6551455 + dbd761f commit f0f6bb3
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server_swagger.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/activities/activities-queue/activities-queue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ export class ActivitiesQueueService {
throw new Error("An activity must have an associated profile.");
} else if (
activity.sourceId == undefined ||
typeof activity.sourceId !== "string"
(typeof activity.sourceId !== "number" &&
typeof activity.sourceId !== "string")
) {
this.logger.error("Activity must have a valid sourceId.");
this.logger.error(
`Activity must have a valid sourceId. ${JSON.stringify(activity)}`,
);
throw new Error("Activity must have a valid sourceId.");
}
this.activitiesQueue
Expand Down
3 changes: 3 additions & 0 deletions src/game/game-filter/dto/change-exclusion-status.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class ChangeExclusionStatusDto {
isActive: boolean;
}
17 changes: 17 additions & 0 deletions src/game/game-filter/dto/find-all-excluded-games.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BaseFindDto } from "../../../utils/base-find.dto";
import { GameExclusion } from "../entity/game-exclusion.entity";
import { OmitType } from "@nestjs/swagger";
import {
PaginationInfo,
PaginationResponseDto,
} from "../../../utils/pagination/pagination-response.dto";

export class FindAllExcludedGamesRequestDto extends OmitType(
BaseFindDto<GameExclusion>,
["search"],
) {}

export class FindAllExcludedGamesResponseDto implements PaginationResponseDto {
data: GameExclusion[];
pagination: PaginationInfo;
}
62 changes: 62 additions & 0 deletions src/game/game-filter/game-filter.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Post,
Put,
Query,
UseGuards,
UseInterceptors,
} from "@nestjs/common";
import { ApiOkResponse, ApiTags } from "@nestjs/swagger";
import { GameFilterService } from "./game-filter.service";
import { Session } from "../../auth/session.decorator";
import { SessionContainer } from "supertokens-node/recipe/session";
import { AuthGuard } from "../../auth/auth.guard";
import { Roles } from "../../auth/roles.decorator";
import { EUserRoles } from "../../utils/constants";
import {
FindAllExcludedGamesRequestDto,
FindAllExcludedGamesResponseDto,
} from "./dto/find-all-excluded-games.dto";
import { PaginationInterceptor } from "../../interceptor/pagination.interceptor";
import { ChangeExclusionStatusDto } from "./dto/change-exclusion-status.dto";

@Controller("game/filter")
@ApiTags("game-filter")
@UseGuards(AuthGuard)
@Roles([EUserRoles.ADMIN, EUserRoles.MOD])
export class GameFilterController {
constructor(private readonly gameFilterService: GameFilterService) {}

@Get()
@UseInterceptors(PaginationInterceptor)
@ApiOkResponse({
type: FindAllExcludedGamesResponseDto,
})
async findAll(@Query() dto: FindAllExcludedGamesRequestDto) {
return this.gameFilterService.findAll(dto);
}

@Post(":gameId")
@HttpCode(HttpStatus.CREATED)
async registerExclusion(
@Session() session: SessionContainer,
@Param("gameId") gameId: number,
) {
return this.gameFilterService.register(session.getUserId(), gameId);
}

@Put(":gameId/status")
@HttpCode(HttpStatus.NO_CONTENT)
async changeStatus(
@Param("gameId") gameId: number,
@Body() dto: ChangeExclusionStatusDto,
) {
await this.gameFilterService.changeStatus(gameId, dto);
}
}
2 changes: 2 additions & 0 deletions src/game/game-filter/game-filter.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GameFilterService } from "./game-filter.service";
import { TypeOrmModule } from "@nestjs/typeorm";
import { GameExclusion } from "./entity/game-exclusion.entity";
import { GameRepositoryModule } from "../game-repository/game-repository.module";
import { GameFilterController } from './game-filter.controller';

/**
* The game filter module is responsible for issuing 'exclusions' for certain games.
Expand All @@ -15,5 +16,6 @@ import { GameRepositoryModule } from "../game-repository/game-repository.module"
imports: [TypeOrmModule.forFeature([GameExclusion]), GameRepositoryModule],
providers: [GameFilterService],
exports: [GameFilterService],
controllers: [GameFilterController],
})
export class GameFilterModule {}
36 changes: 35 additions & 1 deletion src/game/game-filter/game-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { InjectRepository } from "@nestjs/typeorm";
import { GameExclusion } from "./entity/game-exclusion.entity";
import { DataSource, In, Repository } from "typeorm";
import { GameRepositoryService } from "../game-repository/game-repository.service";
import { FindAllExcludedGamesRequestDto } from "./dto/find-all-excluded-games.dto";
import { buildBaseFindOptions } from "../../utils/buildBaseFindOptions";
import { TPaginationData } from "../../utils/pagination/pagination-response.dto";
import { ChangeExclusionStatusDto } from "./dto/change-exclusion-status.dto";

@Injectable()
export class GameFilterService {
Expand All @@ -13,7 +17,14 @@ export class GameFilterService {
private readonly dataSource: DataSource,
) {}

public async issueExclusion(issuerUserId: string, targetGameId: number) {
public async findAll(
dto: FindAllExcludedGamesRequestDto,
): Promise<TPaginationData<GameExclusion>> {
const options = buildBaseFindOptions(dto);
return this.gameExclusionRepository.findAndCount(options);
}

public async register(issuerUserId: string, targetGameId: number) {
// Errors out if game doesn't exist
await this.gameRepositoryService.findOneById(targetGameId);

Expand All @@ -38,6 +49,29 @@ export class GameFilterService {
});
}

public async changeStatus(
targetGameId: number,
dto: ChangeExclusionStatusDto,
) {
await this.gameRepositoryService.findOneById(targetGameId);
const exclusion = await this.gameExclusionRepository.findOneByOrFail({
targetGameId: targetGameId,
});

await this.gameExclusionRepository.update(exclusion.id, {
isActive: dto.isActive,
});
}

public async delete(targetGameId: number) {
// Errors out if game doesn't exist
await this.gameRepositoryService.findOneById(targetGameId);

await this.gameExclusionRepository.delete({
targetGameId: targetGameId,
});
}

public async isExcluded(targetGameId: number) {
return await this.gameExclusionRepository.exists({
where: {
Expand Down
2 changes: 1 addition & 1 deletion src/profile/profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { Roles } from "../auth/roles.decorator";
import { EUserRoles } from "../utils/constants";
import { FindAllProfileResponseItemDto } from "./dto/find-all-profile.dto";

// No POST /profile endpoint
@Controller("profile")
@ApiTags("profile")
@UseGuards(AuthGuard)
Expand Down Expand Up @@ -100,6 +99,7 @@ export class ProfileController {
}

@Get("all")
@Roles([EUserRoles.ADMIN, EUserRoles.MOD])
@ApiOkResponse({
type: FindAllProfileResponseItemDto,
status: "2XX",
Expand Down

0 comments on commit f0f6bb3

Please sign in to comment.