Skip to content

Commit

Permalink
- game-filter controller work
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamarcke committed Nov 6, 2024
1 parent 260114b commit dbd761f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion server_swagger.json

Large diffs are not rendered by default.

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;
}
16 changes: 8 additions & 8 deletions src/game/game-filter/game-filter.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Post,
Put,
Query,
UseGuards,
UseInterceptors,
Expand All @@ -22,6 +24,7 @@ import {
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")
Expand All @@ -45,18 +48,15 @@ export class GameFilterController {
@Session() session: SessionContainer,
@Param("gameId") gameId: number,
) {
return this.gameFilterService.registerExclusion(
session.getUserId(),
gameId,
);
return this.gameFilterService.register(session.getUserId(), gameId);
}

@Delete(":gameId")
@Put(":gameId/status")
@HttpCode(HttpStatus.NO_CONTENT)
async deleteExclusion(
@Session() session: SessionContainer,
async changeStatus(
@Param("gameId") gameId: number,
@Body() dto: ChangeExclusionStatusDto,
) {
return this.gameFilterService.deleteExclusion(gameId);
await this.gameFilterService.changeStatus(gameId, dto);
}
}
19 changes: 17 additions & 2 deletions src/game/game-filter/game-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GameRepositoryService } from "../game-repository/game-repository.servic
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 @@ -23,7 +24,7 @@ export class GameFilterService {
return this.gameExclusionRepository.findAndCount(options);
}

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

Expand All @@ -48,7 +49,21 @@ export class GameFilterService {
});
}

public async deleteExclusion(targetGameId: number) {
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);

Expand Down

0 comments on commit dbd761f

Please sign in to comment.