diff --git a/package-lock.json b/package-lock.json index 114d865..b8ccc1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "class-transformer": "^0.5.1", "class-validator": "^0.14.2", "dotenv": "^17.2.3", - "firebase-admin": "^12.6.0", + "firebase-admin": "^12.7.0", "form-data": "^4.0.5", "joi": "^18.0.1", "passport": "^0.7.0", @@ -6301,7 +6301,6 @@ "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz", "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", "license": "MIT", - "peer": true, "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.0", diff --git a/package.json b/package.json index d1557c8..1ad4690 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", + "postinstall": "npm run build", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", @@ -36,6 +37,7 @@ "class-transformer": "^0.5.1", "class-validator": "^0.14.2", "dotenv": "^17.2.3", + "firebase-admin": "^12.7.0", "form-data": "^4.0.5", "joi": "^18.0.1", "passport": "^0.7.0", @@ -43,8 +45,7 @@ "reflect-metadata": "^0.2.2", "rxjs": "^7.8.1", "swagger-ui-express": "^5.0.1", - "transformer": "^1.2.8", - "firebase-admin": "^12.6.0" + "transformer": "^1.2.8" }, "devDependencies": { "@eslint/eslintrc": "^3.2.0", diff --git a/src/comunidad/comunidad.controller.ts b/src/comunidad/comunidad.controller.ts index 69b7bfc..48126d2 100644 --- a/src/comunidad/comunidad.controller.ts +++ b/src/comunidad/comunidad.controller.ts @@ -7,6 +7,10 @@ import { Body, UseGuards, Req, + Patch, + Query, + HttpCode, + HttpStatus, } from '@nestjs/common'; import { ApiTags, @@ -14,11 +18,19 @@ import { ApiResponse, ApiBearerAuth, ApiParam, + ApiQuery, } from '@nestjs/swagger'; import type { Request } from 'express'; import { ComunidadService } from './comunidad.service'; -import { JwtAuthGuard } from '../auth'; -import { CreateGroupDto, SendMessageBodyDto } from './dto'; +import { JwtAuthGuard, Roles, RolesGuard } from '../auth'; +import { Role } from '../common/dto'; +import { CreateGroupDto, + SendMessageBodyDto, + CreateReportDto, + UpdateReportStatusDto, + EstadoReporte, + TipoContenido, +} from './dto'; // Main controller with root prefix for direct routes like /forums, /chats, etc @ApiTags('Comunidad - Forums & Chats') @@ -419,4 +431,151 @@ export class ComunidadController { async getVotes(@Req() request: Request) { return this.comunidadService.getVotes(request); } + + // ============ REPORTES - Direct routes ============ + @Post('reportes') + @HttpCode(HttpStatus.CREATED) + @ApiOperation({ + summary: 'Crear un nuevo reporte de contenido', + description: + 'Permite a un usuario reportar contenido inapropiado de threads, respuestas o mensajes de chat.', + }) + @ApiResponse({ + status: 201, + description: 'El reporte fue enviado correctamente', + }) + @ApiResponse({ + status: 400, + description: 'Datos inválidos o incompletos', + }) + @ApiResponse({ + status: 404, + description: 'El contenido reportado no existe', + }) + @ApiResponse({ + status: 409, + description: 'Ya has reportado este contenido previamente', + }) + async createReport( + @Body() createReportDto: CreateReportDto, + @Req() request: Request, + ) { + return this.comunidadService.createReport(createReportDto, request); + } + + @Get('reportes') + @UseGuards(RolesGuard) + @Roles(Role.ADMIN) + @ApiOperation({ + summary: 'Obtener todos los reportes', + description: + 'Obtiene la lista de todos los reportes. Solo accesible para administradores.', + }) + @ApiQuery({ + name: 'estado', + required: false, + enum: EstadoReporte, + description: 'Filtrar reportes por estado', + }) + @ApiQuery({ + name: 'tipoContenido', + required: false, + enum: TipoContenido, + description: 'Filtrar reportes por tipo de contenido', + }) + @ApiResponse({ + status: 200, + description: 'Lista de reportes obtenida exitosamente', + }) + async getAllReports( + @Query('estado') estado?: EstadoReporte, + @Query('tipoContenido') tipoContenido?: TipoContenido, + @Req() request?: Request, + ) { + return this.comunidadService.getAllReports(estado, tipoContenido, request); + } + + @Get('reportes/estadisticas') + @UseGuards(RolesGuard) + @Roles(Role.ADMIN) + @ApiOperation({ + summary: 'Obtener estadísticas de reportes', + description: 'Obtiene estadísticas generales sobre los reportes del sistema.', + }) + @ApiResponse({ + status: 200, + description: 'Estadísticas obtenidas exitosamente', + }) + async getReportStatistics(@Req() request: Request) { + return this.comunidadService.getReportStatistics(request); + } + + @Get('reportes/mis-reportes') + @ApiOperation({ + summary: 'Obtener reportes del usuario autenticado', + description: 'Obtiene todos los reportes realizados por el usuario actual.', + }) + @ApiResponse({ + status: 200, + description: 'Lista de reportes del usuario obtenida exitosamente', + }) + async getMyReports(@Req() request: Request) { + return this.comunidadService.getMyReports(request); + } + + @Get('reportes/:id') + @UseGuards(RolesGuard) + @Roles(Role.ADMIN) + @ApiOperation({ + summary: 'Obtener un reporte específico por ID', + description: + 'Obtiene los detalles completos de un reporte incluyendo el historial de logs.', + }) + @ApiParam({ + name: 'id', + description: 'ID del reporte', + }) + @ApiResponse({ + status: 200, + description: 'Reporte obtenido exitosamente', + }) + @ApiResponse({ + status: 404, + description: 'Reporte no encontrado', + }) + async getReportById(@Param('id') id: string, @Req() request: Request) { + return this.comunidadService.getReportById(id, request); + } + + @Patch('reportes/:id/estado') + @UseGuards(RolesGuard) + @Roles(Role.ADMIN) + @ApiOperation({ + summary: 'Actualizar el estado de un reporte', + description: + 'Permite a administradores cambiar el estado de un reporte y añadir notas de moderación.', + }) + @ApiParam({ + name: 'id', + description: 'ID del reporte', + }) + @ApiResponse({ + status: 200, + description: 'Estado del reporte actualizado correctamente', + }) + @ApiResponse({ + status: 404, + description: 'Reporte no encontrado', + }) + async updateReportStatus( + @Param('id') id: string, + @Body() updateStatusDto: UpdateReportStatusDto, + @Req() request: Request, + ) { + return this.comunidadService.updateReportStatus( + id, + updateStatusDto, + request, + ); + } } diff --git a/src/comunidad/comunidad.service.ts b/src/comunidad/comunidad.service.ts index 46054fc..19bee71 100644 --- a/src/comunidad/comunidad.service.ts +++ b/src/comunidad/comunidad.service.ts @@ -529,4 +529,128 @@ export class ComunidadService { throw error; } } + + //Reportes// + /** + * Proxy para crear un nuevo reporte de contenido + */ + async createReport(createReportDto: any, request: Request) { + const config = JwtForwardingHelper.getAxiosConfig(request); + const url = `${this.comunidadServiceUrl}/reportes`; + + try { + this.logger.log(`Forwarding POST request to: ${url}`); + const response = await firstValueFrom( + this.httpService.post(url, createReportDto, config), + ); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding create report request`, error); + throw error; + } + } + + /** + * Proxy para obtener todos los reportes (solo admins) + */ + async getAllReports( + estado?: string, + tipoContenido?: string, + request?: Request, + ) { + const config = request ? JwtForwardingHelper.getAxiosConfig(request) : {}; + let url = `${this.comunidadServiceUrl}/reportes`; + + // Agregar query params si existen + const params = new URLSearchParams(); + if (estado) params.append('estado', estado); + if (tipoContenido) params.append('tipoContenido', tipoContenido); + + if (params.toString()) { + url += `?${params.toString()}`; + } + + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding get all reports request`, error); + throw error; + } + } + + /** + * Proxy para obtener estadísticas de reportes (solo admins) + */ + async getReportStatistics(request: Request) { + const config = JwtForwardingHelper.getAxiosConfig(request); + const url = `${this.comunidadServiceUrl}/reportes/estadisticas`; + + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding get statistics request`, error); + throw error; + } + } + + /** + * Proxy para obtener los reportes del usuario autenticado + */ + async getMyReports(request: Request) { + const config = JwtForwardingHelper.getAxiosConfig(request); + const url = `${this.comunidadServiceUrl}/reportes/mis-reportes`; + + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding get my reports request`, error); + throw error; + } + } + + /** + * Proxy para obtener un reporte por ID (solo admins) + */ + async getReportById(reporteId: string, request: Request) { + const config = JwtForwardingHelper.getAxiosConfig(request); + const url = `${this.comunidadServiceUrl}/reportes/${reporteId}`; + + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding get report by id request`, error); + throw error; + } + } + + /** + * Proxy para actualizar el estado de un reporte (solo admins) + */ + async updateReportStatus( + reporteId: string, + updateStatusDto: any, + request: Request, + ) { + const config = JwtForwardingHelper.getAxiosConfig(request); + const url = `${this.comunidadServiceUrl}/reportes/${reporteId}/estado`; + + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom( + this.httpService.patch(url, updateStatusDto, config), + ); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding update report status request`, error); + throw error; + } + } } diff --git a/src/comunidad/dto/create-report.dto.ts b/src/comunidad/dto/create-report.dto.ts new file mode 100644 index 0000000..fc2f4ad --- /dev/null +++ b/src/comunidad/dto/create-report.dto.ts @@ -0,0 +1,57 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsString, IsNotEmpty, IsEnum, IsOptional, MaxLength } from 'class-validator'; + +export enum TipoContenido { + THREAD = 'THREAD', + RESPONSE = 'RESPONSE', + MENSAJE_CHAT = 'MENSAJE_CHAT', +} + +export enum MotivoReporte { + SPAM = 'SPAM', + LENGUAJE_OFENSIVO = 'LENGUAJE_OFENSIVO', + ACOSO = 'ACOSO', + CONTENIDO_INAPROPIADO = 'CONTENIDO_INAPROPIADO', + INCUMPLIMIENTO_NORMAS = 'INCUMPLIMIENTO_NORMAS', + FRAUDE_ACADEMICO = 'FRAUDE_ACADEMICO', + OTRO = 'OTRO', +} + +export class CreateReportDto { + @ApiProperty({ + description: 'ID del contenido reportado (thread, response o mensaje de chat)', + example: '550e8400-e29b-41d4-a716-446655440000', + }) + @IsString() + @IsNotEmpty({ message: 'El ID del contenido es requerido' }) + contenido_id: string; + + @ApiProperty({ + description: 'Tipo de contenido a reportar', + enum: TipoContenido, + example: TipoContenido.THREAD, + }) + @IsEnum(TipoContenido, { message: 'El tipo de contenido debe ser válido' }) + @IsNotEmpty({ message: 'El tipo de contenido es requerido' }) + tipo_contenido: TipoContenido; + + @ApiProperty({ + description: 'Motivo del reporte', + enum: MotivoReporte, + example: MotivoReporte.SPAM, + }) + @IsEnum(MotivoReporte, { message: 'El motivo del reporte debe ser válido' }) + @IsNotEmpty({ message: 'El motivo del reporte es requerido' }) + motivo: MotivoReporte; + + @ApiProperty({ + description: 'Descripción adicional del reporte (opcional)', + example: 'Este contenido contiene información falsa y engañosa', + required: false, + maxLength: 500, + }) + @IsOptional() + @IsString() + @MaxLength(500, { message: 'La descripción no puede exceder los 500 caracteres' }) + descripcion?: string; +} diff --git a/src/comunidad/dto/index.ts b/src/comunidad/dto/index.ts index 61cfce6..af9d95b 100644 --- a/src/comunidad/dto/index.ts +++ b/src/comunidad/dto/index.ts @@ -1,3 +1,5 @@ export * from './create-group.dto'; -export * from './send-message.dto'; export * from './send-message-body.dto'; +export * from './send-message.dto'; +export * from './create-report.dto'; +export * from './update-report-status.dto'; diff --git a/src/comunidad/dto/update-report-status.dto.ts b/src/comunidad/dto/update-report-status.dto.ts new file mode 100644 index 0000000..190b9fe --- /dev/null +++ b/src/comunidad/dto/update-report-status.dto.ts @@ -0,0 +1,31 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsEnum, IsOptional, IsString, MaxLength } from 'class-validator'; + +export enum EstadoReporte { + PENDIENTE = 'PENDIENTE', + EN_REVISION = 'EN_REVISION', + APROBADO = 'APROBADO', + RECHAZADO = 'RECHAZADO', + RESUELTO = 'RESUELTO', +} + +export class UpdateReportStatusDto { + @ApiProperty({ + description: 'Nuevo estado del reporte', + enum: EstadoReporte, + example: EstadoReporte.EN_REVISION, + }) + @IsEnum(EstadoReporte, { message: 'El estado del reporte debe ser válido' }) + estado: EstadoReporte; + + @ApiProperty({ + description: 'Notas de moderación (opcional)', + example: 'El contenido fue revisado y se encontró que viola las normas de la comunidad', + required: false, + maxLength: 1000, + }) + @IsOptional() + @IsString() + @MaxLength(1000, { message: 'Las notas de moderación no pueden exceder los 1000 caracteres' }) + notas_moderacion?: string; +} diff --git a/src/tutorias/tutorias.service.ts b/src/tutorias/tutorias.service.ts index 6f25fe1..79ed77f 100644 --- a/src/tutorias/tutorias.service.ts +++ b/src/tutorias/tutorias.service.ts @@ -11,511 +11,511 @@ import { CreateSessionDto } from './dto'; @Injectable() export class TutoriasService { - private readonly logger = new Logger(TutoriasService.name); - private readonly tutoriasManagementServiceUrl: string; - - constructor(private readonly httpService: HttpService) { - let url = envs.tutoriasAzure - ? envs.tutoriasAzure - : `${envs.protocol}://${envs.tutoriasHost}:${envs.tutoriasPort}`; - - if (!url.startsWith('http://') && !url.startsWith('https://')) { - url = `https://${url}`; - } - - this.tutoriasManagementServiceUrl = url; - } - - - - async updateAvailabilityById(id: string, disponibilidad: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/users/id/${id}/availability`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom(this.httpService.patch(url, { disponibilidad }, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH users/id availability`, error); - throw error; - } - } - - async updateAvailabilityByEmail(email: string, disponibilidad: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/users/email/${email}/availability`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom(this.httpService.patch(url, { disponibilidad }, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH users/email availability`, error); - throw error; - } - } - - async getAvailabilityById(id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/users/disponibilidad/id/${id}'`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET users/id availability`, error); - throw error; - } - } - - async getAvailabilityByEmail(email: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/users/disponibilidad/email/${email}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET users/email availability`, error); - throw error; - } - } - - - async findTutores(req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/users/tutores`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET users/tutores`, error); - throw error; - } - } - - async create(createTutoriaDto: CreateTutoriaDto, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutores`; - try { - this.logger.log(`Forwarding POST request to: ${url}`); - const response = await firstValueFrom(this.httpService.post(url, createTutoriaDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding POST tutores`, error); - throw error; - } - } - - async getTutorsByMateria(codigo: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/tutors/by-materia/${codigo}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET tutores by-materia`, error); - throw error; - } - } - - async getTutorRatings(id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${id}/ratings`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET tutores ratings`, error); - throw error; - } - } - - async getTutorReputacion(id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${id}/reputacion`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET tutores reputacion`, error); - throw error; - } - } - - async getTutorMaterias(id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${id}/materias`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET tutores materias`, error); - throw error; - } - } - - async addMaterias(id: string, addMateriasDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/tutors/${id}/materias`; - try { - this.logger.log(`Forwarding POST request to: ${url}`); - const response = await firstValueFrom(this.httpService.post(url, addMateriasDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding POST tutores materias`, error); - throw error; - } - } - - async removeMaterias(id: string, removeMateriasDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/tutors/${id}/materias`; - try { - this.logger.log(`Forwarding DELETE request to: ${url}`); - const response = await firstValueFrom(this.httpService.delete(url, { ...config, data: removeMateriasDto })); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding DELETE tutores materias`, error); - throw error; - } - } - - async getSystemOverview(req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/stats/overview`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET overview`, error); - throw error; - } - } - - async getPopularSubjects(limit: number, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/stats/popular-subjects`; - try { - this.logger.log(`Forwarding GET request to: ${url} (limit=${limit})`); - const response = await firstValueFrom(this.httpService.get(url, { ...config, params: { limit } })); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET popular-subjects`, error); - throw error; - } - } - - async createSession(createSessionDto: CreateSessionDto, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions`; - try { - this.logger.log(`Forwarding POST request to: ${url}`); - const response = await firstValueFrom(this.httpService.post(url, createSessionDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding POST sessions`, error); - throw error; - } - } - - async findSessionById(id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/id/${id}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET sessions/id`, error); - throw error; - } - } - - async findByStudent(studentId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/student/${studentId}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET sessions/student`, error); - throw error; - } - } - - async findByTutor(tutorId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/tutor/${tutorId}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET sessions/tutor`, error); - throw error; - } - } - - async confirmSession(sessionId: string, tutorId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/confirmar`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom(this.httpService.patch(url, { tutorId }, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH sessions confirmar`, error); - throw error; - } - } - - async rejectSession(sessionId: string, tutorId: string, rejectDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/rechazar`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom(this.httpService.patch(url, rejectDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH sessions rechazar`, error); - throw error; - } - } - - async cancelSession(sessionId: string, userId: string, cancelDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/cancelar`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom(this.httpService.patch(url, cancelDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH sessions cancelar`, error); - throw error; - } - } - - async completeSession(sessionId: string, tutorId: string, completeDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/completar`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom(this.httpService.patch(url, completeDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH sessions completar`, error); - throw error; - } - } - - async createRating(createRatingDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/ratings`; - try { - this.logger.log(`Forwarding POST request to: ${url}`); - const response = await firstValueFrom(this.httpService.post(url, createRatingDto, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding POST ratings`, error); - throw error; - } - } - - async findRatingsByTutor(tutorId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/ratings/tutor/${tutorId}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET ratings/tutor`, error); - throw error; - } - } - - async findRatingsBySession(sessionId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/ratings/session/${sessionId}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET ratings/session`, error); - throw error; - } - } - - async getFullNameById(id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/users/nombre/${id}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET users/nombre`, error); - throw error; - } - } - - - async findByCodigo(codigo: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/subjects/codigo/${codigo}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET users/nombre`, error); - throw error; - } - } - - async findUpcomingSessions(userId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/upcoming/${userId}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET /api/sessions/upcoming/${userId}`, error); - throw error; - } - } - - async getUserSessionStats(userId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/sessions/stats/${userId}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET /api/sessions/stats/${userId}`, error); - throw error; - } - } - - async getPendingSessions(userId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${userId}/pending-sessions`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET /api/tutors/${userId}/pending-sessions`, error); - throw error; - } - } - - async getConfirmedSessions(userId: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${userId}/confirmed-sessions`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET /api/tutors/${userId}/confirmed-sessions`, error); - throw error; - } - } - - async findById(Id: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${Id}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET /api/tutors/${Id}`, error); - throw error; - } - } - - async createSubject(createSubjectDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/subjects`; - try { - this.logger.log(`Forwarding POST request to: ${url}`); - const response = await firstValueFrom( - this.httpService.post(url, createSubjectDto, config), - ); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding POST subjects`, error); - throw error; - } - } - - async findAllSubjects(query: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/subjects`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom( - this.httpService.get(url, { ...config, params: query }), - ); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET subjects`, error); - throw error; - } - } - - async findSubjectByCodigo(codigo: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/subjects/codigo/${codigo}`; - try { - this.logger.log(`Forwarding GET request to: ${url}`); - const response = await firstValueFrom(this.httpService.get(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding GET subjects/codigo/${codigo}`, error); - throw error; - } - } - - async updateSubject(codigo: string, updateSubjectDto: any, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/subjects/${codigo}`; - try { - this.logger.log(`Forwarding PATCH request to: ${url}`); - const response = await firstValueFrom( - this.httpService.patch(url, updateSubjectDto, config), - ); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding PATCH subjects/${codigo}`, error); - throw error; - } - } - - async removeSubject(codigo: string, req: Request) { - const config = JwtForwardingHelper.getAxiosConfig(req); - const url = `${this.tutoriasManagementServiceUrl}/api/subjects/${codigo}`; - try { - this.logger.log(`Forwarding DELETE request to: ${url}`); - const response = await firstValueFrom(this.httpService.delete(url, config)); - return response.data; - } catch (error) { - this.logger.error(`Error forwarding DELETE subjects/${codigo}`, error); - throw error; - } - } - - -} \ No newline at end of file + private readonly logger = new Logger(TutoriasService.name); + private readonly tutoriasManagementServiceUrl: string; + + constructor(private readonly httpService: HttpService) { + let url = envs.tutoriasAzure + ? envs.tutoriasAzure + : `${envs.protocol}://${envs.tutoriasHost}:${envs.tutoriasPort}`; + + if (!url.startsWith('http://') && !url.startsWith('https://')) { + url = `https://${url}`; + } + + this.tutoriasManagementServiceUrl = url; + } + + + + async updateAvailabilityById(id: string, disponibilidad: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/users/id/${id}/availability`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom(this.httpService.patch(url, { disponibilidad }, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH users/id availability`, error); + throw error; + } + } + + async updateAvailabilityByEmail(email: string, disponibilidad: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/users/email/${email}/availability`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom(this.httpService.patch(url, { disponibilidad }, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH users/email availability`, error); + throw error; + } + } + + async getAvailabilityById(id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/users/disponibilidad/id/${id}'`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET users/id availability`, error); + throw error; + } + } + + async getAvailabilityByEmail(email: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/users/disponibilidad/email/${email}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET users/email availability`, error); + throw error; + } + } + + + async findTutores(req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/users/tutores`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET users/tutors`, error); + throw error; + } + } + + async create(createTutoriaDto: CreateTutoriaDto, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors`; + try { + this.logger.log(`Forwarding POST request to: ${url}`); + const response = await firstValueFrom(this.httpService.post(url, createTutoriaDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding POST /api/tutors`, error); + throw error; + } + } + + async getTutorsByMateria(codigo: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/tutors/by-materia/${codigo}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET tutors by-materia`, error); + throw error; + } + } + + async getTutorRatings(id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${id}/ratings`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET tutors ratings`, error); + throw error; + } + } + + async getTutorReputacion(id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${id}/reputacion`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET tutors reputacion`, error); + throw error; + } + } + + async getTutorMaterias(id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${id}/materias`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET tutors materias`, error); + throw error; + } + } + + async addMaterias(id: string, addMateriasDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/tutors/${id}/materias`; + try { + this.logger.log(`Forwarding POST request to: ${url}`); + const response = await firstValueFrom(this.httpService.post(url, addMateriasDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding POST tutors materias`, error); + throw error; + } + } + + async removeMaterias(id: string, removeMateriasDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/tutors/${id}/materias`; + try { + this.logger.log(`Forwarding DELETE request to: ${url}`); + const response = await firstValueFrom(this.httpService.delete(url, { ...config, data: removeMateriasDto })); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding DELETE tutors materias`, error); + throw error; + } + } + + async getSystemOverview(req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/stats/overview`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET overview`, error); + throw error; + } + } + + async getPopularSubjects(limit: number, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/stats/popular-subjects`; + try { + this.logger.log(`Forwarding GET request to: ${url} (limit=${limit})`); + const response = await firstValueFrom(this.httpService.get(url, { ...config, params: { limit } })); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET popular-subjects`, error); + throw error; + } + } + + async createSession(createSessionDto: CreateSessionDto, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions`; + try { + this.logger.log(`Forwarding POST request to: ${url}`); + const response = await firstValueFrom(this.httpService.post(url, createSessionDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding POST sessions`, error); + throw error; + } + } + + async findSessionById(id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/id/${id}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET sessions/id`, error); + throw error; + } + } + + async findByStudent(studentId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/student/${studentId}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET sessions/student`, error); + throw error; + } + } + + async findByTutor(tutorId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/tutor/${tutorId}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET sessions/tutor`, error); + throw error; + } + } + + async confirmSession(sessionId: string, tutorId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/confirmar`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom(this.httpService.patch(url, { tutorId }, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH sessions confirmar`, error); + throw error; + } + } + + async rejectSession(sessionId: string, tutorId: string, rejectDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/rechazar`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom(this.httpService.patch(url, rejectDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH sessions rechazar`, error); + throw error; + } + } + + async cancelSession(sessionId: string, userId: string, cancelDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/cancelar`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom(this.httpService.patch(url, cancelDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH sessions cancelar`, error); + throw error; + } + } + + async completeSession(sessionId: string, tutorId: string, completeDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/${sessionId}/completar`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom(this.httpService.patch(url, completeDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH sessions completar`, error); + throw error; + } + } + + async createRating(createRatingDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/ratings`; + try { + this.logger.log(`Forwarding POST request to: ${url}`); + const response = await firstValueFrom(this.httpService.post(url, createRatingDto, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding POST ratings`, error); + throw error; + } + } + + async findRatingsByTutor(tutorId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/ratings/tutor/${tutorId}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET ratings/tutor`, error); + throw error; + } + } + + async findRatingsBySession(sessionId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/ratings/session/${sessionId}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET ratings/session`, error); + throw error; + } + } + + async getFullNameById(id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/users/nombre/${id}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET users/nombre`, error); + throw error; + } + } + + + async findByCodigo(codigo: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/subjects/codigo/${codigo}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET users/nombre`, error); + throw error; + } + } + + async findUpcomingSessions(userId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/upcoming/${userId}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET /api/sessions/upcoming/${userId}`, error); + throw error; + } + } + + async getUserSessionStats(userId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/sessions/stats/${userId}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET /api/sessions/stats/${userId}`, error); + throw error; + } + } + + async getPendingSessions(userId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${userId}/pending-sessions`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET /api/tutors/${userId}/pending-sessions`, error); + throw error; + } + } + + async getConfirmedSessions(userId: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${userId}/confirmed-sessions`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET /api/tutors/${userId}/confirmed-sessions`, error); + throw error; + } + } + + async findById(Id: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/tutors/${Id}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET /api/tutors/${Id}`, error); + throw error; + } + } + + async createSubject(createSubjectDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/subjects`; + try { + this.logger.log(`Forwarding POST request to: ${url}`); + const response = await firstValueFrom( + this.httpService.post(url, createSubjectDto, config), + ); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding POST subjects`, error); + throw error; + } + } + + async findAllSubjects(query: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/subjects`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom( + this.httpService.get(url, { ...config, params: query }), + ); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET subjects`, error); + throw error; + } + } + + async findSubjectByCodigo(codigo: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/subjects/codigo/${codigo}`; + try { + this.logger.log(`Forwarding GET request to: ${url}`); + const response = await firstValueFrom(this.httpService.get(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding GET subjects/codigo/${codigo}`, error); + throw error; + } + } + + async updateSubject(codigo: string, updateSubjectDto: any, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/subjects/${codigo}`; + try { + this.logger.log(`Forwarding PATCH request to: ${url}`); + const response = await firstValueFrom( + this.httpService.patch(url, updateSubjectDto, config), + ); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding PATCH subjects/${codigo}`, error); + throw error; + } + } + + async removeSubject(codigo: string, req: Request) { + const config = JwtForwardingHelper.getAxiosConfig(req); + const url = `${this.tutoriasManagementServiceUrl}/api/subjects/${codigo}`; + try { + this.logger.log(`Forwarding DELETE request to: ${url}`); + const response = await firstValueFrom(this.httpService.delete(url, config)); + return response.data; + } catch (error) { + this.logger.error(`Error forwarding DELETE subjects/${codigo}`, error); + throw error; + } + } + + +}