Skip to content

Commit

Permalink
Merge branch 'hotfix/put_newsletter_in_job'
Browse files Browse the repository at this point in the history
  • Loading branch information
emile-bex committed Nov 6, 2023
2 parents c58736f + 88204c8 commit 7c4c541
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 36 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
NODE_ENV: test
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
CHROME_PATH: ${{ secrets.CHROME_PATH }}

steps:
- uses: actions/checkout@v2
Expand Down
32 changes: 11 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ ADMIN_COMPANIES_LORIENT=
ADMIN_COMPANIES_LYON=
ADMIN_COMPANIES_PARIS=
ADMIN_COMPANIES_RENNES=
AIRTABLE_API_KEY=
AIRTABLE_BASE_ID=
AIRTABLE_OFFERS=
AUTO_RECOMMENDATIONS_ZONE=
AWS_LAMBDA_URL=
AWSS3_BUCKET_NAME=
AWSS3_FILE_DIRECTORY=
Expand All @@ -207,53 +203,47 @@ AWSS3_IMAGE_DIRECTORY=
AWSS3_SECRET=
BITLY_TOKEN=
CDN_ID=
CHROME_PATH=
CV_10_REMINDER_DELAY=
CV_20_REMINDER_DELAY=
CV_PDF_GENERATION_AWS_URL=
CV_START_DELAY=
DATABASE_URL=
DEBUG_JOBS=
ENABLE_SF=
EXTERNAL_OFFERS_REMINDER_DELAY=
FRONT_URL=
INTERVIEW_TRAINING_REMINDER_DELAY=
INTERVIEW_TRAINING_REMINDER_DELAY
JWT_SECRET=
MAILCHIMP_API_KEY=
MAILCHIMP_AUDIENCE_ID=
MAILJET_CONTACT_EMAIL=
MAILJET_FROM_EMAIL=
MAILJET_FROM_NAME=
MAILJET_NEWSLETTER_LIST_ID=
MAILJET_NEWSLETTER_PUB=
MAILJET_NEWSLETTER_SEC=
MAILJET_PUB=
MAILJET_SEC=
MAILJET_SMS_TOKEN=
MAILJET_SUPPORT_EMAIL=
OFFER_ARCHIVE_REMINDER_DELAY=
OFFER_NO_RESPONSE_DELAY=
OFFER_REMINDER_DELAY=
PORT=
PUSHER_API_KEY=
PUSHER_API_SECRET=
PUSHER_APP_ID=
PUSHER_URL=
REDIS_URL=
SALESFORCE_CLIENT_ID=
SALESFORCE_CLIENT_ID=
SALESFORCE_CLIENT_SECRET=
SALESFORCE_CLIENT_SECRET=
SALESFORCE_LOGIN_URL=
SALESFORCE_LOGIN_URL=
SALESFORCE_PASSWORD=
SALESFORCE_PASSWORD=
SALESFORCE_REDIRECT_URI=
SALESFORCE_REDIRECT_URI=
SALESFORCE_SECURITY_TOKEN=
SALESFORCE_SECURITY_TOKEN=
SALESFORCE_USERNAME=
SALESFORCE_USERNAME=
SEND_OFFERS_EMAIL_AFTER_CV_PUBLISH_DELAY=
SENTRY_DSN=
SERVER_TIMEOUT=
USE_MAILJET_SMS=
USE_SMS=
SF_INFOCO_CAMPAIGN_ID=
SF_ORGANIZATION_ID=
VIDEO_REMINDER_DELAY=
VONAGE_API_KEY=
VONAGE_API_SECRET=
```

## Tests
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkedout-backend",
"version": "2.16.1",
"version": "2.16.2",
"license": "ISC",
"engines": {
"node": "16.x"
Expand Down
2 changes: 1 addition & 1 deletion src/contacts/contacts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class ContactsController {
throw new BadRequestException();
}

await this.contactsService.sendContactToMailjet({
return this.contactsService.sendContactToMailjet({
email,
zone,
status,
Expand Down
4 changes: 2 additions & 2 deletions src/contacts/contacts.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { MailjetModule } from 'src/external-services/mailjet/mailjet.module';
import { SalesforceModule } from 'src/external-services/salesforce/salesforce.module';
import { MailsModule } from 'src/mails/mails.module';
import { QueuesModule } from 'src/queues/producers';
import { ContactsController } from './contacts.controller';
import { ContactsService } from './contacts.service';

@Module({
imports: [MailsModule, SalesforceModule, MailjetModule],
imports: [MailsModule, SalesforceModule, QueuesModule],
controllers: [ContactsController],
providers: [ContactsService],
exports: [ContactsService],
Expand Down
12 changes: 8 additions & 4 deletions src/contacts/contacts.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Injectable } from '@nestjs/common';
import { MailjetService } from '../external-services/mailjet/mailjet.service';
import { CustomContactParams } from '../external-services/mailjet/mailjet.types';
import { ContactCompanyFormDto, ContactUsFormDto } from 'src/contacts/dto';
import { CustomContactParams } from 'src/external-services/mailjet/mailjet.types';
import { SalesforceService } from 'src/external-services/salesforce/salesforce.service';
import { MailsService } from 'src/mails/mails.service';
import { QueuesService } from 'src/queues/producers/queues.service';
import { Jobs } from 'src/queues/queues.types';
import { ContactCandidateFormDto } from './dto/contact-candidate-form.dto';
import { InscriptionCandidateFormDto } from './dto/inscription-candidate-form.dto';

Expand All @@ -12,11 +13,14 @@ export class ContactsService {
constructor(
private mailsService: MailsService,
private salesforceService: SalesforceService,
private mailjetService: MailjetService
private queuesService: QueuesService
) {}

async sendContactToMailjet(contact: CustomContactParams) {
return this.mailjetService.sendContact(contact);
await this.queuesService.addToWorkQueue(
Jobs.NEWSLETTER_SUBSCRIPTION,
contact
);
}

async sendCompanyContactToSalesforce(
Expand Down
4 changes: 1 addition & 3 deletions src/opportunities/opportunities.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Module } from '@nestjs/common';
import { SequelizeModule } from '@nestjs/sequelize';
import { ContractsModule } from '../common/contracts/contracts.module';
import { BusinessLinesModule } from 'src/common/business-lines/business-lines.module';
import { ContractsModule } from 'src/common/contracts/contracts.module';
import { CVsModule } from 'src/cvs/cvs.module';
import { ExternalDatabasesModule } from 'src/external-databases/external-databases.module';
import { MailjetModule } from 'src/external-services/mailjet/mailjet.module';
import { MailsModule } from 'src/mails/mails.module';
import { QueuesModule } from 'src/queues/producers';
import { SMSModule } from 'src/sms/sms.module';
Expand Down Expand Up @@ -34,7 +33,6 @@ import { OpportunityUsersService } from './opportunity-users.service';
CVsModule,
BusinessLinesModule,
MailsModule,
MailjetModule,
SMSModule,
ExternalDatabasesModule,
QueuesModule,
Expand Down
4 changes: 1 addition & 3 deletions src/opportunities/opportunities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { InjectModel } from '@nestjs/sequelize';
import * as _ from 'lodash';
import moment from 'moment';
import { Op } from 'sequelize';
import { MailjetService } from '../external-services/mailjet/mailjet.service';
import { BusinessLineValue } from 'src/common/business-lines/business-lines.types';
import { BusinessLine } from 'src/common/business-lines/models';
import {
Expand Down Expand Up @@ -81,7 +80,6 @@ export class OpportunitiesService {
private cvsService: CVsService,
private externalDatabasesService: ExternalDatabasesService,
private mailsService: MailsService,
private mailjetService: MailjetService,
private smsService: SMSService
) {}

Expand Down Expand Up @@ -690,7 +688,7 @@ export class OpportunitiesService {
}

try {
await this.mailjetService.sendContact({
await this.queuesService.addToWorkQueue(Jobs.NEWSLETTER_SUBSCRIPTION, {
email: opportunity.contactMail || opportunity.recruiterMail,
zone: getZoneFromDepartment(opportunity.department),
status: ContactStatuses.COMPANY,
Expand Down
10 changes: 10 additions & 0 deletions src/queues/consumers/work-queue.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
GenerateCVPreviewJob,
GenerateCVSearchStringJob,
Jobs,
NewsletterSubscriptionJob,
Queues,
SendMailJob,
SendNoResponseOfferJob,
Expand Down Expand Up @@ -121,6 +122,15 @@ export class WorkQueueProcessor {
})}'`;
}

@Process(Jobs.NEWSLETTER_SUBSCRIPTION)
async processNewsletterSubscription(job: Job<NewsletterSubscriptionJob>) {
const { data } = job;

await this.mailjetService.sendContact(data);

return `Contact '${data.email}' subscribed to newsletter`;
}

@Process(Jobs.SEND_SMS)
async processSendSMS(job: Job<SendSMSJob | SendSMSJob[]>) {
const { data } = job;
Expand Down
5 changes: 5 additions & 0 deletions src/queues/queues.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BusinessLine } from 'src/common/business-lines/models';
import { Location } from 'src/common/locations/models';
import {
CustomContactParams,
CustomMailParams,
MailjetTemplate,
} from 'src/external-services/mailjet/mailjet.types';
Expand All @@ -13,6 +14,7 @@ export const Jobs = {
CACHE_CV: 'cache_cv',
CACHE_ALL_CVS: 'cache_all_cvs',
SEND_MAIL: 'send_mail',
NEWSLETTER_SUBSCRIPTION: 'newsletter_subscription',
SEND_SMS: 'send_sms',
CREATE_OR_UPDATE_SALESFORCE_OPPORTUNITY:
'create_or_update_salesforce_opportunity',
Expand All @@ -39,6 +41,7 @@ type JobsData = {
[Jobs.CACHE_CV]: CacheCVJob;
[Jobs.CACHE_ALL_CVS]: CacheAllCVJob;
[Jobs.SEND_MAIL]: SendMailJob | SendMailJob[];
[Jobs.NEWSLETTER_SUBSCRIPTION]: NewsletterSubscriptionJob;
[Jobs.SEND_SMS]: SendSMSJob | SendSMSJob[];
[Jobs.CREATE_OR_UPDATE_SALESFORCE_OPPORTUNITY]: CreateOrUpdateSalesforceOpportunityJob;
[Jobs.CREATE_OR_UPDATE_SALESFORCE_EVENT]: CreateOrUpdateSalesforceEventJob;
Expand All @@ -62,6 +65,8 @@ export interface SendMailJob extends CustomMailParams {
variables: object;
}

export interface NewsletterSubscriptionJob extends CustomContactParams {}

export interface SendSMSJob extends CustomSMSParams {}

export interface SendReminderOfferJob {
Expand Down

0 comments on commit 7c4c541

Please sign in to comment.