From 3bdfac1f66e3ca4a82d0e45ed40fba1743ac5789 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Thu, 23 Oct 2025 10:01:00 -0600 Subject: [PATCH] added entities and modules --- src/app.module.ts | 4 + .../AT/entities/alumno_inscrito.entity.ts | 72 ++++++++++++++++ .../AT/entities/alumno_sancion.entity.ts | 36 ++++++++ .../AT/entities/area_ubicacion.entity.ts | 18 ++++ src/database/AT/entities/carrera.entity.ts | 19 ++++ .../AT/entities/detalle_servicio.entity.ts | 65 ++++++++++++++ src/database/AT/entities/equipo.entity.ts | 57 ++++++++++++ src/database/AT/entities/perfil.entity.ts | 14 +++ src/database/AT/entities/periodo.entity.ts | 30 +++++++ src/database/AT/entities/programa.entity.ts | 14 +++ .../AT/entities/programa_equipo.entity.ts | 25 ++++++ src/database/AT/entities/recibo.entity.ts | 41 +++++++++ src/database/AT/entities/sancion.entity.ts | 17 ++++ src/database/AT/entities/servicio.entity.ts | 17 ++++ src/database/AT/entities/student.entity.ts | 86 +++++++++++++++++++ src/database/AT/entities/user.entity.ts | 70 +++++++++++++++ src/database/config/AT.config.ts | 37 +++++++- .../AT/alumno/dto/create-student.dto.ts | 22 +++++ src/modules/AT/alumno/student.controller.ts | 18 ++++ src/modules/AT/alumno/student.module.ts | 14 +++ src/modules/AT/alumno/student.service.ts | 83 ++++++++++++++++++ 21 files changed, 758 insertions(+), 1 deletion(-) create mode 100644 src/database/AT/entities/alumno_inscrito.entity.ts create mode 100644 src/database/AT/entities/alumno_sancion.entity.ts create mode 100644 src/database/AT/entities/area_ubicacion.entity.ts create mode 100644 src/database/AT/entities/carrera.entity.ts create mode 100644 src/database/AT/entities/detalle_servicio.entity.ts create mode 100644 src/database/AT/entities/equipo.entity.ts create mode 100644 src/database/AT/entities/perfil.entity.ts create mode 100644 src/database/AT/entities/periodo.entity.ts create mode 100644 src/database/AT/entities/programa.entity.ts create mode 100644 src/database/AT/entities/programa_equipo.entity.ts create mode 100644 src/database/AT/entities/recibo.entity.ts create mode 100644 src/database/AT/entities/sancion.entity.ts create mode 100644 src/database/AT/entities/servicio.entity.ts create mode 100644 src/database/AT/entities/student.entity.ts create mode 100644 src/database/AT/entities/user.entity.ts create mode 100644 src/modules/AT/alumno/dto/create-student.dto.ts create mode 100644 src/modules/AT/alumno/student.controller.ts create mode 100644 src/modules/AT/alumno/student.module.ts create mode 100644 src/modules/AT/alumno/student.service.ts diff --git a/src/app.module.ts b/src/app.module.ts index 997ec83..0628d1a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -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], diff --git a/src/database/AT/entities/alumno_inscrito.entity.ts b/src/database/AT/entities/alumno_inscrito.entity.ts new file mode 100644 index 0000000..a1ede41 --- /dev/null +++ b/src/database/AT/entities/alumno_inscrito.entity.ts @@ -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; +} diff --git a/src/database/AT/entities/alumno_sancion.entity.ts b/src/database/AT/entities/alumno_sancion.entity.ts new file mode 100644 index 0000000..dbaff4d --- /dev/null +++ b/src/database/AT/entities/alumno_sancion.entity.ts @@ -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; +} diff --git a/src/database/AT/entities/area_ubicacion.entity.ts b/src/database/AT/entities/area_ubicacion.entity.ts new file mode 100644 index 0000000..d38758d --- /dev/null +++ b/src/database/AT/entities/area_ubicacion.entity.ts @@ -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 diff --git a/src/database/AT/entities/carrera.entity.ts b/src/database/AT/entities/carrera.entity.ts new file mode 100644 index 0000000..95576fc --- /dev/null +++ b/src/database/AT/entities/carrera.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/detalle_servicio.entity.ts b/src/database/AT/entities/detalle_servicio.entity.ts new file mode 100644 index 0000000..16cb0cb --- /dev/null +++ b/src/database/AT/entities/detalle_servicio.entity.ts @@ -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; +} diff --git a/src/database/AT/entities/equipo.entity.ts b/src/database/AT/entities/equipo.entity.ts new file mode 100644 index 0000000..6331bd4 --- /dev/null +++ b/src/database/AT/entities/equipo.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/perfil.entity.ts b/src/database/AT/entities/perfil.entity.ts new file mode 100644 index 0000000..48da401 --- /dev/null +++ b/src/database/AT/entities/perfil.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/periodo.entity.ts b/src/database/AT/entities/periodo.entity.ts new file mode 100644 index 0000000..635eb69 --- /dev/null +++ b/src/database/AT/entities/periodo.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/programa.entity.ts b/src/database/AT/entities/programa.entity.ts new file mode 100644 index 0000000..f0ea858 --- /dev/null +++ b/src/database/AT/entities/programa.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/programa_equipo.entity.ts b/src/database/AT/entities/programa_equipo.entity.ts new file mode 100644 index 0000000..6b0999f --- /dev/null +++ b/src/database/AT/entities/programa_equipo.entity.ts @@ -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; +} diff --git a/src/database/AT/entities/recibo.entity.ts b/src/database/AT/entities/recibo.entity.ts new file mode 100644 index 0000000..fba6e73 --- /dev/null +++ b/src/database/AT/entities/recibo.entity.ts @@ -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; +} diff --git a/src/database/AT/entities/sancion.entity.ts b/src/database/AT/entities/sancion.entity.ts new file mode 100644 index 0000000..3cff273 --- /dev/null +++ b/src/database/AT/entities/sancion.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/servicio.entity.ts b/src/database/AT/entities/servicio.entity.ts new file mode 100644 index 0000000..3653e9e --- /dev/null +++ b/src/database/AT/entities/servicio.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/student.entity.ts b/src/database/AT/entities/student.entity.ts new file mode 100644 index 0000000..a872702 --- /dev/null +++ b/src/database/AT/entities/student.entity.ts @@ -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[]; +} diff --git a/src/database/AT/entities/user.entity.ts b/src/database/AT/entities/user.entity.ts new file mode 100644 index 0000000..efe4ac3 --- /dev/null +++ b/src/database/AT/entities/user.entity.ts @@ -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[]; +} diff --git a/src/database/config/AT.config.ts b/src/database/config/AT.config.ts index 3b4e686..99024d8 100644 --- a/src/database/config/AT.config.ts +++ b/src/database/config/AT.config.ts @@ -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('DB_AT_USER'), password: config.get('DB_AT_PASSWORD'), database: config.get('DB_AT_NAME'), - entities: [], + entities: [ + Alumno, + AlumnoInscrito, + Plataforma, + Equipo, + AreaUbicacion, + ProgramaEquipo, + Programa, + Carrera, + DetalleServicio, + Sancion, + Servicio, + User, + Perfil, + Recibo, + Periodo, + AlumnoSancion, + ], synchronize: false, }), }; diff --git a/src/modules/AT/alumno/dto/create-student.dto.ts b/src/modules/AT/alumno/dto/create-student.dto.ts new file mode 100644 index 0000000..d9afcbe --- /dev/null +++ b/src/modules/AT/alumno/dto/create-student.dto.ts @@ -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; +} \ No newline at end of file diff --git a/src/modules/AT/alumno/student.controller.ts b/src/modules/AT/alumno/student.controller.ts new file mode 100644 index 0000000..9cdc72a --- /dev/null +++ b/src/modules/AT/alumno/student.controller.ts @@ -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 { + // return this.alumnoService.create(createStudentDto); + // } + + @Get(':id') + findOne(@Param('id') id: number) { + return this.alumnoService.findOne(+id); + } +} +//IO diff --git a/src/modules/AT/alumno/student.module.ts b/src/modules/AT/alumno/student.module.ts new file mode 100644 index 0000000..7250974 --- /dev/null +++ b/src/modules/AT/alumno/student.module.ts @@ -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 diff --git a/src/modules/AT/alumno/student.service.ts b/src/modules/AT/alumno/student.service.ts new file mode 100644 index 0000000..a82ffb1 --- /dev/null +++ b/src/modules/AT/alumno/student.service.ts @@ -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, + // @InjectRepository(Carrera) + // private readonly carreraRepository: Repository, + ) {} + + // async create(data: CreateStudentDto): Promise { + // 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 { + 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 { + const student = await this.studentRepository.findOne({ + where: { nombre }, + }); + + if (!student) { + throw new NotFoundException(`Student not found`); + } + + return student; + } + + async GetCredit(id_cuenta: number): Promise { + 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