Skip to content

Commit

Permalink
add all mentee emails by status api
Browse files Browse the repository at this point in the history
  • Loading branch information
janithlahirukariyawasam committed Nov 27, 2023
1 parent 52a2637 commit b9dee8a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/controllers/admin/email.controller.ts
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[]>> => {

Check failure on line 9 in src/controllers/admin/email.controller.ts

View workflow job for this annotation

GitHub Actions / build

Don't use `String` as a type. Use string instead
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' })
}
}
2 changes: 2 additions & 0 deletions src/routes/admin/admin.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import mentorRouter from './mentor/mentor.route'
import categoryRouter from './category/category.route'
import platformRouter from './platform/platform.route'
import emailTemplateRouter from './email/emailTemplate.route'
import menteeRouter from './mentee/mentee.route'

const adminRouter = express()

adminRouter.use('/users', userRouter)
adminRouter.use('/mentors', mentorRouter)
adminRouter.use('/mentee',menteeRouter)

Check failure on line 13 in src/routes/admin/admin.route.ts

View workflow job for this annotation

GitHub Actions / build

Insert `·`
adminRouter.use('/categories', categoryRouter)
adminRouter.use('/platform', platformRouter)
adminRouter.use('/emailTemplate', emailTemplateRouter)
Expand Down
11 changes: 11 additions & 0 deletions src/routes/admin/mentee/mentee.route.ts
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

View workflow job for this annotation

GitHub Actions / build

'requireAuth' is defined but never used

Check warning on line 2 in src/routes/admin/mentee/mentee.route.ts

View workflow job for this annotation

GitHub Actions / build

'requireAuth' is defined but never used
import {

Check failure on line 3 in src/routes/admin/mentee/mentee.route.ts

View workflow job for this annotation

GitHub Actions / build

Replace `⏎··getAllMenteeEmails,⏎` with `·getAllMenteeEmails·`
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

View workflow job for this annotation

GitHub Actions / build

Expected exception block, space or tab after '/*' in comment

Check failure on line 9 in src/routes/admin/mentee/mentee.route.ts

View workflow job for this annotation

GitHub Actions / build

Expected space or tab before '*/' in comment

export default menteeRouter
21 changes: 21 additions & 0 deletions src/services/admin/email.service.ts
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<{

Check failure on line 5 in src/services/admin/email.service.ts

View workflow job for this annotation

GitHub Actions / build

Replace `status:·ApplicationStatus·|·undefined` with `⏎··status:·ApplicationStatus·|·undefined⏎`
statusCode: number
emails?: String[]

Check failure on line 7 in src/services/admin/email.service.ts

View workflow job for this annotation

GitHub Actions / build

Don't use `String` as a type. Use string instead
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

View workflow job for this annotation

GitHub Actions / build

Replace `"All·mentee·emails·with·status·"` with `'All·mentee·emails·with·status·'`

Check failure on line 19 in src/services/admin/email.service.ts

View workflow job for this annotation

GitHub Actions / build

Invalid operand for a '+' operation. Operands must each be a number or string. Got `ApplicationStatus | undefined`
}
}

0 comments on commit b9dee8a

Please sign in to comment.