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 6 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Thumbs.db
# environment variables
.env


# tf
infrastructure/.terraform

# reminder-email stuff
/reminder-email-scripts/.secrets
/reminder-email-scripts/logs/*
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()
})
})
116 changes: 116 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,116 @@
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`,
}
}

@Get('/s3cr3t-3ndp01nt-t0-tr1gg3r-r3m1nd3r5/mentees-apply-to-mentor')
async sendMenteeApplyToMentorReminders() {
const firstReminderMentees =
await this.reminderEmailsService.getApprovedMenteesByDaysAndLocation({
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.getApprovedMenteesByDaysAndLocation({
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 conProfilesWithThreeMonthsOldMentorshipMatches =
await this.reminderEmailsService.getConProfilesWithThreeMonthsOldMentorshipMatches()

if (conProfilesWithThreeMonthsOldMentorshipMatches.length > 0) {
// send reminder emails
conProfilesWithThreeMonthsOldMentorshipMatches.forEach(async (match) => {
await this.reminderEmailsService.mentorshipFollowUpReminder({
email: match.props.email,
firstName: match.props.firstName,
userType: match.props.userType,
})
})
}

return {
message: `Follow-up reminder emails sent to ${conProfilesWithThreeMonthsOldMentorshipMatches.length} mentorship matches`,
}
}
}
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