-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend/shared): add action buttons to tasks bb-362 (#451)
* feat(backend/shared): add endpoint to update task bb-362 * feat(backend/shared): add prehandler to check access to task bb-362 * feat(backend/shared): add endpoint to get past users tasks bb-362 * fix(backend): update imports/export for api pre handler type bb-362
- Loading branch information
1 parent
54ba144
commit 15c3ef0
Showing
20 changed files
with
224 additions
and
4 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
27 changes: 27 additions & 0 deletions
27
apps/backend/src/modules/tasks/libs/hooks/check-access-to-task.hook.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,27 @@ | ||
import { ErrorMessage } from "~/libs/enums/enums.js"; | ||
import { type APIPreHandler } from "~/libs/modules/controller/controller.js"; | ||
import { HTTPCode } from "~/libs/modules/http/http.js"; | ||
import { type UserDto } from "~/modules/users/users.js"; | ||
|
||
import { type TaskService } from "../../task.service.js"; | ||
import { TaskError } from "../exceptions/exceptions.js"; | ||
import { type TaskUpdateParametersDto } from "../types/types.js"; | ||
|
||
const checkAccessToTask = | ||
(taskService: TaskService): APIPreHandler => | ||
async (request) => { | ||
const { params, user } = request; | ||
|
||
const taskId = (params as TaskUpdateParametersDto).id; | ||
|
||
const task = await taskService.find(taskId); | ||
|
||
if ((user as UserDto).id !== task?.userId) { | ||
throw new TaskError({ | ||
message: ErrorMessage.FORBIDDEN, | ||
status: HTTPCode.FORBIDDEN, | ||
}); | ||
} | ||
}; | ||
|
||
export { checkAccessToTask }; |
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 @@ | ||
export { checkAccessToTask } from "./check-access-to-task.hook.js"; |
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,2 +1,6 @@ | ||
export { type UsersTaskCreateRequestDto } from "./users-task-create-request-dto.type.js"; | ||
export { type TaskDto } from "shared"; | ||
export { | ||
type TaskDto, | ||
type TaskUpdateParametersDto, | ||
type TaskUpdateRequestDto, | ||
} from "shared"; |
1 change: 1 addition & 0 deletions
1
apps/backend/src/modules/tasks/libs/validation-schemas/validation-schemas.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 @@ | ||
export { taskUpdateValidationSchema } from "shared"; |
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
2 changes: 1 addition & 1 deletion
2
apps/backend/src/modules/users/libs/hooks/check-access-to-user-data.hook.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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { TaskStatus } from "./task-status.enum.js"; | ||
export { TaskValidationMessage } from "./task-validation-message.enum.js"; | ||
export { TasksApiPath } from "./tasks-api-path.enum.js"; |
7 changes: 7 additions & 0 deletions
7
packages/shared/src/modules/tasks/libs/enums/task-validation-message.enum.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,7 @@ | ||
const TaskValidationMessage = { | ||
INVALID_TYPE: | ||
"Status must be one of the following: Completed, Current, or Skipped", | ||
REQUIRED: "Status field is required", | ||
} as const; | ||
|
||
export { TaskValidationMessage }; |
2 changes: 2 additions & 0 deletions
2
packages/shared/src/modules/tasks/libs/enums/tasks-api-path.enum.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const TasksApiPath = { | ||
$ID: "/:id", | ||
CURRENT: "/current", | ||
PAST: "/past", | ||
} as const; | ||
|
||
export { TasksApiPath }; |
5 changes: 5 additions & 0 deletions
5
packages/shared/src/modules/tasks/libs/types/task-update-parameters-dto.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,5 @@ | ||
type TaskUpdateParametersDto = { | ||
id: number; | ||
}; | ||
|
||
export { type TaskUpdateParametersDto }; |
8 changes: 8 additions & 0 deletions
8
packages/shared/src/modules/tasks/libs/types/task-update-request-dto.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,8 @@ | ||
import { type ValueOf } from "../../../../libs/types/types.js"; | ||
import { type TaskStatus } from "../enums/enums.js"; | ||
|
||
type TaskUpdateRequestDto = { | ||
status: ValueOf<typeof TaskStatus>; | ||
}; | ||
|
||
export { type TaskUpdateRequestDto }; |
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 +1,3 @@ | ||
export { type TaskDto } from "./task-dto.type.js"; | ||
export { type TaskUpdateParametersDto } from "./task-update-parameters-dto.type.js"; | ||
export { type TaskUpdateRequestDto } from "./task-update-request-dto.type.js"; |
27 changes: 27 additions & 0 deletions
27
packages/shared/src/modules/tasks/libs/validation-schemas/task-update.validation-schema.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,27 @@ | ||
import { z } from "zod"; | ||
|
||
import { TaskStatus, TaskValidationMessage } from "../enums/enums.js"; | ||
|
||
type TaskUpdateRequestValidationDto = { | ||
status: z.ZodEnum< | ||
[ | ||
typeof TaskStatus.COMPLETED, | ||
typeof TaskStatus.CURRENT, | ||
typeof TaskStatus.SKIPPED, | ||
] | ||
>; | ||
}; | ||
|
||
const taskUpdate = z | ||
.object<TaskUpdateRequestValidationDto>({ | ||
status: z.enum( | ||
[TaskStatus.COMPLETED, TaskStatus.CURRENT, TaskStatus.SKIPPED], | ||
{ | ||
invalid_type_error: TaskValidationMessage.INVALID_TYPE, | ||
required_error: TaskValidationMessage.REQUIRED, | ||
}, | ||
), | ||
}) | ||
.required(); | ||
|
||
export { taskUpdate }; |
1 change: 1 addition & 0 deletions
1
packages/shared/src/modules/tasks/libs/validation-schemas/validation-schemas.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 @@ | ||
export { taskUpdate } from "./task-update.validation-schema.js"; |
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,2 +1,7 @@ | ||
export { TasksApiPath, TaskStatus } from "./libs/enums/enums.js"; | ||
export { type TaskDto } from "./libs/types/types.js"; | ||
export { | ||
type TaskDto, | ||
type TaskUpdateParametersDto, | ||
type TaskUpdateRequestDto, | ||
} from "./libs/types/types.js"; | ||
export { taskUpdate as taskUpdateValidationSchema } from "./libs/validation-schemas/validation-schemas.js"; |