added entities and modules

This commit is contained in:
2025-10-23 10:01:00 -06:00
parent f66de9458b
commit 3bdfac1f66
21 changed files with 758 additions and 1 deletions
+4
View File
@@ -13,6 +13,7 @@ import { NombreTransaccionModule } from './modules/Monedero/nombre-transaccion/n
import { dbAT } from './database/config/AT.config';
import { dbMonedero } from './database/config/Monedero.config';
import { PagoKioscoModule } from './modules/Monedero/pago-kiosco/pago-kiosco.module';
import { AlumnoModule } from './modules/AT/alumno/student.module';
@Module({
imports: [
@@ -25,6 +26,7 @@ import { PagoKioscoModule } from './modules/Monedero/pago-kiosco/pago-kiosco.mod
TypeOrmModule.forRootAsync(dbMonedero),
////Module Monedero
PersonaModule,
TransaccionModule,
AbonoTicketModule,
@@ -33,6 +35,8 @@ import { PagoKioscoModule } from './modules/Monedero/pago-kiosco/pago-kiosco.mod
OperationsModule,
PagoPatronatoModule,
NombreTransaccionModule,
////Module AT
AlumnoModule,
],
controllers: [AppController],
providers: [AppService],
@@ -0,0 +1,72 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
OneToMany,
} from 'typeorm';
import { Alumno } from './student.entity';
import { Periodo } from './periodo.entity';
import { Equipo } from './equipo.entity';
@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[];
@OneToMany(() => Equipo, (equipo) => equipo.plataforma)
equipos: Equipo[];
}
@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;
}
@@ -0,0 +1,36 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Alumno } from './student.entity';
import { Sancion } from './sancion.entity';
@Entity({ name: 'alumno_sancion' })
export class AlumnoSancion {
@PrimaryGeneratedColumn({ name: 'id_alumno_sancion', type: 'int' })
id_alumno_sancion: number;
@Column({
name: 'fecha_inicio',
type: 'timestamp',
default: () => 'CURRENT_TIMESTAMP',
nullable: false,
})
fecha_inicio: Date;
@ManyToOne(() => Alumno, (student) => student.sanciones, {
nullable: false,
})
@JoinColumn({ name: 'id_cuenta' })
alumno: Alumno;
@ManyToOne(() => Sancion, (sancion) => sancion.sancion, {
eager: true,
nullable: false,
})
@JoinColumn({ name: 'id_sancion' })
sancion: Sancion;
}
@@ -0,0 +1,18 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { Equipo } from './equipo.entity';
@Entity({ name: 'area_ubicacion' })
export class AreaUbicacion {
@PrimaryGeneratedColumn({ name: 'id_area_ubicacion' })
id_area_ubicacion: number;
@Column({ type: 'varchar', length: 45, nullable: false })
area: string;
@Column({ type: 'char', length: 1, default: '0', nullable: false })
extra: string;
@OneToMany(() => Equipo, (equipo) => equipo.areaUbicacion)
equipos: Equipo[];
}
//IO
@@ -0,0 +1,19 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Alumno } from './student.entity';
@Entity({ name: 'carrera' })
export class Carrera {
@PrimaryGeneratedColumn({ name: 'id_carrera', type: 'int', unsigned: true })
id_carrera: number;
@Column({
name: 'carrera',
type: 'varchar',
length: 100,
nullable: false,
})
carrera: string;
@OneToMany(() => Alumno, (student) => student.carrera)
estudiantes: Alumno[];
}
@@ -0,0 +1,65 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Alumno } from './student.entity';
import { User } from './user.entity';
import { Servicio } from './servicio.entity';
import { Periodo } from './periodo.entity';
@Entity({ name: 'detalle_servicio' })
export class DetalleServicio {
@PrimaryGeneratedColumn({
name: 'id_detalle_servicio',
type: 'int',
unsigned: true,
})
id_detalle_servicio: number;
@Column('decimal', {
name: 'monto',
precision: 10,
scale: 2,
nullable: false,
})
monto: number;
@Column({ name: 'numero_hojas', type: 'int', nullable: false, default: 0 })
numero_hojas: number;
@Column({
name: 'fecha_operacion',
type: 'timestamp',
default: () => 'CURRENT_TIMESTAMP',
nullable: false,
})
fecha_operacion: Date;
@ManyToOne(() => Alumno, (alum) => alum.detalles_servicio, {
eager: true,
})
@JoinColumn({ name: 'id_cuenta' })
alum: Alumno;
@ManyToOne(() => Servicio, (id_servicio) => id_servicio.detalles_servicio, {
eager: true,
})
@JoinColumn({ name: 'id_servicio' })
servicio: Servicio;
@ManyToOne(() => User, (user) => user.detalles_servicio, {
eager: true,
})
@JoinColumn({ name: 'id_usuario' })
user: User;
@ManyToOne(() => Periodo, (periodo) => periodo.detalles_servicio, {
eager: true,
nullable: true,
})
@JoinColumn({ name: 'id_periodo' })
periodo: Periodo;
}
+57
View File
@@ -0,0 +1,57 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
Unique,
OneToMany,
} from 'typeorm';
import { Plataforma } from './alumno_inscrito.entity';
import { AreaUbicacion } from './area_ubicacion.entity';
import { ProgramaEquipo } from './programa_equipo.entity';
@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;
@OneToMany(() => ProgramaEquipo, (programaEquipo) => programaEquipo.equipo)
programaEquipos: ProgramaEquipo[];
}
+14
View File
@@ -0,0 +1,14 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { User } from './user.entity';
@Entity({ name: 'perfil' })
export class Perfil {
@PrimaryGeneratedColumn({ name: 'id_perfil', type: 'int' })
id_perfil: number;
@Column({ name: 'perfil', type: 'varchar', length: 45, nullable: false })
perfil: string;
@OneToMany(() => User, (user) => user.perfil)
usuarios: User[];
}
@@ -0,0 +1,30 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { DetalleServicio } from './detalle_servicio.entity';
@Entity({ name: 'periodo' })
export class Periodo {
@PrimaryGeneratedColumn({ name: 'id_periodo', type: 'int' })
id_periodo: number;
@Column({ type: 'char', length: 6, nullable: false })
semestre: string;
@Column({ name: 'fecha_inicio_servicio', type: 'date', nullable: false })
fecha_inicio_servicio: Date;
@Column({ name: 'fecha_fin_servicio', type: 'date', nullable: false })
fecha_fin_servicio: Date;
@Column({
type: 'bit',
width: 1,
default: () => "b'1'",
})
activo: boolean;
@OneToMany(
() => DetalleServicio,
(id_detalle_servicio) => id_detalle_servicio.periodo,
)
detalles_servicio: DetalleServicio[];
}
@@ -0,0 +1,14 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { ProgramaEquipo } from './programa_equipo.entity';
@Entity({ name: 'programa' })
export class Programa {
@PrimaryGeneratedColumn({ name: 'id_programa' })
id_programa: number;
@Column({ type: 'varchar', length: 45, nullable: false })
programa: string;
@OneToMany(() => ProgramaEquipo, (programaEquipo) => programaEquipo.programa)
programaEquipos: ProgramaEquipo[];
}
@@ -0,0 +1,25 @@
import { Entity, PrimaryColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Equipo } from './equipo.entity';
import { Programa } from './programa.entity';
@Entity('programa_equipo')
export class ProgramaEquipo {
@PrimaryColumn({ name: 'id_programa', type: 'int' })
id_programa: number;
@PrimaryColumn({ name: 'id_equipo', type: 'int' })
id_equipo: number;
@ManyToOne(() => Programa, (programa) => programa.programaEquipos, {
eager: true,
onUpdate: 'CASCADE',
})
@JoinColumn({ name: 'id_programa' })
programa: Programa;
@ManyToOne(() => Equipo, (equipo) => equipo.programaEquipos, {
onUpdate: 'CASCADE',
})
@JoinColumn({ name: 'id_equipo' })
equipo: Equipo;
}
+41
View File
@@ -0,0 +1,41 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Alumno } from './student.entity';
import { User } from './user.entity';
@Entity({ name: 'recibo' })
export class Recibo {
@PrimaryGeneratedColumn({ name: 'id_recibo', type: 'int' })
id_recibo: number;
@Column({
name: 'folio_recibo',
type: 'varchar',
length: 45,
nullable: false,
})
folio_recibo: string;
@Column({
name: 'monto',
type: 'decimal',
nullable: false,
})
monto: number;
@Column({ name: 'fecha_recibo', type: 'date', nullable: false })
fecha_recibo: Date;
@ManyToOne(() => Alumno, (alum) => alum.id_cuenta, { eager: true })
@JoinColumn({ name: 'id_cuenta' })
alum: Alumno;
@ManyToOne(() => User, (user) => user.id_usuario, { eager: true })
@JoinColumn({ name: 'id_usuario' })
user: User;
}
@@ -0,0 +1,17 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { AlumnoSancion } from './alumno_sancion.entity';
@Entity({ name: 'sancion' })
export class Sancion {
@PrimaryGeneratedColumn({ name: 'id_sancion', type: 'int' })
id_sancion: number;
@Column({ name: 'sancion', type: 'varchar', length: 45, nullable: false })
sancion: string;
@Column({ name: 'duracion', type: 'int', nullable: false })
duracion: number;
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
alumnosSancionados: AlumnoSancion[];
}
@@ -0,0 +1,17 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { DetalleServicio } from './detalle_servicio.entity';
@Entity({ name: 'servicio' })
export class Servicio {
@PrimaryGeneratedColumn({ name: 'id_servicio', type: 'int' })
id_servicio: number;
@Column({ type: 'varchar', length: 45, nullable: false })
servicio: string;
@OneToMany(
() => DetalleServicio,
(id_detalle_servicio) => id_detalle_servicio.servicio,
)
detalles_servicio: DetalleServicio[];
}
@@ -0,0 +1,86 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Carrera } from './carrera.entity';
import { DetalleServicio } from './detalle_servicio.entity';
import { AlumnoSancion } from './alumno_sancion.entity';
import { Recibo } from './recibo.entity';
@Entity({ name: 'alumno' })
export class Alumno {
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
id_cuenta: number;
@Column({ name: 'nombre', type: 'varchar', length: 300, nullable: false })
nombre: string;
@Column({
name: 'fecha_nacimiento',
type: 'varchar',
length: 8,
nullable: true,
})
fecha_nacimiento: Date | null;
@Column({ name: 'correo', type: 'varchar', length: 100, nullable: true })
correo: string | null;
@Column({
name: 'credito',
type: 'decimal',
precision: 10,
scale: 2,
default: 0.0,
})
credito: number;
@Column({
name: 'fecha_actualizacion_credito',
type: 'timestamp',
default: () => 'CURRENT_TIMESTAMP',
onUpdate: 'CURRENT_TIMESTAMP',
})
fecha_actualizacion_credito: Date;
@Column({
name: 'vigente',
type: 'enum',
enum: ['si', 'no'],
default: 'si',
})
vigente: 'si' | 'no';
@Column({ name: 'id_periodo', type: 'int', nullable: true })
id_periodo: number | null;
@Column({
name: 'fecha_registro',
type: 'datetime',
nullable: false,
})
fecha_registro: Date;
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
generacion: number | null;
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
eager: true,
nullable: true,
})
@JoinColumn({ name: 'id_carrera' })
carrera: Carrera;
@OneToMany(() => DetalleServicio, (detalle) => detalle.alum)
detalles_servicio: DetalleServicio[];
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
sanciones: AlumnoSancion[];
@OneToMany(() => Recibo, (recibo) => recibo.alum)
recibo: Recibo[];
}
+70
View File
@@ -0,0 +1,70 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Recibo } from './recibo.entity';
import { DetalleServicio } from './detalle_servicio.entity';
import { Perfil } from './perfil.entity';
@Entity({ name: 'usuario' })
export class User {
@PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' })
id_usuario: number;
@Column({ name: 'nombre', type: 'varchar', length: 45, nullable: false })
nombre: string;
@Column({
name: 'apellido_paterno',
type: 'varchar',
length: 45,
nullable: true,
})
apellido_paterno: string;
@Column({
name: 'apellido_materno',
type: 'varchar',
length: 45,
nullable: true,
})
apellido_materno: string;
@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,
})
activo: number;
@Column({ name: 'descripcion', type: 'varchar', length: 50, nullable: true })
descripcion: 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, (detalleServicio) => detalleServicio.user)
detalles_servicio: DetalleServicio[];
@OneToMany(() => Recibo, (recibo) => recibo.user)
recibo: Recibo[];
}
+36 -1
View File
@@ -1,5 +1,23 @@
import { TypeOrmModuleAsyncOptions } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Alumno } from '../AT/entities/student.entity';
import { Carrera } from '../AT/entities/carrera.entity';
import { DetalleServicio } from '../AT/entities/detalle_servicio.entity';
import { Sancion } from '../AT/entities/sancion.entity';
import { Servicio } from '../AT/entities/servicio.entity';
import { User } from '../AT/entities/user.entity';
import { Recibo } from '../AT/entities/recibo.entity';
import { Periodo } from '../AT/entities/periodo.entity';
import { AlumnoSancion } from '../AT/entities/alumno_sancion.entity';
import { Perfil } from '../AT/entities/perfil.entity';
import {
AlumnoInscrito,
Plataforma,
} from '../AT/entities/alumno_inscrito.entity';
import { Equipo } from '../AT/entities/equipo.entity';
import { AreaUbicacion } from '../AT/entities/area_ubicacion.entity';
import { ProgramaEquipo } from '../AT/entities/programa_equipo.entity';
import { Programa } from '../AT/entities/programa.entity';
export const dbAT: TypeOrmModuleAsyncOptions = {
name: 'dbAT',
@@ -12,7 +30,24 @@ export const dbAT: TypeOrmModuleAsyncOptions = {
username: config.get<string>('DB_AT_USER'),
password: config.get<string>('DB_AT_PASSWORD'),
database: config.get<string>('DB_AT_NAME'),
entities: [],
entities: [
Alumno,
AlumnoInscrito,
Plataforma,
Equipo,
AreaUbicacion,
ProgramaEquipo,
Programa,
Carrera,
DetalleServicio,
Sancion,
Servicio,
User,
Perfil,
Recibo,
Periodo,
AlumnoSancion,
],
synchronize: false,
}),
};
@@ -0,0 +1,22 @@
import { IsEmail, IsNotEmpty, IsNumber, IsString } from 'class-validator';
export class CreateStudentDto {
@IsNotEmpty()
@IsNumber()
id_cuenta: number;
@IsNotEmpty()
@IsString()
nombre: string;
@IsString()
fecha_nacimiento: string;
@IsNotEmpty()
@IsNumber()
id_carrera: number;
@IsEmail()
@IsString()
correo: string;
}
@@ -0,0 +1,18 @@
import { Controller, Get, Post, Param } from '@nestjs/common';
import { AlumnoService } from './student.service';
@Controller('student')
export class AlumnoController {
constructor(private readonly alumnoService: AlumnoService) {}
// @Post()
// async create(@Body() createStudentDto: CreateStudentDto): Promise<Alumno> {
// return this.alumnoService.create(createStudentDto);
// }
@Get(':id')
findOne(@Param('id') id: number) {
return this.alumnoService.findOne(+id);
}
}
//IO
+14
View File
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { AlumnoService } from './student.service';
import { AlumnoController } from './student.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Alumno } from 'src/database/AT/entities/student.entity';
@Module({
imports: [TypeOrmModule.forFeature([Alumno], 'dbAT')],
controllers: [AlumnoController],
providers: [AlumnoService],
exports: [AlumnoService],
})
export class AlumnoModule {}
//IO
+83
View File
@@ -0,0 +1,83 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { EntityManager, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Alumno } from 'src/database/AT/entities/student.entity';
@Injectable()
export class AlumnoService {
constructor(
@InjectRepository(Alumno, 'dbAT')
private readonly studentRepository: Repository<Alumno>,
// @InjectRepository(Carrera)
// private readonly carreraRepository: Repository<Carrera>,
) {}
// async create(data: CreateStudentDto): Promise<Alumno> {
// const { id_carrera, ...rest } = data;
// const carrera = await this.carreraRepository.findOne({
// where: { id_carrera: data.id_carrera },
// });
// if (!carrera) {
// throw new NotFoundException(`Carrera not found`);
// }
// const createStudent = { ...rest, carrera, fecha_registro: new Date() };
// const student = this.studentRepository.create(createStudent);
// return await this.studentRepository.save(student);
// }
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;
}
async findOneByName(nombre: string): Promise<Alumno> {
const student = await this.studentRepository.findOne({
where: { nombre },
});
if (!student) {
throw new NotFoundException(`Student not found`);
}
return student;
}
async GetCredit(id_cuenta: number): Promise<Alumno['credito']> {
const student = await this.findOne(id_cuenta);
return student.credito;
}
async collectCredit(
id_cuenta: number,
credit: number,
manager: EntityManager,
) {
const repo = manager.getRepository(Alumno);
return await repo
.createQueryBuilder()
.update()
.set({ credito: () => `credito - ${credit}` })
.where({ id_cuenta })
.execute();
}
async addCredit(id_cuenta: number, credit: number, manager: EntityManager) {
const repo = manager.getRepository(Alumno);
return await repo
.createQueryBuilder()
.update()
.set({ credito: () => `credito + ${credit}` })
.where({ id_cuenta })
.execute();
}
}
//IO