Creacion de entities y DTOs
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
PORT=
|
||||
JWT_SECRET=
|
||||
DB_HOST=
|
||||
DB_PORT=
|
||||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_NAME=
|
||||
@@ -1 +1,22 @@
|
||||
export class CreateStudentDto {}
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDate, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateStudentDto {
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
nombre: string;
|
||||
|
||||
@IsString()
|
||||
fecha_nacimiento: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_carrera: number;
|
||||
|
||||
@IsString()
|
||||
correo: string;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class Student {
|
||||
length: 8,
|
||||
nullable: true,
|
||||
})
|
||||
fecha_nacimiento: string | null;
|
||||
fecha_nacimiento: Date | null;
|
||||
|
||||
@Column({ name: 'correo', type: 'varchar', length: 100, nullable: true })
|
||||
correo: string | null;
|
||||
@@ -47,7 +47,11 @@ export class Student {
|
||||
@Column({ name: 'id_periodo', type: 'int', nullable: true })
|
||||
id_periodo: number | null;
|
||||
|
||||
@Column({ name: 'fecha_registro', type: 'datetime', nullable: false })
|
||||
@Column({
|
||||
name: 'fecha_registro',
|
||||
type: 'datetime',
|
||||
nullable: false,
|
||||
})
|
||||
fecha_registro: Date;
|
||||
|
||||
@Column({ name: 'id_carrera', type: 'int', nullable: false })
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { StudentService } from './student.service';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { UpdateStudentDto } from './dto/update-student.dto';
|
||||
import { Student } from './entities/student.entity';
|
||||
|
||||
@Controller('student')
|
||||
export class StudentController {
|
||||
constructor(private readonly studentService: StudentService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createStudentDto: CreateStudentDto) {
|
||||
async create(@Body() createStudentDto: CreateStudentDto): Promise<Student> {
|
||||
return this.studentService.create(createStudentDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
async findAll(): Promise<Student[]> {
|
||||
return this.studentService.findAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { StudentService } from './student.service';
|
||||
import { StudentController } from './student.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Student } from './entities/student.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Student])],
|
||||
controllers: [StudentController],
|
||||
providers: [StudentService],
|
||||
})
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { UpdateStudentDto } from './dto/update-student.dto';
|
||||
import { Student } from './entities/student.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class StudentService {
|
||||
create(createStudentDto: CreateStudentDto) {
|
||||
return 'This action adds a new student';
|
||||
constructor(
|
||||
@InjectRepository(Student)
|
||||
private readonly studentRepository: Repository<Student>,
|
||||
) {}
|
||||
|
||||
async create(createStudentDto: CreateStudentDto): Promise<Student> {
|
||||
const student = this.studentRepository.create(createStudentDto);
|
||||
return await this.studentRepository.save(student);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all student`;
|
||||
findAll(): Promise<Student[]> {
|
||||
return this.studentRepository.find({ skip: 5000, take: 50 });
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} student`;
|
||||
async findOne(id_cuenta: number): Promise<Student> {
|
||||
const student = await this.studentRepository.findOne({
|
||||
where: { id_cuenta },
|
||||
});
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Student with ID ${id_cuenta} not found`);
|
||||
}
|
||||
return student;
|
||||
}
|
||||
|
||||
update(id: number, updateStudentDto: UpdateStudentDto) {
|
||||
|
||||
+5
-3
@@ -3,17 +3,18 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { StudentModule } from './student/student.module';
|
||||
import { StudentModule } from './alumno/student.module';
|
||||
import { UserModule } from './user/user.module';
|
||||
import { User } from './user/entities/user.entity';
|
||||
import { DetalleServicioModule } from './detalle_servicio/detalle_servicio.module';
|
||||
import { PeriodoModule } from './periodo/periodo.module';
|
||||
import { ServicioModule } from './servicio/servicio.module';
|
||||
import { Student } from './alumno/entities/student.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
isGlobal: true,
|
||||
envFilePath: '.env',
|
||||
}),
|
||||
TypeOrmModule.forRootAsync({
|
||||
@@ -25,7 +26,7 @@ import { ServicioModule } from './servicio/servicio.module';
|
||||
username: configService.get<string>('DB_USER'),
|
||||
password: configService.get<string>('DB_PASSWORD'),
|
||||
database: configService.get<string>('DB_NAME'),
|
||||
entities: [User],
|
||||
entities: [User, Student],
|
||||
synchronize: false,
|
||||
}),
|
||||
}),
|
||||
@@ -33,6 +34,7 @@ import { ServicioModule } from './servicio/servicio.module';
|
||||
DetalleServicioModule,
|
||||
PeriodoModule,
|
||||
ServicioModule,
|
||||
StudentModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
Reference in New Issue
Block a user