-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52a2637
commit b9dee8a
Showing
4 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Request, Response } from 'express' | ||
import type { ApiResponse } from '../../types' | ||
import { getAllMenteeEmailsService } from '../../services/admin/email.service' | ||
import { ApplicationStatus } from '../../enums' | ||
|
||
export const getAllMenteeEmails = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<ApiResponse<String[]>> => { | ||
try { | ||
const status = req.query.status | ||
if ( | ||
status === ApplicationStatus.APPROVED || | ||
status === ApplicationStatus.REJECTED || | ||
status === ApplicationStatus.PENDING | ||
) { | ||
console.log(status) | ||
const { emails, statusCode, message } = await getAllMenteeEmailsService( | ||
status | ||
) | ||
return res.status(statusCode).json({ emails, message }) | ||
} else { | ||
return res.status(400).json({ message: 'Invalid Status' }) | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
return res.status(500).json({ error: err || 'Internal Server Error' }) | ||
} | ||
} |
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,11 @@ | ||
import express from 'express' | ||
import { requireAuth } from '../../../controllers/auth.controller' | ||
Check failure on line 2 in src/routes/admin/mentee/mentee.route.ts GitHub Actions / build
|
||
import { | ||
getAllMenteeEmails, | ||
} from '../../../controllers/admin/email.controller' | ||
|
||
const menteeRouter = express.Router() | ||
|
||
menteeRouter.get('/emails/', /*requireAuth,*/ getAllMenteeEmails) | ||
Check failure on line 9 in src/routes/admin/mentee/mentee.route.ts GitHub Actions / build
|
||
|
||
export default menteeRouter |
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,21 @@ | ||
import { dataSource } from '../../configs/dbConfig' | ||
import Mentee from '../../entities/mentee.entity' | ||
import type { ApplicationStatus } from '../../enums' | ||
|
||
export const getAllMenteeEmailsService = async (status: ApplicationStatus | undefined): Promise<{ | ||
statusCode: number | ||
emails?: String[] | ||
message: string | ||
}> => { | ||
const menteeRepositroy = dataSource.getRepository(Mentee) | ||
const allMentees: Mentee[] = await menteeRepositroy.find({ | ||
where: status ? { state: status } : {}, | ||
relations: ['profile'] | ||
}) | ||
const emails = allMentees.map((mentee) => mentee?.profile?.primary_email) | ||
return { | ||
statusCode: 200, | ||
emails, | ||
message: "All mentee emails with status " + status | ||
Check failure on line 19 in src/services/admin/email.service.ts GitHub Actions / build
|
||
} | ||
} |