Skip to content

Commit

Permalink
refacto(cv-pdf): remove useless isTwoPages params
Browse files Browse the repository at this point in the history
  • Loading branch information
guillobits committed Sep 25, 2024
1 parent b8d0831 commit 4ea58d2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
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
3 changes: 1 addition & 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
1 change: 0 additions & 1 deletion src/queues/queues.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export interface GenerateCVPDFJob {
candidateId: string;
token: string;
fileName: string;
isTwoPages: boolean;
}

export interface GenerateCVPreviewJob {
Expand Down

0 comments on commit 4ea58d2

Please sign in to comment.