Merge branch 'master' of repositorio.acatlan.unam.mx:IO/api-AT into Lino
This commit is contained in:
Generated
+1491
-1134
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -36,7 +36,7 @@
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.26"
|
||||
"typeorm": "^0.3.28"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
|
||||
@@ -2,33 +2,40 @@ import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { OperationsService } from './operations.services';
|
||||
import { chargePrintDto } from './dto/operations.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController {
|
||||
constructor(private readonly operationsService: OperationsService) {}
|
||||
constructor(private readonly operationsService: OperationsService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.PCPUMA, Role.SERVICIO_SOCIAL)
|
||||
@Post('impressions')
|
||||
async chargePrint(@Body() data: chargePrintDto, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.chargePrint(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.PCPUMA, Role.SERVICIO_SOCIAL)
|
||||
@Post('receipt')
|
||||
async addCredit(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.addCredit(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.SERVICIO_SOCIAL, Role.ATENCION_USUARIOS)
|
||||
@Post('registration')
|
||||
async addReceiptInscription(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.addReceiptInscription(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.SERVICIO_SOCIAL, Role.ATENCION_USUARIOS)
|
||||
@Post('time')
|
||||
async addTime(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
|
||||
@@ -23,7 +23,7 @@ export class OperationsService {
|
||||
private readonly userService: UserService,
|
||||
private readonly reciboService: ReciboService,
|
||||
private readonly periodoService: PeriodoService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async chargePrint(data: chargePrintDto, id_usuario: number) {
|
||||
const { monto, id_cuenta, id_servicio, numero_hojas } = data;
|
||||
@@ -41,6 +41,7 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const detalleData = {
|
||||
servicio: id_servicio,
|
||||
@@ -49,6 +50,7 @@ export class OperationsService {
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
numero_hojas,
|
||||
periodo,
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
@@ -92,6 +94,7 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
try {
|
||||
const detalleData = {
|
||||
@@ -100,6 +103,7 @@ export class OperationsService {
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
periodo
|
||||
};
|
||||
|
||||
await this.reciboService.create(detalleData, queryRunner.manager);
|
||||
@@ -119,6 +123,12 @@ export class OperationsService {
|
||||
async addTime(data, id_usuario: number) {
|
||||
const { monto, id_cuenta, idPlataforma, folio_recibo, fecha_recibo } = data;
|
||||
|
||||
const ticket = await this.reciboService.findOne(folio_recibo);
|
||||
|
||||
if (ticket) {
|
||||
throw new BadRequestException('Ticket ya existente');
|
||||
}
|
||||
|
||||
const studentRegister = await this.alumnoInscritoService.findRegister(
|
||||
id_cuenta,
|
||||
idPlataforma,
|
||||
@@ -130,6 +140,7 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
try {
|
||||
const detalleRecibo = {
|
||||
@@ -148,6 +159,7 @@ export class OperationsService {
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
periodo,
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
@@ -182,6 +194,12 @@ export class OperationsService {
|
||||
realizo_pago,
|
||||
} = data;
|
||||
|
||||
const ticket = await this.reciboService.findOne(folio_recibo);
|
||||
|
||||
if (ticket) {
|
||||
throw new BadRequestException('Ticket ya existente');
|
||||
}
|
||||
|
||||
await this.alumnoInscritoService.findNotRegister(id_cuenta, id_plataforma);
|
||||
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
@@ -190,27 +208,30 @@ export class OperationsService {
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
const periodo = await this.periodoService.getPeriodoActivo();
|
||||
|
||||
const detalleRecibo = {
|
||||
folio_recibo,
|
||||
user,
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
};
|
||||
|
||||
const detalleData = {
|
||||
servicio: 4,
|
||||
user,
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
periodo,
|
||||
};
|
||||
|
||||
try {
|
||||
const detalleRecibo = {
|
||||
folio_recibo,
|
||||
user,
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
};
|
||||
|
||||
await this.reciboService.create(detalleRecibo, queryRunner.manager);
|
||||
|
||||
const detalleData = {
|
||||
servicio: 4,
|
||||
user,
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(
|
||||
const ola = await this.detalleServicioService.Create(
|
||||
detalleData,
|
||||
queryRunner.manager,
|
||||
);
|
||||
|
||||
@@ -9,24 +9,38 @@ import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('student')
|
||||
export class AlumnoController {
|
||||
constructor(private readonly alumnoService: AlumnoService) {}
|
||||
constructor(private readonly alumnoService: AlumnoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
async find(){
|
||||
async find() {
|
||||
return this.alumnoService.findAll()
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
}
|
||||
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA)
|
||||
@Get(':id')
|
||||
findOneWhitSancion(@Param('id') id: number) {
|
||||
return this.alumnoService.findOneWhitSancion(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA)
|
||||
@Get('sancion/:id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/create')
|
||||
async newStudent(@Body() createStudentDto: CreateStudentDto) {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, 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 { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { AlumnoSancionModule } from 'src/alumno_sancion/alumno_sancion.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Alumno, Carrera])],
|
||||
imports: [TypeOrmModule.forFeature([Alumno, Carrera]),
|
||||
forwardRef(() => AlumnoSancionModule),
|
||||
],
|
||||
controllers: [AlumnoController],
|
||||
providers: [AlumnoService],
|
||||
exports: [AlumnoService],
|
||||
})
|
||||
export class AlumnoModule {}
|
||||
export class AlumnoModule { }
|
||||
//IO
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { ConflictException, ForbiddenException, forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { Alumno } from './entities/student.entity';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Carrera } from 'src/carrera/entities/carrera.entity';
|
||||
import { AlumnoSancionService } from 'src/alumno_sancion/alumno_sancion.service';
|
||||
import { ExceptionsHandler } from '@nestjs/core/exceptions/exceptions-handler';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoService {
|
||||
@@ -12,7 +14,10 @@ export class AlumnoService {
|
||||
private readonly studentRepository: Repository<Alumno>,
|
||||
@InjectRepository(Carrera)
|
||||
private readonly carreraRepository: Repository<Carrera>,
|
||||
) {}
|
||||
|
||||
@Inject(forwardRef(() => AlumnoSancionService))
|
||||
private readonly alumnoSancionService: AlumnoSancionService,
|
||||
) { }
|
||||
|
||||
async findAll(): Promise<Alumno[]> {
|
||||
return this.studentRepository.find({
|
||||
@@ -22,12 +27,21 @@ export class AlumnoService {
|
||||
|
||||
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 currenStudent = await this.studentRepository.findOne({ where: { id_cuenta: data.id_cuenta } })
|
||||
|
||||
if (currenStudent) {
|
||||
throw new ConflictException('El usuario ya existe')
|
||||
}
|
||||
|
||||
const createStudent = { ...rest, carrera, fecha_registro: new Date() };
|
||||
|
||||
const student = this.studentRepository.create(createStudent);
|
||||
@@ -47,6 +61,25 @@ export class AlumnoService {
|
||||
return student;
|
||||
}
|
||||
|
||||
async findOneWhitSancion(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(`Numero de cuenta ${id_cuenta} no existente`);
|
||||
}
|
||||
|
||||
const sancion = await this.alumnoSancionService.findSancion(id_cuenta)
|
||||
|
||||
if (sancion) {
|
||||
throw new ForbiddenException('El usuario se encuentra sancionado')
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
async findOneByName(nombre: string): Promise<Alumno> {
|
||||
const student = await this.studentRepository.findOne({
|
||||
where: { nombre },
|
||||
|
||||
@@ -1,57 +1,61 @@
|
||||
import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import {
|
||||
AddTimeDto,
|
||||
CreateAlumnoInscritoDto,
|
||||
} from './dto/create-alumno_inscrito.dto';
|
||||
import { AlumnoInscrito } from './entities/alumno_inscrito.entity';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('alumno-inscrito')
|
||||
export class AlumnoInscritoController {
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) {}
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Post()
|
||||
async create(@Body() dto: CreateAlumnoInscritoDto): Promise<AlumnoInscrito> {
|
||||
return this.alumnoInscritoService.createWhitoutPay(dto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findAll();
|
||||
}
|
||||
|
||||
// @Post('/tiempo')
|
||||
// async addTime(@Body() body: AddTimeDto) {
|
||||
// const { idCuenta, idPlataforma, tiempoExtra } = body;
|
||||
// return this.alumnoInscritoService.(
|
||||
// idCuenta,
|
||||
// idPlataforma,
|
||||
// tiempoExtra,
|
||||
// );
|
||||
// }
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get("/inscritos/:idPeriodo")
|
||||
async findAllInscritos(@Param('idPeriodo') idPeriodo: number) {
|
||||
return this.alumnoInscritoService.findAllInscritos(idPeriodo);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/plataforma')
|
||||
async findAllPlataforma() {
|
||||
return this.alumnoInscritoService.findAllPlataforma();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get(':id_cuenta')
|
||||
async findByIdWhitoud(
|
||||
@Param('id_cuenta') id_cuenta: number,
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findByIdWhitoud(id_cuenta);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get(':id_cuenta/sancion')
|
||||
async findById(
|
||||
@Param('id_cuenta') id_cuenta: number,
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findById(id_cuenta);
|
||||
}
|
||||
//pruebas borrar
|
||||
@Patch('platica/:idCuenta/:idPeriodo/:idPlataforma')
|
||||
marcarPlatica(
|
||||
@Param('idCuenta') idCuenta: number,
|
||||
@Param('idPeriodo') idPeriodo: number,
|
||||
@Param('idPlataforma') idPlataforma: number,
|
||||
) {
|
||||
return this.alumnoInscritoService.marcarPlatica(
|
||||
idCuenta,
|
||||
idPeriodo,
|
||||
idPlataforma,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { AlumnoInscritoController } from './alumno_inscrito.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoInscrito, Plataforma } from './entities/alumno_inscrito.entity';
|
||||
import { BitacoraMesa } from 'src/bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
import { PeriodoModule } from 'src/periodo/periodo.module';
|
||||
import { AlumnoSancionModule } from 'src/alumno_sancion/alumno_sancion.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito,Plataforma,BitacoraMesa]),PeriodoModule],
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito, Plataforma, BitacoraMesa]), PeriodoModule,
|
||||
forwardRef(() => AlumnoSancionModule),],
|
||||
controllers: [AlumnoInscritoController],
|
||||
providers: [AlumnoInscritoService],
|
||||
exports:[AlumnoInscritoService]
|
||||
exports: [AlumnoInscritoService]
|
||||
})
|
||||
export class AlumnoInscritoModule {}
|
||||
export class AlumnoInscritoModule { }
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
@@ -8,6 +11,7 @@ import { AlumnoInscrito, Plataforma } from './entities/alumno_inscrito.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { PeriodoService } from 'src/periodo/periodo.service';
|
||||
import { AlumnoSancionService } from 'src/alumno_sancion/alumno_sancion.service';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoInscritoService {
|
||||
@@ -17,7 +21,10 @@ export class AlumnoInscritoService {
|
||||
@InjectRepository(Plataforma)
|
||||
private readonly plataformaRepo: Repository<Plataforma>,
|
||||
private readonly periodoService: PeriodoService,
|
||||
) {}
|
||||
|
||||
@Inject(forwardRef(() => AlumnoSancionService))
|
||||
private readonly alumnoSancionService: AlumnoSancionService,
|
||||
) { }
|
||||
|
||||
async createWhitoutPay(
|
||||
dto: CreateAlumnoInscritoDto,
|
||||
@@ -55,6 +62,31 @@ export class AlumnoInscritoService {
|
||||
});
|
||||
}
|
||||
|
||||
async findAllInscritos(idPeriodo: number) {
|
||||
return this.alumnoInscritoRepo
|
||||
.createQueryBuilder('inscritos')
|
||||
|
||||
.innerJoin('inscritos.alumno', 'alumno')
|
||||
.innerJoin('alumno.carrera', 'carrera')
|
||||
.innerJoin('inscritos.plataforma', 'plataforma')
|
||||
.innerJoin('inscritos.periodo', 'periodo')
|
||||
|
||||
.where('periodo.id_periodo = :idPeriodo', { idPeriodo })
|
||||
|
||||
.select([
|
||||
'carrera.carrera AS carrera',
|
||||
'alumno.genero AS genero',
|
||||
'plataforma.nombre AS profesor',
|
||||
'COUNT(DISTINCT alumno.id_cuenta) AS total'
|
||||
])
|
||||
|
||||
.groupBy('carrera.carrera')
|
||||
.addGroupBy('alumno.genero')
|
||||
.addGroupBy('plataforma.nombre')
|
||||
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async findAllPlataforma() {
|
||||
return this.plataformaRepo.find();
|
||||
}
|
||||
@@ -64,6 +96,12 @@ export class AlumnoInscritoService {
|
||||
}
|
||||
|
||||
async findById(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
const sancion = await this.alumnoSancionService.findSancion(id_cuenta)
|
||||
|
||||
if (sancion) {
|
||||
throw new ForbiddenException('El usuario se encuentra sancionado')
|
||||
}
|
||||
|
||||
const students = await this.alumnoInscritoRepo
|
||||
.createQueryBuilder('ai')
|
||||
.leftJoinAndSelect('ai.alumno', 'alumno')
|
||||
@@ -74,7 +112,25 @@ export class AlumnoInscritoService {
|
||||
.getMany();
|
||||
|
||||
if (students.length === 0) {
|
||||
throw new NotFoundException('Estudiante no Registrado');
|
||||
throw new NotFoundException('Estudiante no inscrito en el periodo actual');
|
||||
}
|
||||
|
||||
return students;
|
||||
}
|
||||
|
||||
async findByIdWhitoud(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
|
||||
const students = await this.alumnoInscritoRepo
|
||||
.createQueryBuilder('ai')
|
||||
.leftJoinAndSelect('ai.alumno', 'alumno')
|
||||
.leftJoinAndSelect('ai.periodo', 'periodo')
|
||||
.leftJoinAndSelect('ai.plataforma', 'plataforma')
|
||||
.where('alumno.id_cuenta = :id_cuenta', { id_cuenta })
|
||||
.andWhere("periodo.activo = b'1'")
|
||||
.getMany();
|
||||
|
||||
if (students.length === 0) {
|
||||
throw new NotFoundException('Estudiante no inscrito en el periodo actual');
|
||||
}
|
||||
|
||||
return students;
|
||||
|
||||
@@ -75,6 +75,6 @@ export class AlumnoInscrito {
|
||||
@OneToMany(() => BitacoraMesa, (bitacoraMesa) => bitacoraMesa.alumno_inscrito)
|
||||
bitacoras_mesa: BitacoraMesa[];
|
||||
|
||||
@OneToMany(() => Bitacora, (bitacora) => bitacora.equipo)
|
||||
@OneToMany(() => Bitacora, (bitacora) => bitacora.alumno_inscrito)
|
||||
bitacoras: Bitacora[];
|
||||
}
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('alumno-sancion')
|
||||
export class AlumnoSancionController {
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
async create(@Body() createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
return this.alumnoSancionService.create(createAlumnoSancionDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findbyStudent(@Param('id') id: number) {
|
||||
return this.alumnoSancionService.findbyStudent(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Delete(':id_cuenta')
|
||||
async deleteSancionesAlumno(@Param('id_cuenta') id_cuenta: number) {
|
||||
return this.alumnoSancionService.removeByStudent(+id_cuenta);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||
import { AlumnoSancionController } from './alumno_sancion.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
@@ -7,16 +7,16 @@ import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { SancionModule } from 'src/sancion/sancion.module';
|
||||
import { AlumnoService } from 'src/alumno/student.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([AlumnoSancion, Alumno, Sancion]),
|
||||
AlumnoModule,
|
||||
forwardRef(() => AlumnoModule),
|
||||
SancionModule,
|
||||
],
|
||||
controllers: [AlumnoSancionController],
|
||||
providers: [AlumnoSancionService],
|
||||
exports: [AlumnoSancionService]
|
||||
})
|
||||
export class AlumnoSancionModule {}
|
||||
//IO
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -11,9 +11,12 @@ export class AlumnoSancionService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoSancion)
|
||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||
|
||||
@Inject(forwardRef(() => AlumnoService))
|
||||
private readonly alumnoService: AlumnoService,
|
||||
|
||||
private readonly sancionService: SancionService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async create(createAlumnoSancionDto: CreateAlumnoSancionDto) {
|
||||
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
|
||||
@@ -34,6 +37,18 @@ export class AlumnoSancionService {
|
||||
return await this.alumnosancionRepository.save(alumnosancion);
|
||||
}
|
||||
|
||||
async findSancion(id_cuenta: number): Promise<boolean> {
|
||||
const alusancion = await this.alumnosancionRepository.find({
|
||||
where: { alumno: { id_cuenta } },
|
||||
});
|
||||
|
||||
if (alusancion.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async findbyStudent(id_cuenta: number) {
|
||||
const student = await this.alumnoService.findOne(id_cuenta);
|
||||
|
||||
@@ -41,9 +56,6 @@ export class AlumnoSancionService {
|
||||
where: { alumno: { id_cuenta } },
|
||||
});
|
||||
|
||||
if (alusancion.length === 0) {
|
||||
throw new NotFoundException(`El estudiante no cuenta con una sanción activa`);
|
||||
}
|
||||
return { student, alusancion };
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -44,6 +44,8 @@ import { Bitacora } from './bitacora/entities/bitacora.entity';
|
||||
import { MensajeModule } from './mensaje/mensaje.module';
|
||||
import { Mensaje } from './mensaje/entities/mensaje.entity';
|
||||
import { ActiveDirectoryModule } from './active-directory/active-directory.module';
|
||||
import { CostoModule } from './costo/costo.module';
|
||||
import { Costo } from './costo/entities/costo.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -80,7 +82,8 @@ import { ActiveDirectoryModule } from './active-directory/active-directory.modul
|
||||
ProgramaEquipo,
|
||||
BitacoraMesa,
|
||||
Bitacora,
|
||||
Mensaje
|
||||
Mensaje,
|
||||
Costo,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -104,6 +107,7 @@ import { ActiveDirectoryModule } from './active-directory/active-directory.modul
|
||||
BitacoraMesaModule,
|
||||
BitacoraModule,
|
||||
MensajeModule,
|
||||
CostoModule,
|
||||
ActiveDirectoryModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { AreaUbicacionService } from './area_ubicacion.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('area-ubicacion')
|
||||
export class AreaUbicacionController {
|
||||
constructor(private readonly areaUbicacionService: AreaUbicacionService) {}
|
||||
constructor(private readonly areaUbicacionService: AreaUbicacionService) { }
|
||||
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.areaUbicacionService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.areaUbicacionService.findOne(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/programs/:id')
|
||||
findProgramsByArea(@Param('id')id:number){
|
||||
findProgramsByArea(@Param('id') id: number) {
|
||||
return this.areaUbicacionService.findProgramsByArea(+id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,38 @@
|
||||
import { Controller, Get, Post, Body, Param, Patch } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, Patch, UseGuards } from '@nestjs/common';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { BitacoraAlumnoDto, CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('bitacora')
|
||||
export class BitacoraController {
|
||||
constructor(private readonly bitacoraService: BitacoraService) {}
|
||||
constructor(private readonly bitacoraService: BitacoraService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Post()
|
||||
assignment(@Body() createBitacoraDto: CreateBitacoraDto) {
|
||||
return this.bitacoraService.assignment(createBitacoraDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/cuenta/:id')
|
||||
findOneByAcount(@Param('id') id: string) {
|
||||
return this.bitacoraService.findOneByAcount(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/equipo/:id')
|
||||
findOneByMachine(@Param('id') id: string) {
|
||||
return this.bitacoraService.findOneByMachine(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Patch('cancelar/:id')
|
||||
cancelationByMachine(
|
||||
@Param('id') id: number,
|
||||
@@ -29,8 +41,32 @@ export class BitacoraController {
|
||||
return this.bitacoraService.cancelation(id, tiempo_asignado);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bitacoraService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('equipos-por-dia')
|
||||
async obtenerEquipos(
|
||||
@Body() dto: BitacoraAlumnoDto
|
||||
) {
|
||||
return this.bitacoraService.obtenerEquiposPorAlumnoYFecha(
|
||||
dto.numero_cuenta,
|
||||
dto.fecha,
|
||||
);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('equipos-por-equipo')
|
||||
async equiposPorEquipo(
|
||||
@Body() dto: EquiposPorEquipoDto,
|
||||
) {
|
||||
return this.bitacoraService.equiposPorEquipo(dto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { CreateBitacoraDto, EquiposPorEquipoDto } from './dto/create-bitacora.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Bitacora } from './entities/bitacora.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -9,7 +9,7 @@ export class BitacoraService {
|
||||
constructor(
|
||||
@InjectRepository(Bitacora)
|
||||
private readonly bitacoraRepository: Repository<Bitacora>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
assignment(dto: CreateBitacoraDto) {
|
||||
const bitacora = this.bitacoraRepository.create({
|
||||
@@ -91,4 +91,64 @@ export class BitacoraService {
|
||||
|
||||
return { message: 'Tiempo cancelado' };
|
||||
}
|
||||
|
||||
async obtenerEquiposPorAlumnoYFecha(numeroCuenta: string, fecha: string) {
|
||||
|
||||
const fechaInicio = new Date(`${fecha}T00:00:00`);
|
||||
const fechaFin = new Date(`${fecha}T23:59:59`);
|
||||
|
||||
return await this.bitacoraRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.innerJoinAndSelect('bitacora.equipo', 'equipo')
|
||||
.innerJoin('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.innerJoin('alumnoInscrito.alumno', 'alumno')
|
||||
.where('alumno.id_cuenta = :numeroCuenta', { numeroCuenta })
|
||||
.andWhere('bitacora.tiempo_entrada BETWEEN :inicio AND :fin', {
|
||||
inicio: fechaInicio,
|
||||
fin: fechaFin,
|
||||
})
|
||||
.select([
|
||||
'bitacora.tiempo_entrada',
|
||||
'bitacora.tiempo_asignado',
|
||||
'equipo.ubicacion',
|
||||
'equipo.nombre_equipo'
|
||||
])
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async equiposPorEquipo(dto: EquiposPorEquipoDto) {
|
||||
const { id_equipo, fecha } = dto;
|
||||
|
||||
const inicio = new Date(`${fecha}T00:00:00`);
|
||||
const fin = new Date(`${fecha}T23:59:59`);
|
||||
|
||||
const registros = await this.bitacoraRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.innerJoin('bitacora.equipo', 'equipo')
|
||||
.innerJoin('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.innerJoin('alumnoInscrito.alumno', 'alumno')
|
||||
.where('equipo.id_equipo = :id_equipo', { id_equipo })
|
||||
.andWhere('bitacora.tiempo_entrada BETWEEN :inicio AND :fin', {
|
||||
inicio,
|
||||
fin,
|
||||
})
|
||||
.select([
|
||||
'bitacora.tiempo_entrada AS tiempo_entrada',
|
||||
'bitacora.tiempo_asignado AS tiempo_asignado',
|
||||
'alumno.id_cuenta AS id_cuenta'
|
||||
])
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getRawMany();
|
||||
|
||||
return registros.map(reg => ({
|
||||
hora_entrada: reg.tiempo_entrada,
|
||||
min_utilizados: reg.tiempo_asignado,
|
||||
hora_salida: new Date(
|
||||
new Date(reg.tiempo_entrada).getTime() +
|
||||
reg.tiempo_asignado * 60000
|
||||
),
|
||||
cuenta_asociada: reg.id_cuenta
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,32 @@
|
||||
import { IsInt, IsOptional, IsString } from "class-validator";
|
||||
import { IsDateString, IsInt, IsNumber, IsNumberString, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateBitacoraDto {
|
||||
@IsInt()
|
||||
tiempo_asignado: number;
|
||||
@IsInt()
|
||||
tiempo_asignado: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ubicacion?: string;
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ubicacion?: string;
|
||||
|
||||
@IsInt()
|
||||
id_equipo: number;
|
||||
@IsInt()
|
||||
id_equipo: number;
|
||||
|
||||
@IsInt()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
@IsInt()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
|
||||
export class BitacoraAlumnoDto {
|
||||
@IsNumberString()
|
||||
numero_cuenta: string;
|
||||
|
||||
@IsDateString()
|
||||
fecha: string;
|
||||
}
|
||||
|
||||
export class EquiposPorEquipoDto {
|
||||
@IsNumber()
|
||||
id_equipo: number;
|
||||
|
||||
@IsString()
|
||||
fecha: string;
|
||||
}
|
||||
|
||||
@@ -5,40 +5,63 @@ import {
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { BitacoraMesaService } from './bitacora_mesa.service';
|
||||
import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto';
|
||||
import { CreateBitacoraMesaDto, FindByDate } from './dto/create-bitacora_mesa.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('bitacora-mesa')
|
||||
export class BitacoraMesaController {
|
||||
constructor(private readonly bitacoraMesaService: BitacoraMesaService) {}
|
||||
constructor(private readonly bitacoraMesaService: BitacoraMesaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Post()
|
||||
assignment(@Body() createBitacoraMesaDto: CreateBitacoraMesaDto) {
|
||||
return this.bitacoraMesaService.assignment(createBitacoraMesaDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bitacoraMesaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.bitacoraMesaService.findOne(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/cuenta/:id_cuenta')
|
||||
findByCuenta(@Param('id_cuenta') id_cuenta: string) {
|
||||
return this.bitacoraMesaService.findByCuenta(+id_cuenta);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/table/:id_mesa')
|
||||
findByTable(@Param('id_mesa') id_mesa: number) {
|
||||
return this.bitacoraMesaService.findByTable(id_mesa);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/date')
|
||||
findByDate(@Body() data: FindByDate) {
|
||||
return this.bitacoraMesaService.findByDate(data.date);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Patch('cancelar/:id')
|
||||
cancelationByMachine(
|
||||
@Param('id') id: number,
|
||||
@@ -46,4 +69,12 @@ export class BitacoraMesaController {
|
||||
) {
|
||||
return this.bitacoraMesaService.cancelation(id, tiempo_asignado);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('mesas-por-dia')
|
||||
mesasPorDia(@Body() body: { fecha: string }) {
|
||||
return this.bitacoraMesaService.mesasPorFecha(body.fecha);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBitacoraMesaDto } from './dto/create-bitacora_mesa.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { BitacoraMesa } from './entities/bitacora_mesa.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Repository, Between } from 'typeorm';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
|
||||
@@ -11,46 +11,46 @@ export class BitacoraMesaService {
|
||||
constructor(
|
||||
@InjectRepository(BitacoraMesa)
|
||||
private readonly bitacoraMesaRepository: Repository<BitacoraMesa>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async assignment(dto: CreateBitacoraMesaDto) {
|
||||
|
||||
// VALIDAR: el alumno ya tiene una mesa activa
|
||||
const alumnoConMesa = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
|
||||
id_alumno_inscrito: dto.id_alumno_inscrito,
|
||||
})
|
||||
.andWhere(
|
||||
`TIMESTAMPDIFF(
|
||||
async assignment(dto: CreateBitacoraMesaDto) {
|
||||
|
||||
const alumnoConMesa = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.where('bitacora.id_alumno_inscrito = :id_alumno_inscrito', {
|
||||
id_alumno_inscrito: dto.id_alumno_inscrito,
|
||||
})
|
||||
.andWhere(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getOne();
|
||||
)
|
||||
.getOne();
|
||||
|
||||
if (alumnoConMesa) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya tiene una mesa asignada',
|
||||
);
|
||||
if (alumnoConMesa) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya tiene una mesa asignada',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const bitacora = this.bitacoraMesaRepository.create({
|
||||
tiempo_entrada: new Date(),
|
||||
tiempo_asignado: dto.tiempo_asignado,
|
||||
mesa: { id_mesa: dto.id_mesa },
|
||||
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
||||
});
|
||||
|
||||
return this.bitacoraMesaRepository.save(bitacora);
|
||||
}
|
||||
|
||||
|
||||
const bitacora = this.bitacoraMesaRepository.create({
|
||||
tiempo_entrada: new Date(),
|
||||
tiempo_asignado: dto.tiempo_asignado,
|
||||
mesa: { id_mesa: dto.id_mesa },
|
||||
alumno_inscrito: { id_alumno_inscrito: dto.id_alumno_inscrito },
|
||||
});
|
||||
|
||||
return this.bitacoraMesaRepository.save(bitacora);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.bitacoraMesaRepository.find({
|
||||
relations: ['mesa', 'alumno_inscrito'],
|
||||
take: 100,
|
||||
order: { id_bitacora_mesa: "DESC" }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,13 +75,13 @@ export class BitacoraMesaService {
|
||||
.getOne();
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException('alumno sin mesa');
|
||||
throw new NotFoundException('Alumno sin mesa');
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
async findByTable(id_mesa: number) {
|
||||
async findByTable(id_mesa: number) {
|
||||
const student = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
@@ -104,6 +104,18 @@ export class BitacoraMesaService {
|
||||
return student;
|
||||
}
|
||||
|
||||
async findByDate(date) {
|
||||
const start = new Date(`${date}T00:00:00`);
|
||||
const end = new Date(`${date}T23:59:59`);
|
||||
|
||||
return this.bitacoraMesaRepository.find({
|
||||
where: {
|
||||
tiempo_entrada: Between(start, end),
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async cancelation(id_bitacora_mesa: number, nuevoTiempo: number) {
|
||||
const bitacora = await this.bitacoraMesaRepository.findOne({
|
||||
where: { id_bitacora_mesa },
|
||||
@@ -119,4 +131,33 @@ export class BitacoraMesaService {
|
||||
|
||||
return { message: 'Tiempo cancelado' };
|
||||
}
|
||||
|
||||
async mesasPorFecha(fecha: string) {
|
||||
const inicio = new Date(`${fecha}T00:00:00`);
|
||||
const fin = new Date(`${fecha}T23:59:59`);
|
||||
|
||||
const registros = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.innerJoinAndSelect('bitacora.mesa', 'mesa')
|
||||
.innerJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.innerJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
||||
.where('bitacora.tiempo_entrada BETWEEN :inicio AND :fin', {
|
||||
inicio,
|
||||
fin,
|
||||
})
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getMany();
|
||||
|
||||
return registros.map(reg => ({
|
||||
no_mesa: reg.mesa?.id_mesa,
|
||||
no_cuenta: reg.alumno_inscrito?.alumno?.id_cuenta,
|
||||
hora_entrada: reg.tiempo_entrada,
|
||||
tiempo_asignado: reg.tiempo_asignado,
|
||||
hora_salida: new Date(
|
||||
new Date(reg.tiempo_entrada).getTime() +
|
||||
reg.tiempo_asignado * 60000
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsInt, IsPositive } from 'class-validator';
|
||||
import { IsDateString, IsInt, IsPositive } from 'class-validator';
|
||||
|
||||
export class CreateBitacoraMesaDto {
|
||||
@IsInt()
|
||||
@@ -12,4 +12,9 @@ export class CreateBitacoraMesaDto {
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
id_alumno_inscrito: number;
|
||||
}
|
||||
|
||||
export class FindByDate {
|
||||
@IsDateString()
|
||||
date: string;
|
||||
}
|
||||
@@ -19,7 +19,6 @@ export class BitacoraMesa {
|
||||
@Column({ name: 'tiempo_entrada', type: 'datetime' })
|
||||
tiempo_entrada: Date;
|
||||
|
||||
|
||||
@ManyToOne(() => Mesa)
|
||||
@JoinColumn({ name: 'id_mesa' })
|
||||
mesa: Mesa;
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { CarreraService } from './carrera.service';
|
||||
import { Carrera } from './entities/carrera.entity';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('carrera')
|
||||
export class CarreraController {
|
||||
constructor(private readonly carreraService: CarreraService) {}
|
||||
constructor(private readonly carreraService: CarreraService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
findAll(): Promise<Carrera[]> {
|
||||
return this.carreraService.findAll();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CostoController } from './costo.controller';
|
||||
import { CostoService } from './costo.service';
|
||||
|
||||
describe('CostoController', () => {
|
||||
let controller: CostoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CostoController],
|
||||
providers: [CostoService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CostoController>(CostoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { CostoService } from './costo.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Role } from 'src/role.enum';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
|
||||
@Controller('costo')
|
||||
export class CostoController {
|
||||
constructor(private readonly costoService: CostoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL,Role.PCPUMA)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.costoService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/:id_servicio')
|
||||
find(@Param('id_servicio') id_servicio: number) {
|
||||
return this.costoService.find(id_servicio);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CostoService } from './costo.service';
|
||||
import { CostoController } from './costo.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Costo } from './entities/costo.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Costo])],
|
||||
controllers: [CostoController],
|
||||
providers: [CostoService],
|
||||
})
|
||||
export class CostoModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CostoService } from './costo.service';
|
||||
|
||||
describe('CostoService', () => {
|
||||
let service: CostoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CostoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CostoService>(CostoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Costo } from './entities/costo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class CostoService {
|
||||
constructor(@InjectRepository(Costo)
|
||||
private readonly CostoRepository: Repository<Costo>) {}
|
||||
|
||||
findAll() {
|
||||
return this.CostoRepository.find();
|
||||
}
|
||||
|
||||
find(id_servicio: number) {
|
||||
return this.CostoRepository.find({ where: { id_servicio } });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateCostoDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateCostoDto } from './create-costo.dto';
|
||||
|
||||
export class UpdateCostoDto extends PartialType(CreateCostoDto) {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
|
||||
|
||||
@Entity('costo')
|
||||
export class Costo {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id_costo: number;
|
||||
|
||||
@Column('decimal', { precision: 10, scale: 2 })
|
||||
costo: number;
|
||||
|
||||
@Column({ type: 'int' })
|
||||
id_servicio: number;
|
||||
|
||||
@Column({
|
||||
type: 'timestamp',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
fecha_registro: Date;
|
||||
|
||||
}
|
||||
@@ -1,20 +1,41 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
|
||||
import { DetalleServicioService } from './detalle_servicio.service';
|
||||
import { FindReciboByRangeDto } from 'src/recibo/dto/create-recibo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
|
||||
@Controller('detalle-servicio')
|
||||
export class DetalleServicioController {
|
||||
constructor(private readonly detalleServicioService: DetalleServicioService) {}
|
||||
constructor(private readonly detalleServicioService: DetalleServicioService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll(){
|
||||
findAll() {
|
||||
return this.detalleServicioService.findAll()
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('rango')
|
||||
async findByDateRange(@Body() data: FindReciboByRangeDto) {
|
||||
return this.detalleServicioService.findByDateRange(data.desde, data.hasta);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('totales-por-periodo')
|
||||
async getTotalesPorPeriodo(
|
||||
@Query('periodoInicio') periodoInicio?: string,
|
||||
@Query('periodoFin') periodoFin?: string,
|
||||
@Query('servicioId') servicioId?: string,
|
||||
) {
|
||||
const inicio = periodoInicio ? parseInt(periodoInicio) : undefined;
|
||||
const fin = periodoFin ? parseInt(periodoFin) : undefined;
|
||||
const servicio = servicioId ? parseInt(servicioId) : undefined;
|
||||
return this.detalleServicioService.getTotalesPorServicioYPeriodo(inicio, fin, servicio);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export class DetalleServicioService {
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.detalleServicioRepository.find({ take: 100 });
|
||||
return this.detalleServicioRepository.find({ take: 100 ,order:{fecha_operacion:'DESC'}});
|
||||
}
|
||||
|
||||
async findByDateRange(desde: string, hasta: string) {
|
||||
@@ -35,4 +35,42 @@ export class DetalleServicioService {
|
||||
.addGroupBy('servicio.servicio')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
async getTotalesPorServicioYPeriodo(periodoInicio?: number, periodoFin?: number, servicioId?: number) {
|
||||
const query = this.detalleServicioRepository
|
||||
.createQueryBuilder('ds')
|
||||
.select('s.servicio', 'nombre_servicio')
|
||||
.addSelect('p.semestre', 'periodo')
|
||||
.addSelect('p.id_periodo', 'id_periodo')
|
||||
.addSelect('SUM(ds.monto)', 'monto_total')
|
||||
.innerJoin('ds.servicio', 's')
|
||||
.innerJoin('ds.periodo', 'p');
|
||||
|
||||
if (periodoInicio && periodoFin) {
|
||||
query.andWhere('p.id_periodo BETWEEN :inicio AND :fin', { inicio: periodoInicio, fin: periodoFin });
|
||||
} else if (periodoInicio) {
|
||||
query.andWhere('p.id_periodo >= :inicio', { inicio: periodoInicio });
|
||||
} else if (periodoFin) {
|
||||
query.andWhere('p.id_periodo <= :fin', { fin: periodoFin });
|
||||
}
|
||||
|
||||
if (servicioId) {
|
||||
query.andWhere('s.id_servicio = :servicioId', { servicioId });
|
||||
}
|
||||
|
||||
const resultados = await query
|
||||
.groupBy('s.id_servicio')
|
||||
.addGroupBy('p.id_periodo')
|
||||
.orderBy('p.id_periodo')
|
||||
.addOrderBy('s.servicio')
|
||||
.getRawMany();
|
||||
|
||||
return resultados.map(item => ({
|
||||
nombre_servicio: item.nombre_servicio,
|
||||
periodo: item.periodo,
|
||||
monto_total: parseFloat(item.monto_total) || 0,
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
//IO
|
||||
@@ -1,57 +1,81 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Param, Patch, Post, UseGuards } from '@nestjs/common';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { Equipo } from './entities/equipo.entity';
|
||||
import { CreateEquipoDto, UpdateAreaEquiposDto } from './dto/create-equipo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('equipo')
|
||||
export class EquipoController {
|
||||
constructor(private readonly equipoService: EquipoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Get()
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
findAll(): Promise<Equipo[]> {
|
||||
return this.equipoService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/active')
|
||||
findActive() {
|
||||
return this.equipoService.findActive();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/disable')
|
||||
findDisable() {
|
||||
return this.equipoService.findDisable();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Get('/student/:id')
|
||||
findOnlyUsable(@Param('id') id: number): Promise<Equipo[]> {
|
||||
return this.equipoService.findOnlyUsable(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/busy')
|
||||
findOnlyBusy(): Promise<Equipo[]> {
|
||||
return this.equipoService.findOnlyBusy();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string): Promise<Equipo> {
|
||||
return this.equipoService.findOne(id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
create(@Body() equipo: CreateEquipoDto) {
|
||||
return this.equipoService.create(equipo);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch()
|
||||
update(@Body() equipo: CreateEquipoDto) {
|
||||
return this.equipoService.update(equipo);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Patch(':id/activo')
|
||||
toggleActivo(@Param('id') id: number) {
|
||||
return this.equipoService.toggleActivo(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR,Role.ATENCION_USUARIOS,Role.SERVICIO_SOCIAL)
|
||||
@Patch('actualizar-area')
|
||||
actualizarPorArea(
|
||||
@Body() updateAreaEquiposDto: UpdateAreaEquiposDto,
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { MensajeService } from './mensaje.service';
|
||||
import { CreateMensajeDto } from './dto/create-mensaje.dto';
|
||||
import { UpdateMensajeDto } from './dto/update-mensaje.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('mensaje')
|
||||
export class MensajeController {
|
||||
constructor(private readonly mensajeService: MensajeService) {}
|
||||
constructor(private readonly mensajeService: MensajeService) { }
|
||||
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Get() @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
findAll() {
|
||||
return this.mensajeService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.mensajeService.findOne(+id);
|
||||
|
||||
@@ -1,21 +1,45 @@
|
||||
import { Controller, Body, Patch, Param, Get } from '@nestjs/common';
|
||||
import { Controller, Body, Patch, Param, Get, UseGuards } from '@nestjs/common';
|
||||
import { MesaService } from './mesa.service';
|
||||
import { UpdateMesaDto } from './dto/update-mesa.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Role } from 'src/role.enum';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
|
||||
@Controller('mesa')
|
||||
export class MesaController {
|
||||
constructor(private readonly mesaService: MesaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get()
|
||||
async findAll() {
|
||||
return this.mesaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('activo')
|
||||
async findAllActivo() {
|
||||
return this.mesaService.findAllActivo();
|
||||
}
|
||||
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('uso')
|
||||
async findActiveMesas() {
|
||||
return this.mesaService.findActiveMesas();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Get('usoWhitout')
|
||||
async findActiveMesasWhitoudOcupado() {
|
||||
return this.mesaService.findActiveMesasWhitoudOcupado();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch(':id')
|
||||
async updateActivo(
|
||||
@Param('id') id: number,
|
||||
@@ -24,6 +48,8 @@ export class MesaController {
|
||||
return this.mesaService.updateActivo(id, updateMesaDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR, Role.ATENCION_USUARIOS, Role.SERVICIO_SOCIAL)
|
||||
@Patch(':id/activo')
|
||||
toggleActivo(@Param('id') id: number) {
|
||||
return this.mesaService.toggleActivo(+id);
|
||||
|
||||
@@ -38,15 +38,42 @@ export class MesaService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async findAll(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find();
|
||||
}
|
||||
|
||||
|
||||
async findAllActivo(): Promise<Mesa[]> {
|
||||
return await this.mesaRepository.find({ where: { activo: true } });
|
||||
const mesas = await this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
|
||||
.andWhere('mesa.activo = true')
|
||||
|
||||
.andWhere((qb) => {
|
||||
const subQuery = qb
|
||||
.subQuery()
|
||||
.select('bitacora_mesa.id_mesa')
|
||||
.from('bitacora_mesa', 'bitacora_mesa')
|
||||
.where(
|
||||
`TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bitacora_mesa.tiempo_entrada, INTERVAL bitacora_mesa.tiempo_asignado MINUTE)
|
||||
) > 0`,
|
||||
)
|
||||
.getQuery();
|
||||
|
||||
return `mesa.id_mesa NOT IN ${subQuery}`;
|
||||
})
|
||||
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
|
||||
.getMany();
|
||||
|
||||
if (!mesas.length) {
|
||||
throw new NotFoundException('No usable table found');
|
||||
}
|
||||
|
||||
return mesas;
|
||||
}
|
||||
|
||||
async updateActivo(id: number, updateMesaDto: UpdateMesaDto) {
|
||||
@@ -92,4 +119,50 @@ export class MesaService {
|
||||
activo: nuevoActivo,
|
||||
};
|
||||
}
|
||||
|
||||
findActiveMesas() {
|
||||
return this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
.select([
|
||||
'mesa.id_mesa AS id_mesa',
|
||||
`
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM bitacora_mesa bm
|
||||
WHERE bm.id_mesa = mesa.id_mesa
|
||||
AND TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bm.tiempo_entrada, INTERVAL bm.tiempo_asignado MINUTE)
|
||||
) > 0
|
||||
) AS ocupado
|
||||
`,
|
||||
])
|
||||
.where('mesa.activo = 1')
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
findActiveMesasWhitoudOcupado() {
|
||||
return this.mesaRepository
|
||||
.createQueryBuilder('mesa')
|
||||
.select([
|
||||
'mesa.id_mesa AS id_mesa',
|
||||
])
|
||||
.where('mesa.activo = 1')
|
||||
.andWhere(`
|
||||
NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM bitacora_mesa bm
|
||||
WHERE bm.id_mesa = mesa.id_mesa
|
||||
AND TIMESTAMPDIFF(
|
||||
SECOND,
|
||||
NOW(),
|
||||
DATE_ADD(bm.tiempo_entrada, INTERVAL bm.tiempo_asignado MINUTE)
|
||||
) > 0
|
||||
)
|
||||
`)
|
||||
.orderBy('mesa.id_mesa', 'ASC')
|
||||
.getRawMany();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,3 +21,13 @@ export class CreatePeriodoDto {
|
||||
@IsBoolean()
|
||||
activo?: boolean;
|
||||
}
|
||||
|
||||
export class ModifiedDateDto {
|
||||
|
||||
@IsDateString()
|
||||
fecha_inicio_servicio: string;
|
||||
|
||||
@IsDateString()
|
||||
fecha_fin_servicio: string;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,40 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('periodo')
|
||||
export class PeriodoController {
|
||||
constructor(private readonly periodoService:PeriodoService){}
|
||||
constructor(private readonly periodoService: PeriodoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll(){
|
||||
findAll() {
|
||||
return this.periodoService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
create(@Body() data: CreatePeriodoDto) {
|
||||
return this.periodoService.create(data);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Delete("/:id_periodo")
|
||||
delete(@Param("id_periodo") id_periodo: number) {
|
||||
return this.periodoService.delete(id_periodo)
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch("/date/:id_periodo")
|
||||
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
||||
return this.periodoService.modifiedDate(data, id_periodo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Periodo } from './entities/periodo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PeriodoService {
|
||||
constructor(
|
||||
@InjectRepository(Periodo)
|
||||
private readonly periodoRepository: Repository<Periodo>,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async findOne() {
|
||||
return this.periodoRepository.findOne({ where: {} });
|
||||
async findOne(semestre: string) {
|
||||
return this.periodoRepository.findOne({ where: { semestre } });
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return this.periodoRepository.find();
|
||||
return this.periodoRepository.find({order:{'id_periodo':"DESC"}});
|
||||
}
|
||||
|
||||
async getPeriodoActivo(): Promise<Periodo> {
|
||||
@@ -30,4 +31,42 @@ export class PeriodoService {
|
||||
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async getPeriodoActivoWhitoutError(): Promise<Periodo | null> {
|
||||
const periodo = await this.periodoRepository.findOne({
|
||||
where: { activo: true },
|
||||
order: { id_periodo: 'DESC' },
|
||||
});
|
||||
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async delete(id_periodo: number) {
|
||||
await this.periodoRepository.delete(id_periodo)
|
||||
}
|
||||
|
||||
async periodoDisable(id_periodo: number) {
|
||||
await this.periodoRepository.update(id_periodo, { activo: false })
|
||||
}
|
||||
|
||||
async create(data: CreatePeriodoDto) {
|
||||
const periodo = await this.findOne(data.semestre)
|
||||
|
||||
if (periodo) {
|
||||
throw new BadRequestException("El periodo ya existe")
|
||||
}
|
||||
|
||||
const periodoActive = await this.getPeriodoActivoWhitoutError();
|
||||
|
||||
if (periodoActive) {
|
||||
await this.periodoDisable(periodoActive.id_periodo)
|
||||
}
|
||||
|
||||
const create = this.periodoRepository.create(data)
|
||||
return this.periodoRepository.save(create)
|
||||
}
|
||||
|
||||
async modifiedDate(data: ModifiedDateDto, id_periodo) {
|
||||
return this.periodoRepository.update(id_periodo, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,48 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { ProgramaService } from './programa.service';
|
||||
import { UpdateProgramaDto } from './dto/update-programa.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('programa')
|
||||
export class ProgramaController {
|
||||
constructor(private readonly programaService: ProgramaService) {}
|
||||
constructor(private readonly programaService: ProgramaService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.programaService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.programaService.findOne(+id);
|
||||
}
|
||||
@Post()
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post()
|
||||
create(@Body() body) {
|
||||
return this.programaService.create(body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateProgramaDto: UpdateProgramaDto) {
|
||||
return this.programaService.update(+id, updateProgramaDto);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Delete(':id')
|
||||
delete(@Param('id') id:string){
|
||||
return this.programaService.delete(+id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ export class ProgramaService {
|
||||
await this.programaRepository.update(id, updateProgramaDto);
|
||||
return await this.findOne(id);
|
||||
}
|
||||
|
||||
async delete(id:number){
|
||||
return this.programaRepository.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,26 +1,39 @@
|
||||
import { Controller, Get, Body, Patch, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Body, Patch, Param, UseGuards } from '@nestjs/common';
|
||||
import { ProgramaEquipoService } from './programa_equipo.service';
|
||||
import { UpdateProgramaEquipoDto, UpdateProgramasSalaDto } from './dto/update-programa_equipo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('programa-equipo')
|
||||
export class ProgramaEquipoController {
|
||||
constructor(private readonly programaEquipoService: ProgramaEquipoService) {}
|
||||
constructor(private readonly programaEquipoService: ProgramaEquipoService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('programas/:id')
|
||||
findAllProgramByNumber(@Param('id') id: number) {
|
||||
return this.programaEquipoService.findAllProgramByNumber(+id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
|
||||
@Get('ubicacion/:id')
|
||||
findAllProgramByUbicacion(@Param('id') id: string) {
|
||||
return this.programaEquipoService.findAllProgramByUbication(id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.programaEquipoService.findOne(id);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch('equipo/:id')
|
||||
updateMachine(
|
||||
@Param('id') id: string,
|
||||
@@ -32,6 +45,8 @@ export class ProgramaEquipoController {
|
||||
);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Patch('sala')
|
||||
updateBySala(@Body() dto: UpdateProgramasSalaDto) {
|
||||
return this.programaEquipoService.updateBySala(dto.sala, dto.programas);
|
||||
|
||||
@@ -3,15 +3,20 @@ import {
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ReciboService } from './recibo.service';
|
||||
import { FindReciboByRangeDto } from './dto/create-recibo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('recibo')
|
||||
export class ReciboController {
|
||||
constructor(private readonly reciboService: ReciboService) {}
|
||||
constructor(private readonly reciboService: ReciboService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('rango')
|
||||
async findByDateRange(@Body() data: FindReciboByRangeDto) {
|
||||
return this.reciboService.findByDateRange(data.desde, data.hasta);
|
||||
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
|
||||
export enum Role {
|
||||
ADMINISTRADOR = 'ADMINISTRADOR',
|
||||
OPERADOR = 'OPERADOR',
|
||||
}
|
||||
ADMINISTRADOR = 1,
|
||||
ATENCION_USUARIOS = 2,
|
||||
SERVICIO_SOCIAL = 3,
|
||||
SUPER_ADMINISTRADOR = 4,
|
||||
PCPUMA = 5,
|
||||
}
|
||||
+2
-2
@@ -6,7 +6,7 @@ import { ROLES_KEY } from './roles.decorator';
|
||||
|
||||
@Injectable()
|
||||
export class RolesGuard implements CanActivate {
|
||||
constructor(private reflector: Reflector) {}
|
||||
constructor(private reflector: Reflector) { }
|
||||
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
|
||||
@@ -17,6 +17,6 @@ export class RolesGuard implements CanActivate {
|
||||
return true;
|
||||
}
|
||||
const { user } = context.switchToHttp().getRequest();
|
||||
return requiredRoles.some((role) => user.role?.includes(role));
|
||||
return requiredRoles.some((role) => user.role === role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { SancionService } from './sancion.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
@Controller('sancion')
|
||||
export class SancionController {
|
||||
constructor(private readonly sancionService: SancionService) {}
|
||||
constructor(private readonly sancionService: SancionService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
find() {
|
||||
return this.sancionService.find();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.sancionService.findOne(+id);
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ServicioService } from './servicio.service';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('servicio')
|
||||
export class ServicioController {
|
||||
constructor(private readonly servicioService: ServicioService) {}
|
||||
constructor(private readonly servicioService: ServicioService) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.servicioService.findAll();
|
||||
|
||||
@@ -23,7 +23,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
if (!payload || !payload.id || !payload.usuario) {
|
||||
throw new ForbiddenException('Token inválido o corrupto');
|
||||
}
|
||||
console.log(payload)
|
||||
return { id: payload.id, usuario: payload.usuario,role:payload.role};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
@@ -12,16 +11,22 @@ import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { changePasswordDto, CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
import { RolesGuard } from 'src/roles.guard';
|
||||
import { Roles } from 'src/roles.decorator';
|
||||
import { Role } from 'src/role.enum';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
constructor(private readonly userService: UserService) { }
|
||||
|
||||
|
||||
@Get()
|
||||
async getAll() {
|
||||
return this.userService.getAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Get('/perfil')
|
||||
async getAllPerfil() {
|
||||
return this.userService.getAllPerfil();
|
||||
@@ -35,15 +40,18 @@ export class UserController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/validate-token')
|
||||
getProfile(@Req() req) {
|
||||
return req.user;
|
||||
return req.user.role;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/create')
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||
@Post('/changePassword')
|
||||
async changePassword(@Body() data: changePasswordDto, @Req() req) {
|
||||
const id_usuario = req.user.id;
|
||||
|
||||
@@ -18,7 +18,7 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
return {
|
||||
global: true,
|
||||
secret: configService.get('JWT_SECRET'),
|
||||
signOptions: { expiresIn: '1h' },
|
||||
signOptions: { expiresIn: '7h' },
|
||||
};
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -27,9 +27,10 @@ export class UserService {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { usuario, password },
|
||||
});
|
||||
console.log(usuario);
|
||||
console.log(password);
|
||||
console.log(user);
|
||||
|
||||
if(user?.activo === 0){
|
||||
throw new NotFoundException(`El usuario se encuentra desactivado`);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(`El usuario o la contraseña es incorrecta`);
|
||||
@@ -43,14 +44,14 @@ export class UserService {
|
||||
|
||||
const payload = {
|
||||
id: user.id_usuario,
|
||||
usuario: user.usuario,
|
||||
role: user.perfil.perfil,
|
||||
usuario: user.nombre,
|
||||
role: user.perfil.id_perfil,
|
||||
};
|
||||
const token = await this.jwtService.signAsync(payload);
|
||||
|
||||
res.cookie('token', token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production', // en dev desactívalo
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'strict',
|
||||
path: '/',
|
||||
});
|
||||
@@ -108,7 +109,6 @@ export class UserService {
|
||||
usuario: (await this.findOne(id_usuario)).usuario,
|
||||
password: data.password,
|
||||
});
|
||||
console.log(user);
|
||||
|
||||
user.password = data.newPassword;
|
||||
return this.userRepository.save(user);
|
||||
|
||||
Reference in New Issue
Block a user