-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(Module, Enrollment, Route): Mark module as completed route
- Loading branch information
1 parent
02e8ae0
commit 51a59d0
Showing
3 changed files
with
44 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { NotAllowedError } from '@/core/errors/errors/not-allowed-error' | ||
import { ResourceNotFoundError } from '@/core/errors/errors/resource-not-found-error' | ||
import { AllClassesInTheModuleMustBeMarkedAsCompleted } from '@/domain/course-management/application/use-cases/errors/all-classes-in-the-module-must-be-marked-as-completed' | ||
import { makeMarkModuleAsCompletedUseCase } from '@/infra/use-cases/factories/make-mark-module-as-completed-use-case' | ||
import { type FastifyReply, type FastifyRequest } from 'fastify' | ||
import { z } from 'zod' | ||
|
||
const markModuleAsCompletedParamsSchema = z.object({ | ||
enrollmentId: z.string().uuid(), | ||
moduleId: z.string().uuid() | ||
}) | ||
|
||
export async function markModuleAsCompletedController(request: FastifyRequest, reply: FastifyReply) { | ||
const { enrollmentId, moduleId } = markModuleAsCompletedParamsSchema.parse(request.params) | ||
const { sub: studentId } = request.user | ||
|
||
const markModuleAsCompletedUseCase = makeMarkModuleAsCompletedUseCase() | ||
|
||
const result = await markModuleAsCompletedUseCase.exec({ | ||
enrollmentId, | ||
moduleId, | ||
studentId | ||
}) | ||
|
||
if (result.isLeft()) { | ||
const error = result.value | ||
|
||
switch (error.constructor) { | ||
case ResourceNotFoundError: | ||
return await reply.status(404).send({ message: error.message }) | ||
case NotAllowedError: | ||
return await reply.status(401).send({ message: error.message }) | ||
case AllClassesInTheModuleMustBeMarkedAsCompleted: | ||
return await reply.status(403).send({ message: error.message }) | ||
default: | ||
return await reply.status(500).send({ message: error.message }) | ||
} | ||
} | ||
|
||
return await reply.status(201).send() | ||
} |
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