added bitacora and renamed things
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { Bitacora } from 'src/bitacora/entities/bitacora.entity';
|
||||
import { BitacoraMesa } from 'src/bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
import { Equipo } from 'src/equipo/entities/equipo.entity';
|
||||
import { Periodo } from 'src/periodo/entities/periodo.entity';
|
||||
@@ -73,4 +74,7 @@ export class AlumnoInscrito {
|
||||
|
||||
@OneToMany(() => BitacoraMesa, (bitacoraMesa) => bitacoraMesa.alumno_inscrito)
|
||||
bitacoras_mesa: BitacoraMesa[];
|
||||
|
||||
@OneToMany(() => Bitacora, (bitacora) => bitacora.equipo)
|
||||
bitacoras: Bitacora[];
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ import { ProgramaEquipoModule } from './programa_equipo/programa_equipo.module';
|
||||
import { ProgramaEquipo } from './programa_equipo/entities/programa_equipo.entity';
|
||||
import { BitacoraMesaModule } from './bitacora_mesa/bitacora_mesa.module';
|
||||
import { BitacoraMesa } from './bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
import { BitacoraModule } from './bitacora/bitacora.module';
|
||||
import { Bitacora } from './bitacora/entities/bitacora.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -74,6 +76,7 @@ import { BitacoraMesa } from './bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
Programa,
|
||||
ProgramaEquipo,
|
||||
BitacoraMesa,
|
||||
Bitacora
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -95,6 +98,7 @@ import { BitacoraMesa } from './bitacora_mesa/entities/bitacora_mesa.entity';
|
||||
ProgramaModule,
|
||||
ProgramaEquipoModule,
|
||||
BitacoraMesaModule,
|
||||
BitacoraModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { BitacoraController } from './bitacora.controller';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
|
||||
describe('BitacoraController', () => {
|
||||
let controller: BitacoraController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [BitacoraController],
|
||||
providers: [BitacoraService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<BitacoraController>(BitacoraController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Param,
|
||||
} from '@nestjs/common';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
|
||||
@Controller('bitacora')
|
||||
export class BitacoraController {
|
||||
constructor(private readonly bitacoraService: BitacoraService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createBitacoraDto: CreateBitacoraDto) {
|
||||
return this.bitacoraService.create(createBitacoraDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bitacoraService.findAll();
|
||||
}
|
||||
|
||||
@Get('/cuenta/:id')
|
||||
findOneByAcount(@Param('id') id: string) {
|
||||
return this.bitacoraService.findOneByAcount(+id);
|
||||
}
|
||||
|
||||
@Get('/equipo/:id')
|
||||
findOneByMachine(@Param('id') id: string) {
|
||||
return this.bitacoraService.findOneByMachine(+id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
import { BitacoraController } from './bitacora.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Bitacora } from './entities/bitacora.entity';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Bitacora])],
|
||||
controllers: [BitacoraController],
|
||||
providers: [BitacoraService],
|
||||
})
|
||||
export class BitacoraModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { BitacoraService } from './bitacora.service';
|
||||
|
||||
describe('BitacoraService', () => {
|
||||
let service: BitacoraService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [BitacoraService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<BitacoraService>(BitacoraService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateBitacoraDto } from './dto/create-bitacora.dto';
|
||||
import { UpdateBitacoraDto } from './dto/update-bitacora.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Bitacora } from './entities/bitacora.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class BitacoraService {
|
||||
constructor(
|
||||
@InjectRepository(Bitacora)
|
||||
private readonly bitacoraService: Repository<Bitacora>,
|
||||
) {}
|
||||
create(createBitacoraDto: CreateBitacoraDto) {
|
||||
return 'This action adds a new bitacora';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all bitacora`;
|
||||
}
|
||||
|
||||
async findOneByAcount(id_cuenta: number) {
|
||||
const student = await this.bitacoraService
|
||||
.createQueryBuilder('bitacora')
|
||||
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
||||
.leftJoinAndSelect('alumno.carrera', 'carrera')
|
||||
.leftJoinAndSelect('bitacora.equipo', 'equipo')
|
||||
.where('alumno.id_cuenta = :id_cuenta', { id_cuenta })
|
||||
|
||||
.andWhere(
|
||||
`TIMESTAMPDIFF(SECOND,NOW(),DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)) > 0`,
|
||||
)
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getOne();
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException('Alumno sin equipo asignado');
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
async findOneByMachine(ubicacion: number) {
|
||||
const student = await this.bitacoraService
|
||||
.createQueryBuilder('bitacora')
|
||||
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
||||
.leftJoinAndSelect('alumno.carrera', 'carrera')
|
||||
.leftJoinAndSelect('bitacora.equipo', 'equipo')
|
||||
.where('equipo.ubicacion = :ubicacion', { ubicacion })
|
||||
|
||||
.andWhere(
|
||||
`TIMESTAMPDIFF(SECOND,NOW(),DATE_ADD(bitacora.tiempo_entrada, INTERVAL bitacora.tiempo_asignado MINUTE)) > 0`,
|
||||
)
|
||||
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getOne();
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException('Equipo no asignado');
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateBitacoraDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateBitacoraDto } from './create-bitacora.dto';
|
||||
|
||||
export class UpdateBitacoraDto extends PartialType(CreateBitacoraDto) {}
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Equipo } from 'src/equipo/entities/equipo.entity';
|
||||
import { AlumnoInscrito } from 'src/alumno_inscrito/entities/alumno_inscrito.entity';
|
||||
|
||||
@Entity({ name: 'bitacora' })
|
||||
export class Bitacora {
|
||||
@PrimaryGeneratedColumn({ name: 'id_bitacora' })
|
||||
id_bitacora: number;
|
||||
|
||||
@Column({ name: 'tiempo_entrada', type: 'datetime' })
|
||||
tiempo_entrada: Date;
|
||||
|
||||
@Column({ name: 'tiempo_asignado', type: 'int' })
|
||||
tiempo_asignado: number;
|
||||
|
||||
@Column({ name: 'ubicacion', type: 'smallint', nullable: true })
|
||||
ubicacion: number;
|
||||
|
||||
@Column({
|
||||
name: 'fecha_actualizacion',
|
||||
type: 'timestamp',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
onUpdate: 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
fecha_actualizacion: Date;
|
||||
|
||||
@ManyToOne(() => Equipo, (equipo) => equipo.bitacoras, {
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'id_equipo' })
|
||||
equipo: Equipo;
|
||||
|
||||
@ManyToOne(
|
||||
() => AlumnoInscrito,
|
||||
(alumno) => alumno.bitacoras,
|
||||
{
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
},
|
||||
)
|
||||
@JoinColumn({ name: 'id_alumno_inscrito' })
|
||||
alumno_inscrito: AlumnoInscrito;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export class BitacoraMesaService {
|
||||
}
|
||||
|
||||
async findByCuenta(id_cuenta: number) {
|
||||
const alumno = await this.bitacoraMesaRepository
|
||||
const student = await this.bitacoraMesaRepository
|
||||
.createQueryBuilder('bitacora')
|
||||
.leftJoinAndSelect('bitacora.alumno_inscrito', 'alumnoInscrito')
|
||||
.leftJoinAndSelect('alumnoInscrito.alumno', 'alumno')
|
||||
@@ -36,10 +36,10 @@ export class BitacoraMesaService {
|
||||
.orderBy('bitacora.tiempo_entrada', 'DESC')
|
||||
.getOne();
|
||||
|
||||
if (!alumno) {
|
||||
if (!student) {
|
||||
throw new NotFoundException('alumno sin mesa');
|
||||
}
|
||||
|
||||
return alumno;
|
||||
return student;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Plataforma } from 'src/alumno_inscrito/entities/alumno_inscrito.entity';
|
||||
import { AreaUbicacion } from 'src/area_ubicacion/entities/area_ubicacion.entity';
|
||||
import { Bitacora } from 'src/bitacora/entities/bitacora.entity';
|
||||
import { ProgramaEquipo } from 'src/programa_equipo/entities/programa_equipo.entity';
|
||||
import {
|
||||
Entity,
|
||||
@@ -54,4 +55,7 @@ export class Equipo {
|
||||
|
||||
@OneToMany(() => ProgramaEquipo, (programaEquipo) => programaEquipo.equipo)
|
||||
programaEquipos: ProgramaEquipo[];
|
||||
|
||||
@OneToMany(() => Bitacora, (bitacora) => bitacora.equipo)
|
||||
bitacoras: Bitacora[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user