From 8858c8f96d9f05fc388150483b4bcccc5ff68683 Mon Sep 17 00:00:00 2001 From: JudLup Luna Date: Mon, 21 Oct 2024 22:51:23 -0500 Subject: [PATCH] chore: Agregar authorization header en getScoreAverage --- src/clients/assessments/assessments.client.ts | 6 ++++++ .../bootcamps/bootcamps.controller.ts | 19 ++++++++++++++++--- src/models/bootcamp/bootcamp.entity.ts | 6 ++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/clients/assessments/assessments.client.ts b/src/clients/assessments/assessments.client.ts index a449f85..1da8c1c 100644 --- a/src/clients/assessments/assessments.client.ts +++ b/src/clients/assessments/assessments.client.ts @@ -12,11 +12,17 @@ export class AssessmentsClient { async getAssessmentByBootcampId( bootcampId: string, + token: string, ): Promise { try { const response = await this.httpService .get( `${this.environmentConfigService.ASSESSEMENT_SERVICE_URL}/bootcamp/${bootcampId}`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + }, ) .toPromise(); return response.data; diff --git a/src/controllers/bootcamps/bootcamps.controller.ts b/src/controllers/bootcamps/bootcamps.controller.ts index 0dc6418..2a0bfdb 100644 --- a/src/controllers/bootcamps/bootcamps.controller.ts +++ b/src/controllers/bootcamps/bootcamps.controller.ts @@ -9,6 +9,7 @@ import { ParseUUIDPipe, Post, Put, + Req, Res, UploadedFile, UseGuards, @@ -366,10 +367,15 @@ export class BootcampsController { @Get('score/:id') async getScoreAverage( @Param('id', ParseUUIDPipe) id: string, + @Req() request: Request, ): Promise { try { + const authorizationToken = request.headers['authorization'].split(' ')[1]; const getAssessmentByBootcampIdResponse = - await this.assessmentsClient.getAssessmentByBootcampId(id); + await this.assessmentsClient.getAssessmentByBootcampId( + id, + authorizationToken, + ); return await this.bootcampsService.getScoreAverage( id, getAssessmentByBootcampIdResponse, @@ -390,10 +396,17 @@ export class BootcampsController { type: Number, }) @Post('score/recalculate/:id') - async recalculateScoreAverage(@Param('id', ParseUUIDPipe) id: string) { + async recalculateScoreAverage( + @Param('id', ParseUUIDPipe) id: string, + @Req() request: Request, + ) { try { + const authorizationToken = request.headers['authorization'].split(' ')[1]; const getAssessmentByBootcampIdResponse = - await this.assessmentsClient.getAssessmentByBootcampId(id); + await this.assessmentsClient.getAssessmentByBootcampId( + id, + authorizationToken, + ); return await this.bootcampsService.recalculateScoreAverage( id, getAssessmentByBootcampIdResponse, diff --git a/src/models/bootcamp/bootcamp.entity.ts b/src/models/bootcamp/bootcamp.entity.ts index 985482a..cca9db6 100644 --- a/src/models/bootcamp/bootcamp.entity.ts +++ b/src/models/bootcamp/bootcamp.entity.ts @@ -1,5 +1,6 @@ import { genereUUID } from 'src/utils/uuid/uuid.utils'; import { + BeforeInsert, Column, CreateDateColumn, Entity, @@ -9,6 +10,11 @@ import { @Entity('bootcamps') export class BootcampEntity { + @BeforeInsert() + setId() { + this.id = genereUUID(); + } + @PrimaryColumn({ unique: true, default: genereUUID() }) id: string;