added alumno_inscrito and others Ep
This commit is contained in:
@@ -20,6 +20,4 @@ export class CreateStudentDto {
|
||||
@IsEmail()
|
||||
@IsString()
|
||||
correo: string;
|
||||
}
|
||||
|
||||
//Hubo pedos con la base , revisar
|
||||
}
|
||||
@@ -84,9 +84,6 @@ export class Alumno {
|
||||
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
|
||||
generacion: number | null;
|
||||
|
||||
@OneToMany(() => DetalleServicio, (detalle) => detalle.alum)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
@@ -94,6 +91,9 @@ export class Alumno {
|
||||
@JoinColumn({ name: 'id_carrera' })
|
||||
carrera: Carrera;
|
||||
|
||||
@OneToMany(() => DetalleServicio, (detalle) => detalle.alum)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
|
||||
sanciones: AlumnoSancion[];
|
||||
|
||||
|
||||
@@ -21,5 +21,10 @@ export class AlumnoController {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Post('/create')
|
||||
async newStudent(@Body() createStudentDto: CreateStudentDto) {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -2,10 +2,10 @@ import { Module } from '@nestjs/common';
|
||||
import { AlumnoService } from './student.service';
|
||||
import { AlumnoController } from './student.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { Alumno, Carrera } from './entities/student.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Alumno])],
|
||||
imports: [TypeOrmModule.forFeature([Alumno,Carrera])],
|
||||
controllers: [AlumnoController],
|
||||
providers: [AlumnoService],
|
||||
exports:[AlumnoService]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { Alumno, Carrera } from './entities/student.entity';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@@ -9,11 +9,21 @@ export class AlumnoService {
|
||||
constructor(
|
||||
@InjectRepository(Alumno)
|
||||
private readonly studentRepository: Repository<Alumno>,
|
||||
) {}
|
||||
@InjectRepository(Carrera)
|
||||
private readonly carreraRepository: Repository<Carrera>,
|
||||
) { }
|
||||
|
||||
async create(createStudentDto: CreateStudentDto): Promise<Alumno> {
|
||||
//Hubo pedos con la base , revisar
|
||||
const student = this.studentRepository.create(createStudentDto);
|
||||
async create(data: CreateStudentDto): Promise<Alumno> {
|
||||
const { id_carrera, ...rest } = data;
|
||||
const carrera = await this.carreraRepository.findOne({
|
||||
where: { id_carrera: data.id_carrera },
|
||||
});
|
||||
if (!carrera) {
|
||||
throw new NotFoundException(`Carrera not found`);
|
||||
}
|
||||
const createStudent = { ...rest, carrera ,fecha_registro: new Date()};
|
||||
|
||||
const student = this.studentRepository.create(createStudent);
|
||||
return await this.studentRepository.save(student);
|
||||
}
|
||||
|
||||
@@ -24,6 +34,7 @@ export class AlumnoService {
|
||||
async findOne(id_cuenta: number): Promise<Alumno> {
|
||||
const student = await this.studentRepository.findOne({
|
||||
where: { id_cuenta },
|
||||
select: {id_cuenta:true,nombre:true,credito:true},
|
||||
});
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Student not found`);
|
||||
@@ -50,7 +61,7 @@ export class AlumnoService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async addCredit(
|
||||
async addCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { CreateAlumnoInscritoDto } from './dto/create-alumno_inscrito.dto';
|
||||
import { UpdateAlumnoInscritoDto } from './dto/update-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
|
||||
@Controller('alumno-inscrito')
|
||||
export class AlumnoInscritoController {
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) {}
|
||||
|
||||
@Post()
|
||||
async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
return this.alumnoInscritoService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id_cuenta')
|
||||
async findByAlumno(@Param('id_cuenta') id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findByAlumno(id_cuenta);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { AlumnoInscritoController } from './alumno_inscrito.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito])],
|
||||
controllers: [AlumnoInscritoController],
|
||||
providers: [AlumnoInscritoService],
|
||||
})
|
||||
export class AlumnoInscritoModule {}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { CreateAlumnoInscritoDto } from './dto/create-alumno_inscrito.dto';
|
||||
import { UpdateAlumnoInscritoDto } from './dto/update-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoInscritoService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoInscrito)
|
||||
private readonly alumnoInscritoRepo: Repository<AlumnoInscrito>,
|
||||
) {}
|
||||
|
||||
async create(dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
const existing = await this.alumnoInscritoRepo.findOne({
|
||||
where: {
|
||||
alumno: { id_cuenta: dto.id_cuenta },
|
||||
periodo: { id_periodo: dto.id_periodo },
|
||||
},
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya está inscrito en este periodo y plataforma',
|
||||
);
|
||||
}
|
||||
|
||||
const alumnoInscrito = this.alumnoInscritoRepo.create(dto);
|
||||
return this.alumnoInscritoRepo.save(alumnoInscrito);
|
||||
}
|
||||
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoRepo.find({
|
||||
relations: ['alumno', 'periodo', 'plataforma'],
|
||||
});
|
||||
}
|
||||
|
||||
async findByAlumno(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoRepo.find({
|
||||
where: { alumno: { id_cuenta } },
|
||||
relations: ['alumno', 'periodo', 'plataforma'],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { IsNotEmpty, IsNumber, IsBoolean } from 'class-validator';
|
||||
|
||||
export class CreateAlumnoInscritoDto {
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_periodo: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_plataforma: number;
|
||||
|
||||
@IsBoolean()
|
||||
realizo_pago?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
platica?: boolean;
|
||||
|
||||
@IsNumber()
|
||||
tiempo_disponible?: number;
|
||||
|
||||
@IsBoolean()
|
||||
ad?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateAlumnoInscritoDto } from './create-alumno_inscrito.dto';
|
||||
|
||||
export class UpdateAlumnoInscritoDto extends PartialType(CreateAlumnoInscritoDto) {}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Periodo } from 'src/periodo/entities/periodo.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'plataforma' })
|
||||
export class Plataforma {
|
||||
@PrimaryGeneratedColumn({ name: 'id_plataforma' })
|
||||
id_plataforma: number;
|
||||
|
||||
@Column({ name: 'plataforma', type: 'varchar', length: 45 })
|
||||
nombre: string;
|
||||
|
||||
@OneToMany(() => AlumnoInscrito, (alumnoInscrito) => alumnoInscrito.plataforma)
|
||||
alumnos_inscritos: AlumnoInscrito[];
|
||||
}
|
||||
|
||||
@Entity({ name: 'alumno_inscrito' })
|
||||
export class AlumnoInscrito {
|
||||
@PrimaryGeneratedColumn({ name: 'id_alumno_inscrito' })
|
||||
id_alumno_inscrito: number;
|
||||
|
||||
@Column({ name: 'fecha_inscripcion', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
|
||||
fecha_inscripcion: Date;
|
||||
|
||||
@Column({ name: 'tiempo_disponible', type: 'int', default: 3600 })
|
||||
tiempo_disponible: number;
|
||||
|
||||
@Column({ name: 'realizo_pago', type: 'tinyint', width: 1, default: 0 })
|
||||
realizo_pago: boolean;
|
||||
|
||||
@Column({ name: 'platica', type: 'bit', width: 1, default: () => "b'0'" })
|
||||
platica: boolean;
|
||||
|
||||
@ManyToOne(() => Alumno)
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
alumno: Alumno;
|
||||
|
||||
@ManyToOne(() => Periodo)
|
||||
@JoinColumn({ name: 'id_periodo' })
|
||||
periodo: Periodo;
|
||||
|
||||
@ManyToOne(() => Plataforma)
|
||||
@JoinColumn({ name: 'id_plataforma' })
|
||||
plataforma: Plataforma;
|
||||
|
||||
@Column({ name: 'ad', type: 'bit', width: 1, nullable: true, default: () => "b'0'" })
|
||||
ad?: boolean;
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import { Recibo } from './recibo/entities/recibo.entity';
|
||||
import { ReciboModule } from './recibo/recibo.module';
|
||||
import { MesaModule } from './mesa/mesa.module';
|
||||
import { Mesa } from './mesa/entities/mesa.entity';
|
||||
import { AlumnoInscritoModule } from './alumno_inscrito/alumno_inscrito.module';
|
||||
import { AlumnoInscrito, Plataforma } from './alumno_inscrito/entities/alumno_inscrito.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -50,6 +52,8 @@ import { Mesa } from './mesa/entities/mesa.entity';
|
||||
Carrera,
|
||||
Recibo,
|
||||
Mesa,
|
||||
AlumnoInscrito,
|
||||
Plataforma,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -64,6 +68,7 @@ import { Mesa } from './mesa/entities/mesa.entity';
|
||||
OperationsModule,
|
||||
ReciboModule,
|
||||
MesaModule,
|
||||
AlumnoInscritoModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
+1
-4
@@ -14,10 +14,7 @@ export class AppService {
|
||||
propiedad intelectual.
|
||||
</p>
|
||||
<h4>
|
||||
Encargado de la parte de programacion Lino
|
||||
</h4>
|
||||
<h4>
|
||||
Programadores: Carlos, Axel
|
||||
Programadores:Lino Carlos, Axel
|
||||
</h4>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -7,3 +7,12 @@ export class CreateUserDto {
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
export class changePasswordDto {
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@IsString()
|
||||
newPassword: string;
|
||||
}
|
||||
@@ -6,15 +6,17 @@ import {
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto } from './dto/create-user.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
constructor(private readonly userService: UserService) { }
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
@@ -23,8 +25,16 @@ export class UserController {
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('/validate-token')
|
||||
getProfile(@Request() req) {
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/change-password')
|
||||
async changePassword(@Body() data: changePasswordDto, @Req() req) {
|
||||
const id_usuario = req.user.id;
|
||||
await this.userService.changePassword(data, id_usuario);
|
||||
return { message: 'Contraseña actualizada correctamente' };
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto } from './dto/create-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -12,7 +12,7 @@ export class UserService {
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
const { usuario, password } = data;
|
||||
@@ -56,5 +56,16 @@ export class UserService {
|
||||
}
|
||||
return student;
|
||||
}
|
||||
|
||||
async changePassword(data: changePasswordDto, id_usuario: number) {
|
||||
|
||||
const user = await this.findOneByNameandPassword({
|
||||
usuario: (await this.findOne(id_usuario)).usuario,
|
||||
password: data.password,
|
||||
});
|
||||
|
||||
user.password = data.newPassword;
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user