Skip to content

Commit

Permalink
chore: Agregar authorization header en getScoreAverage
Browse files Browse the repository at this point in the history
  • Loading branch information
judlup committed Oct 22, 2024
1 parent 5d7a88d commit 8858c8f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/clients/assessments/assessments.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ export class AssessmentsClient {

async getAssessmentByBootcampId(
bootcampId: string,
token: string,
): Promise<AssessmentEntity[]> {
try {
const response = await this.httpService
.get(
`${this.environmentConfigService.ASSESSEMENT_SERVICE_URL}/bootcamp/${bootcampId}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
)
.toPromise();
return response.data;
Expand Down
19 changes: 16 additions & 3 deletions src/controllers/bootcamps/bootcamps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ParseUUIDPipe,
Post,
Put,
Req,
Res,
UploadedFile,
UseGuards,
Expand Down Expand Up @@ -366,10 +367,15 @@ export class BootcampsController {
@Get('score/:id')
async getScoreAverage(
@Param('id', ParseUUIDPipe) id: string,
@Req() request: Request,
): Promise<BootcampEntity> {
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,
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/models/bootcamp/bootcamp.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { genereUUID } from 'src/utils/uuid/uuid.utils';
import {
BeforeInsert,
Column,
CreateDateColumn,
Entity,
Expand All @@ -9,6 +10,11 @@ import {

@Entity('bootcamps')
export class BootcampEntity {
@BeforeInsert()
setId() {
this.id = genereUUID();
}

@PrimaryColumn({ unique: true, default: genereUUID() })
id: string;

Expand Down

0 comments on commit 8858c8f

Please sign in to comment.