-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from No-Country-simulation/orlando
Orlando
- Loading branch information
Showing
40 changed files
with
853 additions
and
340 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { Schema, Document } from 'mongoose'; | ||
// import { Schema, Document } from 'mongoose'; | ||
|
||
|
||
export const CourseSchema = new Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
createAt:{type: Date, required: true,default:Date.now()}, | ||
updateAt:{type: Date, required: true,default:Date.now()}, | ||
userId:{type: String, required:true}, | ||
price:{type:Number}, | ||
plataforma:{type:String}, | ||
reputacion:{type:String}, | ||
fotoCurso:{type:String}, | ||
tags:{type:String} | ||
}); | ||
// export const CourseSchema = new Schema({ | ||
// name: { type: String, required: true }, | ||
// description: { type: String, required: true }, | ||
// createAt:{type: Date, required: true,default:Date.now()}, | ||
// updateAt:{type: Date, required: true,default:Date.now()}, | ||
// userId:{type: String, required:true}, | ||
// price:{type:Number}, | ||
// plataforma:{type:String}, | ||
// reputacion:{type:String}, | ||
// fotoCurso:{type:String}, | ||
// tags:{type:String} | ||
// }); | ||
|
||
export interface Course extends Document { | ||
id: string; | ||
name: string; | ||
description: string; | ||
userId:string; | ||
price:number; | ||
plataforma:string; | ||
reputacion:string; | ||
fotoCurso:string; | ||
tags:string; | ||
} | ||
// export interface Course extends Document { | ||
// id: string; | ||
// name: string; | ||
// description: string; | ||
// userId:string; | ||
// price:number; | ||
// plataforma:string; | ||
// reputacion:string; | ||
// fotoCurso:string; | ||
// tags:string; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
import { Controller, Post, Body,Get, Param } from '@nestjs/common'; | ||
import { Controller } from '@nestjs/common'; | ||
import { CoursesService } from './courses.service'; | ||
import { CreateCourseDto } from './dto/create-course.dto'; // Importa el DTO | ||
import { MessagePattern, RpcException } from '@nestjs/microservices'; | ||
import { CreateCourseSchema } from './dto/create-course.dto'; | ||
|
||
@Controller('courses') | ||
export class CoursesController { | ||
constructor(private readonly coursesService: CoursesService) {} | ||
|
||
@MessagePattern({ cmd: 'createCourse' }) | ||
async createCourse(courseData: any) { | ||
// Validar los datos con Zod | ||
const validationResult = CreateCourseSchema.safeParse(courseData); | ||
if (!validationResult.success) { | ||
throw new RpcException({ | ||
statusCode: 400, | ||
message: 'Validation error', | ||
errors: validationResult.error.errors, | ||
}); | ||
} | ||
|
||
@Get('/') | ||
async getCourse(){ | ||
return await this.coursesService.getCourse(); | ||
// Llamar al servicio para guardar el curso | ||
return this.coursesService.createCourse(validationResult.data); | ||
} | ||
|
||
@Get('/:id') | ||
async getCourseId(@Param('id') id:string) { | ||
return await this.coursesService.getCourseId(id); | ||
} | ||
// @Get('/') | ||
// async getCourse(){ | ||
// return await this.coursesService.getCourse(); | ||
// } | ||
|
||
@Post() | ||
async create(@Body() createCourseDto: CreateCourseDto){ | ||
return await this.coursesService.create(createCourseDto); | ||
} | ||
// @Get('/:id') | ||
// async getCourseId(@Param('id') id:string) { | ||
// return await this.coursesService.getCourseId(id); | ||
// } | ||
|
||
// @Post() | ||
// async create(@Body() createCourseDto: CreateCourseDto){ | ||
// return await this.coursesService.create(createCourseDto); | ||
// } | ||
|
||
// Otros métodos del controlador (por ejemplo, para obtener cursos, eliminar, etc.) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
import { Course } from './course.shema'; | ||
import { CreateCourseDto } from './dto/create-course.dto'; | ||
import { Course } from './schemas/course.schema'; | ||
|
||
@Injectable() | ||
export class CoursesService { | ||
constructor( | ||
@InjectModel('Course') private readonly courseModel: Model<Course>, // Inyecta el modelo Course | ||
) {} | ||
constructor(@InjectModel(Course.name) private courseModel: Model<Course>) {} | ||
|
||
async getCourse(){ | ||
return this.courseModel.find(); | ||
} | ||
async getCourseId(id){ | ||
return await this.courseModel.findById(id); | ||
async createCourse(data: any) { | ||
const newCourse = new this.courseModel(data); | ||
return newCourse.save(); | ||
} | ||
} | ||
//constructor(@InjectModel(Course.name) private courseModel: Model<Course>) { } | ||
|
||
// Método para crear un curso | ||
async create(createCourseDto: CreateCourseDto): Promise<Course> { | ||
const course = new this.courseModel(createCourseDto); // Usa el DTO para crear el curso | ||
return course.save(); // Guarda el curso en la base de datos | ||
} | ||
// async createCourse(data: { title: string; description?: string }) { | ||
// const newCourse = new this.courseModel(data); | ||
// return newCourse.save(); | ||
// } | ||
|
||
// async getAllCourses() { | ||
// return this.courseModel.find().exec(); | ||
// } | ||
|
||
// async getCourse(){ | ||
// return this.courseModel.find(); | ||
// } | ||
// async getCourseId(id){ | ||
// return await this.courseModel.findById(id); | ||
// } | ||
|
||
// Otros métodos de servicio (por ejemplo, para listar cursos, eliminar, etc.) | ||
} | ||
// // Método para crear un curso | ||
// async create(createCourseDto: CreateCourseDto): Promise<Course> { | ||
// const course = new this.courseModel(createCourseDto); // Usa el DTO para crear el curso | ||
// return course.save(); // Guarda el curso en la base de datos | ||
// } |
Oops, something went wrong.