Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/issue-153_token_revalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmabulage authored Sep 4, 2024
2 parents c68c7c3 + 9dfd64c commit d4e195d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
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')
}
}

0 comments on commit d4e195d

Please sign in to comment.