Merge branch 'Lino' into Dev
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[];
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ export class AlumnoController {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<Alumno[]> {
|
||||
return this.alumnoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Post('/create')
|
||||
async newStudent(@Body() createStudentDto: CreateStudentDto) {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//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,25 +9,34 @@ 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);
|
||||
return await this.studentRepository.save(student);
|
||||
}
|
||||
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() };
|
||||
|
||||
findAll(): Promise<Alumno[]> {
|
||||
return this.studentRepository.find({ skip: 5000, take: 50 });
|
||||
const student = this.studentRepository.create(createStudent);
|
||||
return await this.studentRepository.save(student);
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
@@ -50,11 +59,7 @@ export class AlumnoService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async addCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
) {
|
||||
async addCredit(id_cuenta: number, credit: number, manager: EntityManager) {
|
||||
const repo = manager.getRepository(Alumno);
|
||||
return await repo
|
||||
.createQueryBuilder()
|
||||
@@ -64,4 +69,4 @@ export class AlumnoService {
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -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,9 @@ 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';
|
||||
import { EquipoModule } from './equipo/equipo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -50,6 +53,8 @@ import { Mesa } from './mesa/entities/mesa.entity';
|
||||
Carrera,
|
||||
Recibo,
|
||||
Mesa,
|
||||
AlumnoInscrito,
|
||||
Plataforma,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -64,6 +69,8 @@ import { Mesa } from './mesa/entities/mesa.entity';
|
||||
OperationsModule,
|
||||
ReciboModule,
|
||||
MesaModule,
|
||||
AlumnoInscritoModule,
|
||||
EquipoModule,
|
||||
],
|
||||
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>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateEquipoDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateEquipoDto } from './create-equipo.dto';
|
||||
|
||||
export class UpdateEquipoDto extends PartialType(CreateEquipoDto) {}
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
Unique,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity({ name: 'plataforma' })
|
||||
export class Plataforma {
|
||||
@PrimaryGeneratedColumn({ name: 'id_plataforma', type: 'int' })
|
||||
id_plataforma: number;
|
||||
|
||||
@Column({ name: 'plataforma', type: 'varchar', length: 45 })
|
||||
plataforma: string;
|
||||
|
||||
// Relación con equipos
|
||||
@OneToMany(() => Equipo, (equipo) => equipo.plataforma)
|
||||
equipos: Equipo[];
|
||||
}
|
||||
|
||||
@Entity({ name: 'area_ubicacion' })
|
||||
export class AreaUbicacion {
|
||||
@PrimaryGeneratedColumn({ name: 'id_area_ubicacion', type: 'int' })
|
||||
id_area_ubicacion: number;
|
||||
|
||||
@Column({ name: 'area', type: 'varchar', length: 45 })
|
||||
area: string;
|
||||
|
||||
@Column({ name: 'extra', type: 'char', length: 1, default: '0' })
|
||||
extra: string;
|
||||
|
||||
// Relación con equipos
|
||||
@OneToMany(() => Equipo, (equipo) => equipo.areaUbicacion)
|
||||
equipos: Equipo[];
|
||||
}
|
||||
|
||||
@Entity({ name: 'equipo' })
|
||||
@Unique('indice_unico_ubicacion', ['ubicacion'])
|
||||
export class Equipo {
|
||||
@PrimaryGeneratedColumn({ name: 'id_equipo', type: 'int' })
|
||||
id_equipo: number;
|
||||
|
||||
@Column({ name: 'id_plataforma', type: 'int' })
|
||||
id_plataforma: number;
|
||||
|
||||
@Column({ name: 'id_area_ubicacion', type: 'int' })
|
||||
id_area_ubicacion: number;
|
||||
|
||||
@Column({ name: 'nombre_equipo', type: 'varchar', length: 45 })
|
||||
nombre_equipo: string;
|
||||
|
||||
@Column({ name: 'ubicacion', type: 'varchar', length: 25 })
|
||||
ubicacion: string;
|
||||
|
||||
@Column({ name: 'activo', type: 'bit', default: () => "b'1'" })
|
||||
activo: boolean;
|
||||
|
||||
@Column({
|
||||
name: 'ip',
|
||||
type: 'varchar',
|
||||
length: 15,
|
||||
default: () => "'no service'",
|
||||
})
|
||||
ip: string;
|
||||
|
||||
@ManyToOne(() => Plataforma, (plataforma) => plataforma.equipos, {
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'id_plataforma' })
|
||||
plataforma: Plataforma;
|
||||
|
||||
@ManyToOne(() => AreaUbicacion, (area) => area.equipos, {
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'id_area_ubicacion' })
|
||||
areaUbicacion: AreaUbicacion;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||
|
||||
@Controller('equipo')
|
||||
export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createEquipoDto: CreateEquipoDto) {
|
||||
return this.equipoService.create(createEquipoDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.equipoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.equipoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateEquipoDto: UpdateEquipoDto) {
|
||||
return this.equipoService.update(+id, updateEquipoDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.equipoService.remove(+id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { EquipoController } from './equipo.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [EquipoController],
|
||||
providers: [EquipoService],
|
||||
})
|
||||
export class EquipoModule {}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class EquipoService {
|
||||
create(createEquipoDto: CreateEquipoDto) {
|
||||
return 'This action adds a new equipo';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all equipo`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} equipo`;
|
||||
}
|
||||
|
||||
update(id: number, updateEquipoDto: UpdateEquipoDto) {
|
||||
return `This action updates a #${id} equipo`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} equipo`;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,11 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { SancionService } from './sancion.service';
|
||||
import { CreateSancionDto } from './dto/create-sancion.dto';
|
||||
import { UpdateSancionDto } from './dto/update-sancion.dto';
|
||||
|
||||
@Controller('sancion')
|
||||
export class SancionController {
|
||||
constructor(private readonly sancionService: SancionService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createSancionDto: CreateSancionDto) {
|
||||
return this.sancionService.create(createSancionDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.sancionService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.sancionService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateSancionDto: UpdateSancionDto) {
|
||||
return this.sancionService.update(+id, updateSancionDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.sancionService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateSancionDto } from './dto/create-sancion.dto';
|
||||
import { UpdateSancionDto } from './dto/update-sancion.dto';
|
||||
import { Sancion } from './entities/sancion.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -9,15 +7,8 @@ import { Repository } from 'typeorm';
|
||||
export class SancionService {
|
||||
constructor(
|
||||
@InjectRepository(Sancion)
|
||||
private readonly sancionRepository: Repository<Sancion>
|
||||
){}
|
||||
create(createSancionDto: CreateSancionDto) {
|
||||
return 'This action adds a new sancion';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all sancion`;
|
||||
}
|
||||
private readonly sancionRepository: Repository<Sancion>,
|
||||
) {}
|
||||
|
||||
async findOne(id_sancion: number): Promise<Sancion> {
|
||||
const sancion = await this.sancionRepository.findOne({
|
||||
@@ -28,13 +19,5 @@ export class SancionService {
|
||||
}
|
||||
return sancion;
|
||||
}
|
||||
|
||||
update(id: number, updateSancionDto: UpdateSancionDto) {
|
||||
return `This action updates a #${id} sancion`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} sancion`;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -1,9 +1,65 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreateUserDto {
|
||||
export class Login {
|
||||
@IsString()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
export class CreateUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nombre: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
apellido_paterno: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
apellido_materno?: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MinLength(6)
|
||||
@MaxLength(45)
|
||||
password: string;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
activo?: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@MaxLength(50)
|
||||
descripcion?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
fecha_registro?: string;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_perfil: number;
|
||||
}
|
||||
|
||||
export class changePasswordDto {
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@IsString()
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
@@ -26,38 +26,54 @@ export class User {
|
||||
@PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' })
|
||||
id_usuario: number;
|
||||
|
||||
@Column({ name: 'nombre', type: 'varchar' })
|
||||
@Column({ name: 'nombre', type: 'varchar', length: 45, nullable: false })
|
||||
nombre: string;
|
||||
|
||||
@Column({ name: 'apellido_paterno', type: 'varchar' })
|
||||
@Column({
|
||||
name: 'apellido_paterno',
|
||||
type: 'varchar',
|
||||
length: 45,
|
||||
nullable: true,
|
||||
})
|
||||
apellido_paterno: string;
|
||||
|
||||
@Column({ name: 'apellido_materno', type: 'varchar' })
|
||||
@Column({
|
||||
name: 'apellido_materno',
|
||||
type: 'varchar',
|
||||
length: 45,
|
||||
nullable: true,
|
||||
})
|
||||
apellido_materno: string;
|
||||
|
||||
@Column({ name: 'usuario', type: 'varchar' })
|
||||
@Column({ name: 'usuario', type: 'varchar', length: 45, nullable: false })
|
||||
usuario: string;
|
||||
|
||||
@Column({ name: 'password', type: 'varchar', length: 45, nullable: false })
|
||||
password: string;
|
||||
|
||||
@Column({ name: 'activo', type: 'tinyint', nullable: false, default: 1 })
|
||||
@Column({
|
||||
name: 'activo',
|
||||
type: 'tinyint',
|
||||
nullable: false,
|
||||
default: () => 1,
|
||||
})
|
||||
activo: number;
|
||||
|
||||
@Column({ name: 'descripcion', type: 'varchar', length: 50, default: null })
|
||||
description: boolean;
|
||||
@Column({ name: 'descripcion', type: 'varchar', length: 50, nullable: true })
|
||||
descripcion: string;
|
||||
|
||||
@Column({ name: 'fecha_registro', type: 'varchar' })
|
||||
fecha_registro: string;
|
||||
@Column({
|
||||
name: 'fecha_registro',
|
||||
type: 'timestamp',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
fecha_registro: Date;
|
||||
|
||||
@ManyToOne(() => Perfil, (perfil) => perfil.usuarios, { eager: true })
|
||||
@JoinColumn({ name: 'id_perfil' })
|
||||
perfil: Perfil;
|
||||
|
||||
@OneToMany(
|
||||
() => DetalleServicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.user,
|
||||
)
|
||||
@OneToMany(() => DetalleServicio, (detalleServicio) => detalleServicio.user)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@OneToMany(() => Recibo, (recibo) => recibo.user)
|
||||
|
||||
@@ -6,25 +6,40 @@ 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, Login } 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) {}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
async Login(@Body() data: Login, @Res() res: Response) {
|
||||
return this.userService.Login(data, res);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('/validate-token')
|
||||
getProfile(@Request() req) {
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@Post('/create')
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
|
||||
import { UserService } from './user.service';
|
||||
import { UserController } from './user.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Perfil, User } from './entities/user.entity';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
@@ -10,7 +10,7 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User]),
|
||||
TypeOrmModule.forFeature([User, Perfil]),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
@@ -25,6 +25,6 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
],
|
||||
controllers: [UserController],
|
||||
providers: [UserService, JwtStrategy],
|
||||
exports: [UserService,PassportModule,JwtModule],
|
||||
exports: [UserService, PassportModule, JwtModule],
|
||||
})
|
||||
export class UserModule {}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Perfil, User } from './entities/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
@@ -11,10 +11,13 @@ export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
|
||||
@InjectRepository(Perfil)
|
||||
private perfilRepository: Repository<Perfil>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
async findOneByNameandPassword(data: Login): Promise<User> {
|
||||
const { usuario, password } = data;
|
||||
|
||||
const user = await this.userRepository.findOne({
|
||||
@@ -28,7 +31,7 @@ export class UserService {
|
||||
return user;
|
||||
}
|
||||
|
||||
async Login(data: CreateUserDto, res: Response) {
|
||||
async Login(data: Login, res: Response) {
|
||||
const user = await this.findOneByNameandPassword(data);
|
||||
|
||||
const payload = { id: user.id_usuario, usuario: user.usuario };
|
||||
@@ -56,5 +59,32 @@ export class UserService {
|
||||
}
|
||||
return student;
|
||||
}
|
||||
|
||||
async create(data: CreateUserDto) {
|
||||
const { id_perfil, ...rest } = data;
|
||||
|
||||
const perfil = await this.perfilRepository.findOne({
|
||||
where: { id_perfil },
|
||||
});
|
||||
|
||||
if (!perfil) {
|
||||
throw new NotFoundException('Perfil not found');
|
||||
}
|
||||
|
||||
const datauser = { ...rest, perfil };
|
||||
|
||||
const user = this.userRepository.create(datauser);
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
|
||||
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