Skip to content

Commit

Permalink
Merge pull request #129 from Trycatch-tv/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
judlup authored Sep 3, 2024
2 parents 3f02ac3 + c1c47ff commit 8d0e58a
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/controllers/assessments/assessments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import {
ParseUUIDPipe,
Post,
Put,
UseGuards,
} from '@nestjs/common';

import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import { boolean } from 'joi';
import { BootcampsClient } from 'src/clients/bottcamps/bootcamps.client';
import { Roles } from 'src/decorators/user/roles.decorator';
import { CreateOneAssessmentDto } from 'src/dtos/assessment/createOneAssessment.dto';
import { UpdateManyAssessmentDto } from 'src/dtos/assessment/updateManyAssessment.dto';
import { Role } from 'src/enum/user/role.enum';
import { RoleGuard } from 'src/guards/user/role.guard';
import { AuthGuard } from 'src/guards/user/user.guard';
import { CreateOneAssessmentResponse } from 'src/responses/assessments/createAssessment.response';
import CreateManyAssessmentResponse from 'src/responses/assessments/createManyAssessment.response';
import { AssessmentsService } from 'src/services/assessments/assessments.service';
Expand All @@ -26,6 +32,8 @@ export class AssessmentsController {
private readonly bootcampsClient: BootcampsClient,
) {}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Create new assessment',
Expand All @@ -46,6 +54,8 @@ export class AssessmentsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Create new assessment',
Expand Down Expand Up @@ -77,6 +87,8 @@ export class AssessmentsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Get assessment by bootcamp id',
Expand All @@ -95,6 +107,8 @@ export class AssessmentsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: UpdateManyAssessmentDto })
@ApiResponse({
status: 200,
Expand Down
19 changes: 19 additions & 0 deletions src/controllers/bootcamps/bootcamps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Put,
Res,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
Expand All @@ -19,11 +20,15 @@ import { Response } from 'express';
import { firstValueFrom } from 'rxjs';
import { AssessmentsClient } from 'src/clients/assessments/assessments.client';
import { FilesClient } from 'src/clients/files/files.client';
import { Roles } from 'src/decorators/user/roles.decorator';
import { CreateBootcampDto } from 'src/dtos/bootcamps/createBootcamp.dto';
import { UpdateBootcampDto } from 'src/dtos/bootcamps/updateBootcamp.dto';
import { UpdateScoreBootcampDto } from 'src/dtos/bootcamps/updateScoreBoocamp.dto';
import { UploadAvatarBootcampDto } from 'src/dtos/bootcamps/uploadAvatarBootcamp.dto';
import { UploadTermsAndConditionsBootcampDto } from 'src/dtos/bootcamps/uploadTermsAndConditionsBootcamp.dto';
import { Role } from 'src/enum/user/role.enum';
import { RoleGuard } from 'src/guards/user/role.guard';
import { AuthGuard } from 'src/guards/user/user.guard';
import { BootcampEntity } from 'src/models/bootcamp/bootcamp.entity';
import { CreateOneBootcampResponse } from 'src/responses/bootcamps/createOneBootcamp.response';
import { findAllBootcampsResponse } from 'src/responses/bootcamps/findAllBootcamp.response';
Expand Down Expand Up @@ -63,6 +68,8 @@ export class BootcampsController {
return await this.bootcampsService.findAll();
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: CreateBootcampDto })
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -100,6 +107,8 @@ export class BootcampsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: CreateBootcampDto })
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -138,6 +147,8 @@ export class BootcampsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Remove bootcamp by id.',
Expand All @@ -157,6 +168,8 @@ export class BootcampsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: UploadAvatarBootcampDto })
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -230,6 +243,8 @@ export class BootcampsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: UploadTermsAndConditionsBootcampDto })
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -303,6 +318,8 @@ export class BootcampsController {
}
}

// TODO: Validar si el flujo de calcular el score de un bootcamp
// lo utiliza, si no, los permisos deben ser del rol admin
@ApiBody({ type: UpdateScoreBootcampDto })
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -365,6 +382,8 @@ export class BootcampsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Returns bootcamp score average by id',
Expand Down
5 changes: 4 additions & 1 deletion src/controllers/files/files.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { FilesService } from 'src/services/files/files.service';
export class FilesController {
constructor(private readonly filesService: FilesService) {}

// TODO: El despliegue de este servicio debe ser privado, y adicionalmente contar con
// un mecanismo de autenticación para comunicarse con los otros servicios.
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
async uploadOne(
Expand All @@ -31,7 +33,8 @@ export class FilesController {
throw err;
}
}

// TODO: El despliegue de este servicio debe ser privado, y adicionalmente contar con
// un mecanismo de autenticación para comunicarse con los otros servicios.
@Get('/:id')
async findOne(@Res() res: Response, @Param('id', ParseUUIDPipe) id: string) {
try {
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/programs/programs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ import {
Post,
Res,
UploadedFile,
UseGuards,
UseInterceptors,
} from '@nestjs/common';

import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBody, ApiConsumes, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
import { firstValueFrom } from 'rxjs';
import { FilesClient } from 'src/clients/files/files.client';
import { Roles } from 'src/decorators/user/roles.decorator';
import { CreateOneProgramDto } from 'src/dtos/programs/createOneProgram.dto';
import { UploadContentProgramDto } from 'src/dtos/programs/uploadContentProgram.dto';
import { Role } from 'src/enum/user/role.enum';
import { RoleGuard } from 'src/guards/user/role.guard';
import { AuthGuard } from 'src/guards/user/user.guard';
import { FindAllProgramsResponse } from 'src/responses/programs/findAllPrograms.response';
import { FindManyByBootcampIdProgramsResponse } from 'src/responses/programs/findManyByBootcampIdPrograms.response';
import { FindOneByBootcampIdProgramsResponse } from 'src/responses/programs/findOneByBootcampIdPrograms.response';
Expand All @@ -33,6 +39,8 @@ export class ProgramsController {
private readonly filesClient: FilesClient,
) {}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: CreateOneProgramDto })
@ApiResponse({
status: 200,
Expand All @@ -53,6 +61,8 @@ export class ProgramsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Programs found successfully',
Expand Down Expand Up @@ -109,6 +119,8 @@ export class ProgramsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: UploadContentProgramDto })
@ApiResponse({
status: 200,
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/reviews/reviews.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import {
Param,
ParseUUIDPipe,
Post,
UseGuards,
} from '@nestjs/common';

import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Roles } from 'src/decorators/user/roles.decorator';
import { CreateOneReviewDto } from 'src/dtos/review/createOneReview.dto';
import { Role } from 'src/enum/user/role.enum';
import { RoleGuard } from 'src/guards/user/role.guard';
import { AuthGuard } from 'src/guards/user/user.guard';
import { CreateOneReviewResponse } from 'src/responses/reviews/createOneReview.response';
import { FindAllReviewsResponse } from 'src/responses/reviews/findAllReviews.response';
import { ReviewsService } from 'src/services/reviews/reviews.service';
Expand All @@ -19,6 +25,8 @@ import { ReviewsService } from 'src/services/reviews/reviews.service';
export class ReviewsController {
constructor(private readonly reviewsService: ReviewsService) {}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.User)
@ApiBody({ type: CreateOneReviewDto })
@ApiResponse({
status: 201,
Expand All @@ -36,6 +44,8 @@ export class ReviewsController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'List all reviews',
Expand All @@ -50,6 +60,8 @@ export class ReviewsController {
}
}

// TODO: El despliegue de este servicio debe ser privado, y adicionalmente contar con
// un mecanismo de autenticación para comunicarse con los otros servicios.
@ApiResponse({
status: 200,
description: 'Get score average by bootcamp id',
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class UsersController {
return await this.usersService.findAll();
}

// TODO: Se debe crear un endpoint adicional para obtener
// un usuario por id utilizando el JWT y no el parámetro en la petición.
@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Returns a user by id',
Expand All @@ -73,6 +77,8 @@ export class UsersController {
return await this.usersService.findOne(id);
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description: 'Remove an user by id',
Expand All @@ -85,6 +91,8 @@ export class UsersController {
return await this.usersService.removeOne(id);
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin, Role.User)
@ApiBody({ type: UpdateUserDto })
@ApiResponse({
status: 200,
Expand All @@ -99,6 +107,8 @@ export class UsersController {
return await this.usersService.updateOne(id, user);
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiBody({ type: CreateUserDto })
@ApiResponse({
status: 200,
Expand All @@ -114,6 +124,8 @@ export class UsersController {
}
}

@UseGuards(AuthGuard, RoleGuard)
@Roles(Role.Admin)
@ApiResponse({
status: 200,
description:
Expand Down
14 changes: 13 additions & 1 deletion src/modules/assessments/assessments.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BootcampsClient } from 'src/clients/bottcamps/bootcamps.client';
import { AssessmentsController } from 'src/controllers/assessments/assessments.controller';
import { AssessmentEntity } from 'src/models/assessment/assessment.entity';
import { AssessmentsService } from 'src/services/assessments/assessments.service';
import { EnvironmentConfigService } from 'src/services/environment-config/environment-config.service';
import { jwtConstants } from 'src/utils/jwt/constants.jwt';

@Module({
imports: [HttpModule, TypeOrmModule.forFeature([AssessmentEntity])],
imports: [
HttpModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.register({
secret: jwtConstants.secret,

signOptions: { expiresIn: '60m' },
}),
TypeOrmModule.forFeature([AssessmentEntity]),
],
controllers: [AssessmentsController],
providers: [AssessmentsService, BootcampsClient, EnvironmentConfigService],
})
Expand Down
9 changes: 9 additions & 0 deletions src/modules/bootcamps/bootcamps.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AssessmentsClient } from 'src/clients/assessments/assessments.client';
import { FilesClient } from 'src/clients/files/files.client';
Expand All @@ -18,10 +20,17 @@ import { TestimonialEntity } from 'src/models/testimonial/testimonial.entity';
import { UserEntity } from 'src/models/user/user.entity';
import { BootcampsService } from 'src/services/bootcamps/bootcamps.service';
import { EnvironmentConfigService } from 'src/services/environment-config/environment-config.service';
import { jwtConstants } from 'src/utils/jwt/constants.jwt';

@Module({
imports: [
HttpModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.register({
secret: jwtConstants.secret,

signOptions: { expiresIn: '60m' },
}),
TypeOrmModule.forFeature([
BootcampEntity,
UserEntity,
Expand Down
14 changes: 13 additions & 1 deletion src/modules/programs/programs.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { FilesClient } from 'src/clients/files/files.client';
import { ProgramsController } from 'src/controllers/programs/programs.controller';
import { ProgramEntity } from 'src/models/program/program.entity';
import { EnvironmentConfigService } from 'src/services/environment-config/environment-config.service';
import { ProgramsService } from 'src/services/programs/programs.service';
import { jwtConstants } from 'src/utils/jwt/constants.jwt';

@Module({
imports: [HttpModule, TypeOrmModule.forFeature([ProgramEntity])],
imports: [
HttpModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.register({
secret: jwtConstants.secret,

signOptions: { expiresIn: '60m' },
}),
TypeOrmModule.forFeature([ProgramEntity]),
],
controllers: [ProgramsController],
providers: [ProgramsService, FilesClient, EnvironmentConfigService],
exports: [TypeOrmModule],
Expand Down
Loading

0 comments on commit 8d0e58a

Please sign in to comment.