-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(game): cancel playing game with DELETE endpoint (#35)
- Loading branch information
1 parent
b4de0e0
commit 16eef75
Showing
15 changed files
with
4,380 additions
and
3,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum BAD_RESOURCE_MUTATION_REASONS { | ||
GAME_NOT_PLAYING = "game-not-playing", | ||
} | ||
|
||
export { BAD_RESOURCE_MUTATION_REASONS }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import { NotFoundException } from "@nestjs/common"; | ||
import { ResourceNotFoundError } from "../types/error.type"; | ||
import { BadRequestException, NotFoundException } from "@nestjs/common"; | ||
import { BAD_RESOURCE_MUTATION_REASONS } from "../enums/bad-resource-mutation-error.enum"; | ||
import { BadResourceMutationError } from "../types/bad-resource-mutation-error.type"; | ||
import { ResourceNotFoundError } from "../types/resource-not-found-error.type"; | ||
|
||
function getControllerRouteError(err: unknown): unknown { | ||
if (err instanceof ResourceNotFoundError) { | ||
return new NotFoundException(err.message); | ||
} else if (err instanceof BadResourceMutationError) { | ||
return new BadRequestException(err.message); | ||
} | ||
return err; | ||
} | ||
|
||
export { getControllerRouteError }; | ||
function getBadResourceMutationReasonMessage(reason: BAD_RESOURCE_MUTATION_REASONS): string { | ||
const reasonMessages: Record<BAD_RESOURCE_MUTATION_REASONS, string> = { [BAD_RESOURCE_MUTATION_REASONS.GAME_NOT_PLAYING]: `Game doesn't have status with value "playing"` }; | ||
return reasonMessages[reason]; | ||
} | ||
|
||
export { getControllerRouteError, getBadResourceMutationReasonMessage }; |
16 changes: 16 additions & 0 deletions
16
src/shared/error/types/bad-resource-mutation-error.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { upperFirst } from "lodash"; | ||
import type { API_RESOURCES } from "../../api/enums/api.enum"; | ||
import { getResourceSingularForm } from "../../api/helpers/api.helper"; | ||
import type { BAD_RESOURCE_MUTATION_REASONS } from "../enums/bad-resource-mutation-error.enum"; | ||
import { getBadResourceMutationReasonMessage } from "../helpers/error.helper"; | ||
|
||
class BadResourceMutationError extends Error { | ||
public constructor(resource: API_RESOURCES, id: string, reason: BAD_RESOURCE_MUTATION_REASONS) { | ||
const resourceSingularForm = getResourceSingularForm(resource); | ||
const reasonMessage = getBadResourceMutationReasonMessage(reason); | ||
const message = `Bad mutation for ${upperFirst(resourceSingularForm)} with id "${id}" : ${reasonMessage}`; | ||
super(message); | ||
} | ||
} | ||
|
||
export { BadResourceMutationError }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.