diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe4281fe..ed789940 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/README.md b/README.md index 038c259b..f8fcc817 100644 --- a/README.md +++ b/README.md @@ -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= @@ -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 diff --git a/package.json b/package.json index 72ed2f2f..9f65da6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkedout-backend", - "version": "2.16.1", + "version": "2.16.2", "license": "ISC", "engines": { "node": "16.x" diff --git a/src/contacts/contacts.controller.ts b/src/contacts/contacts.controller.ts index 7dc73edd..ca2941f6 100644 --- a/src/contacts/contacts.controller.ts +++ b/src/contacts/contacts.controller.ts @@ -87,7 +87,7 @@ export class ContactsController { throw new BadRequestException(); } - await this.contactsService.sendContactToMailjet({ + return this.contactsService.sendContactToMailjet({ email, zone, status, diff --git a/src/contacts/contacts.module.ts b/src/contacts/contacts.module.ts index c0033033..570b9516 100644 --- a/src/contacts/contacts.module.ts +++ b/src/contacts/contacts.module.ts @@ -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], diff --git a/src/contacts/contacts.service.ts b/src/contacts/contacts.service.ts index 09e59aa1..d5836b2f 100644 --- a/src/contacts/contacts.service.ts +++ b/src/contacts/contacts.service.ts @@ -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'; @@ -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( diff --git a/src/opportunities/opportunities.module.ts b/src/opportunities/opportunities.module.ts index 4539e827..c4e1c09a 100644 --- a/src/opportunities/opportunities.module.ts +++ b/src/opportunities/opportunities.module.ts @@ -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'; @@ -34,7 +33,6 @@ import { OpportunityUsersService } from './opportunity-users.service'; CVsModule, BusinessLinesModule, MailsModule, - MailjetModule, SMSModule, ExternalDatabasesModule, QueuesModule, diff --git a/src/opportunities/opportunities.service.ts b/src/opportunities/opportunities.service.ts index 934ab20c..2fe2bf27 100644 --- a/src/opportunities/opportunities.service.ts +++ b/src/opportunities/opportunities.service.ts @@ -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 { @@ -81,7 +80,6 @@ export class OpportunitiesService { private cvsService: CVsService, private externalDatabasesService: ExternalDatabasesService, private mailsService: MailsService, - private mailjetService: MailjetService, private smsService: SMSService ) {} @@ -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, diff --git a/src/queues/consumers/work-queue.processor.ts b/src/queues/consumers/work-queue.processor.ts index f07e880f..615f3338 100644 --- a/src/queues/consumers/work-queue.processor.ts +++ b/src/queues/consumers/work-queue.processor.ts @@ -29,6 +29,7 @@ import { GenerateCVPreviewJob, GenerateCVSearchStringJob, Jobs, + NewsletterSubscriptionJob, Queues, SendMailJob, SendNoResponseOfferJob, @@ -121,6 +122,15 @@ export class WorkQueueProcessor { })}'`; } + @Process(Jobs.NEWSLETTER_SUBSCRIPTION) + async processNewsletterSubscription(job: Job) { + const { data } = job; + + await this.mailjetService.sendContact(data); + + return `Contact '${data.email}' subscribed to newsletter`; + } + @Process(Jobs.SEND_SMS) async processSendSMS(job: Job) { const { data } = job; diff --git a/src/queues/queues.types.ts b/src/queues/queues.types.ts index 6ad7c9e6..ece66ac8 100644 --- a/src/queues/queues.types.ts +++ b/src/queues/queues.types.ts @@ -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'; @@ -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', @@ -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; @@ -62,6 +65,8 @@ export interface SendMailJob extends CustomMailParams { variables: object; } +export interface NewsletterSubscriptionJob extends CustomContactParams {} + export interface SendSMSJob extends CustomSMSParams {} export interface SendReminderOfferJob {