Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…e-job-back into fix/whatsapp-url-coach-in-user
  • Loading branch information
guillobits committed Sep 27, 2024
2 parents 23d4e49 + 7cb7ae6 commit 695dddd
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 35 deletions.
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.25.6",
"version": "2.26.0",
"license": "ISC",
"engines": {
"node": "18.x"
Expand Down
26 changes: 4 additions & 22 deletions src/cvs/cvs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
UserRoles,
} from 'src/users/users.types';
import { isRoleIncluded } from 'src/users/users.utils';
import { AdminZone, FilterParams } from 'src/utils/types';
import { FilterParams } from 'src/utils/types';
import { CVsService } from './cvs.service';
import { CVFilterKey } from './cvs.types';
import { getPDFPaths } from './cvs.utils';
Expand All @@ -60,7 +60,6 @@ export class CVsController {
@UserPayload() user: User,
@UserPayload('id', new ParseUUIDPipe()) userId: string,
@UserPayload('role') role: UserRole,
@UserPayload('zone') zone: AdminZone,
@Param('candidateId', new ParseUUIDPipe()) candidateId: string,
@Body('cv', new ParseCVPipe()) createCVDto: CreateCVDto,
@Body('autoSave') autoSave: boolean,
Expand Down Expand Up @@ -147,28 +146,17 @@ export class CVsController {

const token = getTokenFromHeaders(req);

let isTwoPages = false;

if (
(createCVDto.experiences?.length || 0) +
(createCVDto.formations?.length || 0) >
4
) {
isTwoPages = true;
}

// génération du CV en version PDF; exécution par lambda AWS
await this.cvsService.sendGenerateCVPDF(
candidateId,
token,
`${firstName}_${lastName}`,
isTwoPages
`${firstName}_${lastName}`
);
}
return createdCV;
}

/*
/*
récupérer une liste de CVs publiés aléatoirement pour la gallerie
*/
@Public()
Expand Down Expand Up @@ -216,17 +204,11 @@ export class CVsController {

const pdfUrl = await this.cvsService.findPDF(s3Key);

const cv = await this.cvsService.findOneByCandidateId(candidateId);

let isTwoPages = false;
if (cv.experiences?.length + cv.formations?.length > 4) isTwoPages = true;

if (!pdfUrl) {
const createdPdfUrl = await this.cvsService.generatePDFFromCV(
candidateId,
getTokenFromHeaders(req),
fileName,
isTwoPages
fileName
);
return {
pdfUrl: createdPdfUrl,
Expand Down
8 changes: 2 additions & 6 deletions src/cvs/cvs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,7 @@ export class CVsService {
async generatePDFFromCV(
candidateId: string,
token: string,
/*paths: string[],*/ fileName: string,
isTwoPages: boolean
fileName: string
) {
const response = await fetch(`${process.env.CV_PDF_GENERATION_AWS_URL}`, {
headers: {
Expand All @@ -670,7 +669,6 @@ export class CVsService {
candidateId,
token,
fileName,
isTwoPages,
}),
});

Expand Down Expand Up @@ -1108,14 +1106,12 @@ export class CVsService {
async sendGenerateCVPDF(
candidateId: string,
token: string,
fileName: string,
isTwoPages: boolean
fileName: string
) {
await this.queuesService.addToWorkQueue(Jobs.GENERATE_CV_PDF, {
candidateId,
token,
fileName,
isTwoPages,
});
}

Expand Down
19 changes: 19 additions & 0 deletions src/external-databases/external-databases.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Injectable } from '@nestjs/common';
import { CreateUserRegistrationDto } from '../users-creation/dto';
import { CandidateGender, CandidateGenders } from 'src/contacts/contacts.types';
import { QueuesService } from 'src/queues/producers/queues.service';
import { Jobs } from 'src/queues/queues.types';
import { Genders } from 'src/users/users.types';

@Injectable()
export class ExternalDatabasesService {
Expand Down Expand Up @@ -50,13 +52,30 @@ export class ExternalDatabasesService {
| 'workingExperience'
| 'jobSearchDuration'
| 'workingRight'
| 'gender'
>
) {
let conertedGenderType: CandidateGender;
switch (otherInfo.gender) {
case Genders.MALE:
conertedGenderType = CandidateGenders.MALE;
break;
case Genders.FEMALE:
conertedGenderType = CandidateGenders.FEMALE;
break;
case Genders.OTHER:
conertedGenderType = CandidateGenders.OTHER;
break;
default:
throw new Error('Invalid gender value');
}

await this.queuesService.addToWorkQueue(
Jobs.CREATE_OR_UPDATE_SALESFORCE_USER,
{
userId,
...otherInfo,
gender: conertedGenderType,
}
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/external-services/salesforce/salesforce.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import moment from 'moment-timezone';

import {
CandidateAccommodation,
CandidateGender,
CandidateResource,
CandidateYesNoNSPPValue,
JobSearchDuration,
Expand Down Expand Up @@ -1190,6 +1191,7 @@ export class SalesforceService {
workingExperience,
workingRight,
jobSearchDuration,
gender,
}: UserProps) {
const contactSf = await this.findContact(email);
let contactSfId = contactSf?.Id;
Expand Down Expand Up @@ -1220,6 +1222,7 @@ export class SalesforceService {
workingExperience,
jobSearchDuration,
workingRight,
gender,
};

const leadSfId = (await this.findOrCreateLead(
Expand Down Expand Up @@ -1283,6 +1286,7 @@ export class SalesforceService {
studiesLevel,
workingExperience,
jobSearchDuration,
gender,
};

contactSfId = (await this.createContact(
Expand Down Expand Up @@ -1813,6 +1817,7 @@ export class SalesforceService {
studiesLevel?: StudiesLevel;
workingExperience?: WorkingExperience;
jobSearchDuration?: JobSearchDuration;
gender?: CandidateGender;
}
) {
this.setIsWorker(true);
Expand All @@ -1832,6 +1837,7 @@ export class SalesforceService {
studiesLevel: otherInfo.studiesLevel,
workingExperience: otherInfo.workingExperience,
jobSearchDuration: otherInfo.jobSearchDuration,
gender: otherInfo.gender,
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/external-services/salesforce/salesforce.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ export interface ContactProps {
studiesLevel?: StudiesLevel;
workingExperience?: WorkingExperience;
jobSearchDuration?: JobSearchDuration;
gender?: CandidateGender;
}

export interface SalesforceContact {
Expand All @@ -634,6 +635,7 @@ export interface SalesforceContact {
Dur_e_de_recherche_d_emploi__c: string;
Situation_d_h_bergement__c: string;
Type_de_ressources__c?: string;
Genre__c: string;
}

export interface CompanyLeadProps {
Expand Down Expand Up @@ -861,6 +863,7 @@ export interface CoachSalesforceLead {
RecordTypeId: LeadRecordType;
Antenne__c: string;
Source__c: 'Lead entrant';
Genre__c: CandidateGender | null;
}

export interface UserProps {
Expand All @@ -882,4 +885,5 @@ export interface UserProps {
studiesLevel?: StudiesLevel;
workingExperience?: WorkingExperience;
jobSearchDuration?: JobSearchDuration;
gender?: CandidateGender;
}
2 changes: 2 additions & 0 deletions src/external-services/salesforce/salesforce.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ export const mapSalesforceContactFields = (
studiesLevel,
workingExperience,
jobSearchDuration,
gender,
}: ContactProps,
recordType: ContactRecordType
): SalesforceContact => {
Expand Down Expand Up @@ -667,6 +668,7 @@ export const mapSalesforceContactFields = (
resources,
LeadResources
),
Genre__c: formatSalesforceValue<CandidateGender>(gender, LeadGender),
};
};

Expand Down
6 changes: 5 additions & 1 deletion src/mails/mails.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export class MailsService {
{
toEmail: user.email,
templateId: MailjetTemplates.ONBOARDING_J3_PROFILE_COMPLETION,
variables: { firstName: user.firstName },
variables: {
firstName: user.firstName,
role: getRoleString(user),
zone: user.zone,
},
},
{
//trois jours après la création du compte
Expand Down
4 changes: 2 additions & 2 deletions src/queues/consumers/work-queue.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ export class WorkQueueProcessor {
await this.cvsService.generatePDFFromCV(
data.candidateId,
data.token,
data.fileName,
data.isTwoPages
data.fileName
);

await this.pusherService.sendEvent(
Expand Down Expand Up @@ -434,6 +433,7 @@ export class WorkQueueProcessor {
workingExperience: data.workingExperience,
jobSearchDuration: data.jobSearchDuration,
workingRight: data.workingRight,
gender: data.gender,
});
return `Salesforce : created or updated user '${data.userId}'`;
}
Expand Down
3 changes: 2 additions & 1 deletion src/queues/queues.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BusinessLine } from 'src/common/business-lines/models';
import { Location } from 'src/common/locations/models';
import {
CandidateAccommodation,
CandidateGender,
CandidateResource,
CandidateYesNoNSPPValue,
JobSearchDuration,
Expand Down Expand Up @@ -126,7 +127,6 @@ export interface GenerateCVPDFJob {
candidateId: string;
token: string;
fileName: string;
isTwoPages: boolean;
}

export interface GenerateCVPreviewJob {
Expand Down Expand Up @@ -165,6 +165,7 @@ export interface CreateOrUpdateSalesforceUserJob {
workingExperience?: WorkingExperience;
jobSearchDuration?: JobSearchDuration;
workingRight?: CandidateYesNoNSPPValue;
gender?: CandidateGender;
}

export interface SendOffersEmailAfterCVPublishJob {
Expand Down
4 changes: 2 additions & 2 deletions src/user-profiles/user-profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ export class UserProfilesService {
),
this.mailsService.sendUserReportedMail(
report,
userReporter,
userReported
userReported,
userReporter
),
]);
}
Expand Down
1 change: 1 addition & 0 deletions src/users-creation/users-creation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export class UsersCreationController {
studiesLevel: createUserRegistrationDto.studiesLevel,
workingExperience: createUserRegistrationDto.workingExperience,
jobSearchDuration: createUserRegistrationDto.jobSearchDuration,
gender: createUserRegistrationDto.gender,
});

if (createUserRegistrationDto.program === Programs.BOOST) {
Expand Down
1 change: 1 addition & 0 deletions src/users-creation/users-creation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class UsersCreationService {
| 'workingExperience'
| 'jobSearchDuration'
| 'workingRight'
| 'gender'
>
) {
return this.externalDatabasesService.createExternalDBUser(
Expand Down

0 comments on commit 695dddd

Please sign in to comment.