diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f38bb58 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +npm-debug.log +dist +.git +*.md +.gitignore +.env diff --git a/src/controllers/mentee.controller.ts b/src/controllers/mentee.controller.ts index fdb1af4..45b9faa 100644 --- a/src/controllers/mentee.controller.ts +++ b/src/controllers/mentee.controller.ts @@ -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' @@ -65,6 +69,26 @@ export const updateMenteeStatus = async ( } } +export const revokeApplication = async ( + req: Request, + res: Response +): Promise> => { + 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 diff --git a/src/routes/mentee/mentee.route.ts b/src/routes/mentee/mentee.route.ts index 9c53cf8..24d255b 100644 --- a/src/routes/mentee/mentee.route.ts +++ b/src/routes/mentee/mentee.route.ts @@ -4,6 +4,7 @@ import { getMenteeDetails, getPublicMenteeDetails, menteeApplicationHandler, + revokeApplication, updateMenteeStatus } from '../../controllers/mentee.controller' import { requestBodyValidator } from '../../middlewares/requestValidator' @@ -26,5 +27,6 @@ menteeRouter.put( [requireAuth, requestBodyValidator(updateMenteeStatusSchema)], updateMenteeStatus ) +menteeRouter.put('/revoke-application', requireAuth, revokeApplication) export default menteeRouter diff --git a/src/services/admin/mentee.service.ts b/src/services/admin/mentee.service.ts index 8abb911..4173885 100644 --- a/src/services/admin/mentee.service.ts +++ b/src/services/admin/mentee.service.ts @@ -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') + } +}