Skip to content

Commit

Permalink
Merge branch 'feature/update'
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlandoc0107 committed Dec 16, 2024
2 parents 91f6c7c + 510c63a commit 986183c
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 240 deletions.
2 changes: 1 addition & 1 deletion server/apps/courses/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ARG MONGO_URI

# Variables de entorno
ENV NODE_ENV=production
ENV COURSES_MICROSERVICE_HOST=0.0.0.0
ENV COURSES_MICROSERVICE_HOST=courses
ENV COURSES_MICROSERVICE_PORT=3002
ENV JWT_SECRET=$JWT_SECRET
ENV MONGO_URI=$MONGO_URI
Expand Down
4 changes: 3 additions & 1 deletion server/apps/courses/src/config/envs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from '@nestjs/common';
import * as dotenv from 'dotenv';
import {env} from 'process';
dotenv.config();
Expand All @@ -10,4 +11,5 @@ export class ConfigEnvs {
static COURSES_MICROSERVICE_PORT = process.env.COURSES_MICROSERVICE_PORT;
}

console.log('Variables de entorno microservicio courses', env);
console.log('Variables de entorno microservicio courses', env);
Logger.log('Variables de entorno microservicio courses', env);
28 changes: 28 additions & 0 deletions server/apps/courses/src/courses/courses.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ export class CoursesController {
};
}
}
@Get('filter')
async filterCourses(
@Body() data: {
page: number;
limit: number;
filters: Record<string, any> },
) {
Logger.log('Datos recibidos para filtrar cursos:', data);
const { page, limit, filters } = data;

try {
const courses = await this.coursesService.filterCourses(filters, page, limit);
return {
statusCode: 200,
success: courses.success,
message: courses.message,
data: courses.courses,
};
} catch (error) {
Logger.error('Error al filtrar los cursos:', error.message);
return {
statusCode: 500,
success: false,
message: 'Error al filtrar los cursos',
error: error.message,
};
}
}
}

// // Buscar curso por filtro
Expand Down
127 changes: 82 additions & 45 deletions server/apps/courses/src/courses/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CreateCourseDto } from './dto/create.course.dto';
import { Users } from './schemas/users.schema';
import { JwtService } from '@nestjs/jwt';
import { Modules, ModulesSchema } from './schemas/module.schema';
import { FilterCoursesSuccess } from 'src/types/responseTypes';


@Injectable()
Expand Down Expand Up @@ -42,7 +43,7 @@ export class CoursesService {
return existingUser;
}

async createCourse(data:CreateCourseDto) {
async createCourse(data: CreateCourseDto) {
try {
const decodedToken = this.jwtService.verify(data.token);
const userId = decodedToken.userId;
Expand Down Expand Up @@ -92,56 +93,93 @@ export class CoursesService {
}
}


// filtro
// async filterCourses(filters: Record<string, any>, page: number, limit: number) {
// const query = this.buildQuery(filters); // Supongamos que tienes una función para construir el filtro
// return this.courseModel.find(query)
// .skip((page - 1) * limit) // Implementación simple de paginación
// private cleanFilters(filters: Record<string, any>): Record<string, any> {
// const cleaned = {};
// for (const key in filters) {
// if (filters[key] !== undefined && filters[key] !== null && filters[key] !== '') {
// cleaned[key] = filters[key];
// }
// }
// return cleaned;
// }
// // funcion principal del filtro depende de otras funciones
// async filterCourses(
// filters: Record<string, any>,
// page: number,
// limit: number):
// Promise<FilterCoursesSuccess> {
// const cleanFilters = this.cleanFilters(filters);
// const query = this.buildQuery(cleanFilters);
// const courses = await this.courseModel
// .find(query)
// .skip((page - 1) * limit)
// .limit(limit)
// .exec();
// const total = await this.courseModel.countDocuments(query);
// Logger.log('Courses Found', courses);
// if (!courses || courses.length === 0) {
// throw new Error('No courses found with the provided filters');
// }
// const mappedCourses: Course[] = courses.map(course => ({
// id: course._id.toString(), // Convierte ObjectId a string
// userId: course.userId,
// title: course.title,
// contentType: course.contentType,
// kind: course.kind,
// basicDescription: course.basicDescription || '',
// platform: course.platform,
// idiom: course.idiom,
// reviews: course.reviews,
// rating: course.rating,
// pilar: course.pilar || '',
// funcionalidad: course.funcionalidad || '', // Ajuste del nombre correcto
// sector: course.sector || '',
// tool: course.tool || '',
// purpose: course.purpose || '',
// prerequisites: course.prerequisites || [],
// followUp: course.followUp || [],
// contents: course.contents || [],
// detailedContent: course.detailedContent || '',
// imageUrl: course.imageUrl || '',
// status: course.status,
// enrolledUsers: course.enrolledUsers || [],
// createdAt: course.createdAt,
// updatedAt: course.updatedAt,
// modules: course.modules || [],
// __v: course.__v || 0,
// }));

// return {
// success: true,
// message: 'Courses fetched successfully',
// courses: mappedCourses,
// pagination: {
// page,
// limit,
// total,
// },
// };
// }

// private buildQuery(filters: Record<string, any>) {
// let query = {};

// // Puedes construir una lógica más compleja dependiendo de los filtros
// if (filters.status) {
// query['status'] = filters.status;
// }

// if (filters.contentType) {
// query['contentType'] = filters.contentType;
// }

// if (filters.kind) {
// query['kind'] = filters.kind;
// }
// if (filters.level) {
// query['level'] = filters.level
// }
// if (filters.platafor) {
// query['platafor'] = filters.platafor
// }
// if (filters.idiom) {
// query['idiom'] = filters.idiom
// }
// if (filters.pilar) {
// query['pilar'] = filters.pilar
// }
// if (filters.funtionalidad) {
// query['funtionalidad'] = filters.funtionalidad
// }
// if (filters.sector) {
// query['sector'] = filters.sector
// }
// if (filters.tool) {
// query['tool'] = filters.tool
// }

// // Aquí puedes agregar más filtros según las propiedades del curso
// Logger.log("query", query)
// const query: Record<string, any> = {};

// if (filters.status) query['status'] = filters.status;
// if (filters.contentType) query['contentType'] = filters.contentType;
// if (filters.kind) query['kind'] = filters.kind;
// if (filters.level) query['level'] = filters.level;
// if (filters.platform) query['platform'] = filters.platform; // Ajuste en el nombre
// if (filters.idiom) query['idiom'] = filters.idiom;
// if (filters.pilar) query['pilar'] = filters.pilar;
// if (filters.funcionalidad) query['funcionalidad'] = filters.funcionalidad; // Ajuste en el nombre
// if (filters.sector) query['sector'] = filters.sector;
// if (filters.tool) query['tool'] = filters.tool;

// Logger.log('Query:', query);
// return query;
// }
}

// // buscar curse por id
// async findById(id: string): Promise<Course | null> {
Expand Down Expand Up @@ -311,4 +349,3 @@ export class CoursesService {
// return { message: 'Error al agregar la lección', error: error.message };
// }
// }
}
39 changes: 39 additions & 0 deletions server/apps/courses/src/types/responseTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export interface FilterCoursesSuccess {
success: boolean;
message: string;
courses: Course[];
pagination: {
page: number;
limit: number;
total: number;
};
}

export interface Course {
id: string;
userId: string;
title: string;
contentType: 'premium' | 'free'; // Literal restringido
kind: 'course' | 'lesson';
basicDescription?: string; // Opcional
platform: string;
idiom: string;
reviews: string;
rating: string;
pilar?: string; // Opcional
funcionalidad?: string; // Opcional
sector?: string; // Opcional
tool?: string; // Opcional
purpose?: string; // Opcional
prerequisites?: string[]; // Opcional
followUp?: string[]; // Opcional
contents?: string[]; // Opcional
detailedContent?: string; // Opcional
imageUrl?: string; // Opcional
status: 'in-progress' | 'published' | 'draft';
enrolledUsers: string[];
createdAt: string;
updatedAt: string;
modules: any[]; // Cambia esto si tienes una interfaz específica para módulos
__v?: number; // Opcional
}
24 changes: 15 additions & 9 deletions server/apps/gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ FROM base AS production
WORKDIR /app

# Declaración de los ARGs (se pasarán desde GitHub Actions)
ARG USERS_MICROSERVICE_HOST
ARG COURSES_MICROSERVICE_HOST
ARG UPLOAD_MICROSERVICE_HOST
ARG USERS_MICROSERVICE_URL
ARG COURSES_MICROSERVICE_URL
ARG UPLOAD_MICROSERVICE_URL
#ARG USERS_MICROSERVICE_HOST
#ARG COURSES_MICROSERVICE_HOST
#ARG UPLOAD_MICROSERVICE_HOST
ARG JWT_SECRET

# Variables de entorno
ENV NODE_ENV=production
ENV PORT=3000
ENV USERS_MICROSERVICE_HOST=$USERS_MICROSERVICE_HOST
ENV USERS_MICROSERVICE_PORT=4441
ENV COURSES_MICROSERVICE_HOST=$COURSES_MICROSERVICE_HOST
ENV COURSES_MICROSERVICE_PORT=3002
ENV UPLOAD_MICROSERVICE_HOST=$UPLOAD_MICROSERVICE_HOST
ENV UPLOAD_SERVICE_PORT=3003
ENV USERS_MICROSERVICE_URL=$USERS_MICROSERVICE_URL
ENV COURSES_MICROSERVICE_URL=$COURSES_MICROSERVICE_URL
ENV UPLOAD_MICROSERVICE_URL=$UPLOAD_MICROSERVICE_URL
#ENV USERS_MICROSERVICE_HOST=$USERS_MICROSERVICE_HOST
#ENV USERS_MICROSERVICE_PORT=4441
#ENV COURSES_MICROSERVICE_HOST=$COURSES_MICROSERVICE_HOST
#ENV COURSES_MICROSERVICE_PORT=3002
#ENV UPLOAD_MICROSERVICE_HOST=$UPLOAD_MICROSERVICE_HOST
#ENV UPLOAD_SERVICE_PORT=3003
ENV JWT_SECRET=$JWT_SECRET
ENV FRONTEND_URL=https://klowhub-824410275969.southamerica-east1.run.app

Expand Down
3 changes: 2 additions & 1 deletion server/apps/gateway/src/config/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export class ConfigEnvs {
static FRONTEND_URL = process.env.FRONTEND_URL;
}

Logger.log('Variables de entorno GateWay:', env);
Logger.log('Variables de entorno GateWay:', env);
console.log('Variables de entorno GateWay:', env);
Loading

0 comments on commit 986183c

Please sign in to comment.