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

CON Reminder Emails #910

Merged
merged 13 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Thumbs.db
# environment variables
.env


# tf
infrastructure/.terraform

# reminder-email stuff
/reminder-email-scripts/*
2 changes: 2 additions & 0 deletions apps/nestjs-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ConMentorshipMatchesModule } from '../con-mentorship-matches/con-mentor
import { ConProblemReportModule } from '../con-problem-report/con-problem-report.module'
import { ConProfilesModule } from '../con-profiles/con-profiles.module'
import { EmailModule } from '../email/email.module'
import { ReminderEmailsModule } from '../reminder-emails/reminder-emails.module'
import { SfApiModule } from '../salesforce-api/sf-api.module'
import { SalesforceRecordEventsListenerModule } from '../salesforce-record-events-listener/salesforce-record-events-listener.module'
import { TpCompanyFavoritedJobseekerProfilesModule } from '../tp-company-favorited-jobseeker-profiles/tp-company-favorited-jobseeker-profiles.module'
Expand Down Expand Up @@ -57,6 +58,7 @@ import { AppService } from './app.service'
TpJobseekerCvModule,
TpJobseekerFavoritedJobListingsModule,
TpCompanyFavoritedJobseekerProfilesModule,
ReminderEmailsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
18 changes: 18 additions & 0 deletions apps/nestjs-api/src/auth/cronjob-auth.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { Observable } from 'rxjs'

@Injectable()
export class CronjobAuthGuard implements CanActivate {
constructor(private config: ConfigService) {}

canActivate(
context: ExecutionContext
): boolean | Promise<boolean> | Observable<boolean> {
const request = context.switchToHttp().getRequest()
return (
request.headers.authorization ===
this.config.get('NX_DAILY_CRONJOB_SEND_REMINDER_EMAIL_SECRET_TOKEN')
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing'
import { ReminderEmailsController } from './reminder-emails.controller'

describe('ReminderEmailsController', () => {
let controller: ReminderEmailsController

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ReminderEmailsController],
}).compile()

controller = module.get<ReminderEmailsController>(ReminderEmailsController)
})

it('should be defined', () => {
expect(controller).toBeDefined()
})
})
178 changes: 178 additions & 0 deletions apps/nestjs-api/src/reminder-emails/reminder-emails.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import { Controller, Get, UseGuards } from '@nestjs/common'
import { UserType } from '@talent-connect/common-types'
import { CronjobAuthGuard } from '../auth/cronjob-auth.guard'
import { ReminderEmailsService } from './reminder-emails.service'

@Controller('reminder-emails')
@UseGuards(CronjobAuthGuard)
export class ReminderEmailsController {
constructor(private readonly reminderEmailsService: ReminderEmailsService) {}

@Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentors-complete-profile')
async sendMentorCompleteProfileReminders() {
const mentorsWithDraftingProfile =
await this.reminderEmailsService.getDraftingConProfiles({
userType: UserType.MENTOR,
})

if (mentorsWithDraftingProfile.length > 0) {
// send reminder emails
mentorsWithDraftingProfile.forEach(async (mentor) => {
await this.reminderEmailsService.sendCompleteProfileReminder({
userType: UserType.MENTOR,
email: mentor.props.email,
firstName: mentor.props.firstName,
})
})
}

return {
message: `Complete Profile reminder emails sent to ${mentorsWithDraftingProfile.length} mentors`,
}
}

@Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentees-complete-profile')
async sendMenteeCompleteProfileReminders() {
const menteesWithDrafingProfile =
await this.reminderEmailsService.getDraftingConProfiles({
userType: UserType.MENTEE,
})

if (menteesWithDrafingProfile.length > 0) {
// send reminder emails
menteesWithDrafingProfile.forEach(async (mentor) => {
await this.reminderEmailsService.sendCompleteProfileReminder({
userType: UserType.MENTEE,
email: mentor.props.email,
firstName: mentor.props.firstName,
})
})
}

return {
message: `Complete Profile reminder emails sent to ${menteesWithDrafingProfile.length} mentees`,
}
}

/**
* Following reminders are implemented but not working as expected.
* They will be tested and fixed in the next iterations.
*/

// @Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentees-apply-to-mentor')
// async sendMenteeApplyToMentorReminders() {
// const firstReminderMentees =
// await this.reminderEmailsService.getApprovedMenteesWithNoMentorApplicationsByDays(
// {
// daysAgo: '7d',
// }
// )

// if (firstReminderMentees.length > 0) {
// // send reminder emails
// firstReminderMentees.forEach(async (mentee) => {
// await this.reminderEmailsService.sendApplyToMentorFirstReminder({
// email: mentee.props.email,
// firstName: mentee.props.firstName,
// location: mentee.props.rediLocation,
// })
// })
// }

// const secondReminderMentees =
// await this.reminderEmailsService.getApprovedMenteesWithNoMentorApplicationsByDays(
// {
// daysAgo: '14d',
// }
// )

// if (secondReminderMentees.length > 0) {
// // send reminder emails
// secondReminderMentees.forEach(async (mentee) => {
// await this.reminderEmailsService.sendApplyToMentorSecondReminder({
// email: mentee.props.email,
// firstName: mentee.props.firstName,
// location: mentee.props.rediLocation,
// })
// })
// }

// return {
// message: `First reminder emails to apply to a mentor sent to ${firstReminderMentees.length} mentees. Second reminder emails to apply to a mentor sent to ${secondReminderMentees.length} mentees`,
// }
// }

@Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentorship-follow-up')
async sendMentorshipFollowUpReminders() {
const threeMonthsOldMentorshipMatches =
await this.reminderEmailsService.getThreeMonthsOldMentorshipMatches()

if (Object.keys(threeMonthsOldMentorshipMatches).length > 0) {
threeMonthsOldMentorshipMatches.forEach(async (match) => {
// Send reminder email to mentee
await this.reminderEmailsService.sendMentorshipFollowUpReminder({
userType: UserType.MENTEE,
email: match.menteeEmail,
firstName: match.menteeFirstName,
menteeOrMentorFirstName: match.mentorFirstName,
})

// Send reminder email to mentor
await this.reminderEmailsService.sendMentorshipFollowUpReminder({
userType: UserType.MENTOR,
email: match.mentorEmail,
firstName: match.mentorFirstName,
menteeOrMentorFirstName: match.menteeFirstName,
})
})
}

return {
message: `Follow-up reminder emails sent to ${
Object.keys(threeMonthsOldMentorshipMatches).length
} mentorship matches`,
}
}

// @Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentees-platform-and-new-mentors')
// async sendUnmatchedMenteesReminder() {
// const unmatchedMenteesWithApprovedProfiles =
// await this.reminderEmailsService.getUnmatchedMenteesWithApprovedProfiles()

// if (unmatchedMenteesWithApprovedProfiles.length > 0) {
// // send reminder emails
// unmatchedMenteesWithApprovedProfiles.forEach(async (mentee) => {
// await this.reminderEmailsService.sendMenteesPlatformAndNewMentorsReminder(
// {
// email: mentee.props.email,
// firstName: mentee.props.firstName,
// }
// )
// })
// }

// return {
// message: `Reminder emails sent to ${unmatchedMenteesWithApprovedProfiles.length} unmatched mentees with approved profiles`,
// }
// }

// @Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentoring-sessions-logging')
// async sendMentoringSessionsLoggingReminder() {
// const conProfilesWithMentoringSessionsToLog =
// await this.reminderEmailsService.getConProfilesWithMentorshipMatchesWithoutMentoringSessions(
// { mentorshipMatchAgeInDays: 402 }
// )

// if (conProfilesWithMentoringSessionsToLog.length > 0) {
// // send reminder emails
// conProfilesWithMentoringSessionsToLog.forEach(async (profile) => {
// await this.reminderEmailsService.sendLogMentoringSessionsReminder({
// email: profile.props.email,
// firstName: profile.props.firstName,
// userType: profile.props.userType,
// mentorshipMatchAgeInDays: 14,
// })
// })
// }
// }
}
19 changes: 19 additions & 0 deletions apps/nestjs-api/src/reminder-emails/reminder-emails.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { ConMentorshipMatchesModule } from '../con-mentorship-matches/con-mentorship-matches.module'
import { ConProfilesModule } from '../con-profiles/con-profiles.module'
import { SfApiModule } from '../salesforce-api/sf-api.module'
import { ReminderEmailsController } from './reminder-emails.controller'
import { ReminderEmailsService } from './reminder-emails.service'

@Module({
imports: [
SfApiModule,
ConProfilesModule,
ConMentorshipMatchesModule,
ConfigModule,
],
controllers: [ReminderEmailsController],
providers: [ReminderEmailsService],
})
export class ReminderEmailsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing'
import { ReminderEmailsService } from './reminder-emails.service'

describe('ReminderEmailsService', () => {
let service: ReminderEmailsService

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ReminderEmailsService],
}).compile()

service = module.get<ReminderEmailsService>(ReminderEmailsService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})
Loading
Loading