Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the mentee revoke mentee application API #161

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
npm-debug.log
dist
.git
*.md
.gitignore
.env
26 changes: 25 additions & 1 deletion src/controllers/mentee.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { Request, Response } from 'express'
import { type ApiResponse } from '../types'
import type Mentee from '../entities/mentee.entity'
import type Profile from '../entities/profile.entity'
import { getMentee, updateStatus } from '../services/admin/mentee.service'
import {
getMentee,
revoke,
updateStatus
} from '../services/admin/mentee.service'
import { MentorApplicationStatus, StatusUpdatedBy } from '../enums'
import { addMentee, getPublicMentee } from '../services/mentee.service'

Expand Down Expand Up @@ -65,6 +69,26 @@ export const updateMenteeStatus = async (
}
}

export const revokeApplication = async (
req: Request,
res: Response
): Promise<ApiResponse<Mentee>> => {
try {
const user = req.user as Profile

const { statusCode, message } = await revoke(user.uuid)
return res.status(statusCode).json({ message })
} catch (err) {
if (err instanceof Error) {
console.error('Error executing query', err)
return res
.status(500)
.json({ error: 'Internal server error', message: err.message })
}
throw err
}
}

export const getMenteeDetails = async (
req: Request,
res: Response
Expand Down
2 changes: 2 additions & 0 deletions src/routes/mentee/mentee.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getMenteeDetails,
getPublicMenteeDetails,
menteeApplicationHandler,
revokeApplication,
updateMenteeStatus
} from '../../controllers/mentee.controller'
import { requestBodyValidator } from '../../middlewares/requestValidator'
Expand All @@ -26,5 +27,6 @@ menteeRouter.put(
[requireAuth, requestBodyValidator(updateMenteeStatusSchema)],
updateMenteeStatus
)
menteeRouter.put('/revoke-application', requireAuth, revokeApplication)

export default menteeRouter
42 changes: 42 additions & 0 deletions src/services/admin/mentee.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,45 @@ export const getMentee = async (
throw new Error('Error getting mentees')
}
}

export const revoke = async (
userId: string
): Promise<{
statusCode: number
updatedMenteeApplication?: Mentee
message: string
}> => {
try {
const menteeRepository = dataSource.getRepository(Mentee)
const mentee = await menteeRepository.findOne({
where: {
profile: { uuid: userId },
state: MenteeApplicationStatus.PENDING
},
relations: ['profile', 'mentor']
})

if (!mentee) {
return {
statusCode: 404,
message: 'Mentee not found'
}
}

await menteeRepository.update(
{ uuid: mentee.uuid },
{
state: MenteeApplicationStatus.REVOKED,
status_updated_date: new Date()
}
)

return {
statusCode: 200,
message: 'Mentee application state successfully updated'
}
} catch (err) {
console.error('Error updating mentee status', err)
throw new Error('Error updating mentee status')
}
}
Loading