Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c00e01f63 | |||
| 2d5898d1af | |||
| 35f0381af9 | |||
| 8b2266cb51 | |||
| 38211e253e | |||
| 76b96f0be3 | |||
| 22be291a80 | |||
| ecc8858f90 | |||
| 3c23ad8a01 | |||
| 76a86ae3b0 | |||
| c34ea0c1bb | |||
| 26134397fa | |||
| ade52ac8c2 | |||
| dbd3657acb | |||
| 3a3e145642 | |||
| aae6cb8704 | |||
| 549d0645aa | |||
| b5bd666934 | |||
| 840887c97d | |||
| 303bdc655d | |||
| 8baec559a8 | |||
| 3bdfac1f66 | |||
| f66de9458b | |||
| ec1dd723d2 | |||
| 5be67d6904 | |||
| 3e64e6b04f | |||
| 802249f89c | |||
| 11819bb31c | |||
| 3558605533 | |||
| 9b8221509f | |||
| c085e7ba02 | |||
| 3f10078114 | |||
| a975b89a85 | |||
| 496b3ab367 | |||
| d9b2483bc9 | |||
| d42fb0e088 | |||
| 5c0f8cc0ba | |||
| d0dd882cf3 | |||
| 0d2ba5d2be | |||
| cb766083e6 | |||
| 2f6137d874 | |||
| 94db1f7557 | |||
| ef4d20bfb7 | |||
| 2dc90a4ac8 | |||
| 351b5c6643 | |||
| 28dbf45756 | |||
| a1bed1dedc | |||
| 95913a8ecc | |||
| 3acb35437d | |||
| 198d0ace01 | |||
| 2e40e4366e | |||
| 10d71b19d1 | |||
| fd381b5c29 | |||
| ed371ee497 | |||
| db331d8255 | |||
| 05129381be | |||
| 935a8384a7 |
@@ -0,0 +1,23 @@
|
||||
GOOGLE_CLIENT_ID=164998630411-i53dmn6cjibjv7o2llq32fn2hb1cdcnm.apps.googleusercontent.com
|
||||
GOOGLE_CLIENT_SECRET=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
|
||||
GOOGLE_CALLBACK_URL=http://localhost:3000/persona/google/callback
|
||||
|
||||
JWT_SECRET=superSecreto
|
||||
JWT_EXPIRES_IN=3600s
|
||||
|
||||
DB_MONEDERO_HOST=
|
||||
DB_MONEDERO_PORT=
|
||||
DB_MONEDERO_USER=
|
||||
DB_MONEDERO_PASS=
|
||||
DB_MONEDERO_NAME=
|
||||
|
||||
DB_AT_HOST=
|
||||
DB_AT_PORT=
|
||||
DB_AT_USER=
|
||||
DB_AT_PASSWORD=
|
||||
DB_AT_NAME=
|
||||
|
||||
FRONTEND_URL=
|
||||
|
||||
USER=pruebas
|
||||
PASS=123456
|
||||
Generated
+1320
-533
File diff suppressed because it is too large
Load Diff
+20
-1
@@ -21,10 +21,25 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/jwt": "^11.0.1",
|
||||
"@nestjs/mapped-types": "*",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"axios": "^1.12.2",
|
||||
"bcrypt": "^6.0.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.2",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"mysql2": "^3.15.2",
|
||||
"passport": "^0.7.0",
|
||||
"passport-google-oauth20": "^2.0.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.27"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
@@ -32,9 +47,13 @@
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@types/bcrypt": "^6.0.0",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/passport": "^1.0.17",
|
||||
"@types/passport-google-oauth20": "^2.0.16",
|
||||
"@types/passport-jwt": "^4.0.1",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
|
||||
+38
-1
@@ -1,9 +1,46 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { PersonaModule } from './modules/Monedero/persona/persona.module';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TransaccionModule } from './modules/Monedero/transaccion/transaccion.module';
|
||||
import { AbonoTicketModule } from './modules/Monedero/abono-ticket/abono-ticket.module';
|
||||
import { KioscoModule } from './modules/Monedero/kiosco/kiosco.module';
|
||||
import { OperationsModule } from './operations/operations.module';
|
||||
import { PagoPatronatoModule } from './modules/Monedero/pago-patronato/pago-patronato.module';
|
||||
import { NombreTransaccionModule } from './modules/Monedero/nombre-transaccion/nombre-transaccion.module';
|
||||
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';
|
||||
import { AlumnoInscritoModule } from './modules/AT/alumno_inscrito/alumno_inscrito.module';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
envFilePath: '.env',
|
||||
}),
|
||||
|
||||
TypeOrmModule.forRootAsync(dbAT),
|
||||
|
||||
TypeOrmModule.forRootAsync(dbMonedero),
|
||||
|
||||
////Module Monedero
|
||||
PersonaModule,
|
||||
TransaccionModule,
|
||||
AbonoTicketModule,
|
||||
PagoKioscoModule,
|
||||
KioscoModule,
|
||||
OperationsModule,
|
||||
PagoPatronatoModule,
|
||||
NombreTransaccionModule,
|
||||
|
||||
////Module AT
|
||||
AlumnoModule,
|
||||
AlumnoInscritoModule,
|
||||
],
|
||||
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;
|
||||
}
|
||||
@@ -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[];
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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[];
|
||||
}
|
||||
@@ -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[];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Transaccion } from 'src/database/Monedero/entities/transaccion.entity'; // ajusta la ruta según tu estructura
|
||||
|
||||
@Entity('AbonoTicket')
|
||||
export class AbonoTicket {
|
||||
@PrimaryGeneratedColumn({ name: 'idTickect', type: 'int' })
|
||||
idTickect: number;
|
||||
|
||||
@ManyToOne(() => Transaccion, (transaccion) => transaccion.abonos, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({ name: 'idTransaccion' })
|
||||
transaccion: Transaccion;
|
||||
|
||||
@Column({ type: 'varchar', length: 100 })
|
||||
folio: string;
|
||||
|
||||
@Column({ type: 'int' })
|
||||
monto: number;
|
||||
|
||||
@Column({ type: 'datetime' })
|
||||
fecha: Date;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { PagoKiosco } from 'src/database/Monedero/entities/pago-kiosco.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
|
||||
|
||||
@Entity('Kiosco')
|
||||
export class Kiosco {
|
||||
@PrimaryGeneratedColumn({ type: 'int' })
|
||||
idKiosco: number;
|
||||
|
||||
@Column({ type: 'varchar', length: 100 })
|
||||
responsable: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100 })
|
||||
lugar: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 20 })
|
||||
token: string;
|
||||
|
||||
@Column({ type: 'tinyint', width: 1, default: 0 })
|
||||
useToken: boolean;
|
||||
|
||||
@Column({ type: 'datetime', nullable: true })
|
||||
dateToken: Date;
|
||||
|
||||
@Column({ type: 'int' })
|
||||
saldo: number;
|
||||
|
||||
@Column({ type: 'varchar', length: 20 })
|
||||
status: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 100 })
|
||||
usuario: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 250 })
|
||||
password: string;
|
||||
|
||||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
||||
fechaCreado: Date;
|
||||
|
||||
@Column({ type: 'tinyint', width: 1, default: 0 })
|
||||
activado: boolean;
|
||||
|
||||
@OneToMany(() => PagoKiosco, (pagokiosco) => pagokiosco.kiosco)
|
||||
pagoKiosco: PagoKiosco[];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Transaccion } from 'src/database/Monedero/entities/transaccion.entity';
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('NombreTransaccion')
|
||||
export class NombreTransaccion {
|
||||
@PrimaryGeneratedColumn()
|
||||
idNombreTransaccion: number;
|
||||
|
||||
@Column({ type: 'varchar', length: '50' })
|
||||
nombreTransaccion: string;
|
||||
|
||||
@OneToMany(() => Transaccion, (transaccion) => transaccion.nombreTransaccion)
|
||||
transacciones: Transaccion[];
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from 'typeorm';
|
||||
import { Transaccion } from 'src/database/Monedero/entities/transaccion.entity'; // ajusta la ruta
|
||||
import { PagoPatronato } from 'src/database/Monedero/entities/pago-patronato.entity';
|
||||
import { Kiosco } from './kiosco.entity';
|
||||
|
||||
@Entity('PagoKiosco')
|
||||
export class PagoKiosco {
|
||||
@PrimaryGeneratedColumn({ name: 'idPagoKiosco', type: 'int' })
|
||||
idPagoKiosco: number;
|
||||
|
||||
@ManyToOne(() => Transaccion, (transacccion) => transacccion.pagoKiosco, {
|
||||
onDelete: 'CASCADE',
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'idTransaccion' })
|
||||
transaccion: Transaccion;
|
||||
|
||||
@Column({ type: 'int' })
|
||||
monto: number;
|
||||
|
||||
@Column({ type: 'datetime' })
|
||||
fecha: Date;
|
||||
|
||||
@Column({ type: 'tinyint', width: 1, default: 0 })
|
||||
patronatoCompletado: boolean;
|
||||
|
||||
@Column({ type: 'tinyint', width: 1, default: 0 })
|
||||
pagoPatronatoCreado: boolean;
|
||||
|
||||
@Column({ type: 'tinyint', width: 1, default: 0 })
|
||||
ticketCreado: boolean;
|
||||
|
||||
@Column({ type: 'tinyint', width: 1, default: 0 })
|
||||
ticketEnviado: boolean;
|
||||
|
||||
@ManyToOne(() => PagoPatronato, (pago) => pago.pagoKiosco, {
|
||||
onDelete: 'CASCADE',
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'idPagoPatronato' })
|
||||
pagoPatronato: PagoPatronato;
|
||||
|
||||
@ManyToOne(() => Kiosco, (kiosco) => kiosco.pagoKiosco, {
|
||||
onDelete: 'CASCADE',
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'idKiosco' })
|
||||
kiosco: Kiosco;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { PagoKiosco } from 'src/database/Monedero/entities/pago-kiosco.entity';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
|
||||
|
||||
@Entity('PagoPatronato')
|
||||
export class PagoPatronato {
|
||||
@PrimaryGeneratedColumn({ name: 'idPagoPatronato', type: 'int' })
|
||||
idPagoPatronato: number;
|
||||
|
||||
@Column({ name: 'numeroTicket', type: 'varchar', length: 30 })
|
||||
numeroTicket: string;
|
||||
|
||||
@Column({ name: 'folio', type: 'varchar', length: 30 })
|
||||
folio: string;
|
||||
|
||||
@Column({ name: 'importeLetra', type: 'varchar', length: 50 })
|
||||
importeLetra: string;
|
||||
|
||||
@Column({ name: 'fechaPago', type: 'varchar', length: 30 })
|
||||
fechaPago: string;
|
||||
|
||||
@Column({ name: 'fechaEnvio', type: 'datetime' })
|
||||
fechaEnvio: Date;
|
||||
|
||||
@OneToMany(() => PagoKiosco, (pagokiosco) => pagokiosco.pagoPatronato)
|
||||
pagoKiosco: PagoKiosco[];
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Transaccion } from 'src/database/Monedero/entities/transaccion.entity';
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity({ name: 'Persona' })
|
||||
export class Persona {
|
||||
@PrimaryGeneratedColumn()
|
||||
idPersona: number;
|
||||
|
||||
@Column({ length: 50 })
|
||||
nombre: string;
|
||||
|
||||
@Column({ length: 50 })
|
||||
apellidoP: string;
|
||||
|
||||
@Column({ length: 50 })
|
||||
apellidoM: string;
|
||||
|
||||
@Column({ length: 150 })
|
||||
password: string;
|
||||
|
||||
@Column({ length: 150, nullable: true })
|
||||
passwordTem?: string;
|
||||
|
||||
@Column({ type: 'datetime', nullable: true })
|
||||
fechaPasswordTem?: Date;
|
||||
|
||||
@Column({ length: 100, unique: true })
|
||||
correo: string;
|
||||
|
||||
@Column({ length: 100, nullable: true })
|
||||
carreraAds?: string;
|
||||
|
||||
@Column({ type: 'float', default: 0 })
|
||||
cantidadCuenta: number;
|
||||
|
||||
@Column({ length: 150, unique: true })
|
||||
usuario: string;
|
||||
|
||||
@Column({ length: 50, nullable: true })
|
||||
numeroIdentificar?: string;
|
||||
|
||||
@Column({ length: 50 })
|
||||
tipoUsuario: string;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
correoEnviado: boolean;
|
||||
|
||||
@Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' })
|
||||
fechaRegistro: Date;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
cambioPasswordReq: boolean;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
primerLogin: boolean;
|
||||
|
||||
@OneToMany(() => Transaccion, (transaccion) => transaccion.persona)
|
||||
transacciones: Transaccion[];
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { Persona } from 'src/database/Monedero/entities/persona.entity'; // ajusta la ruta según tu estructura
|
||||
import { AbonoTicket } from 'src/database/Monedero/entities/abono-ticket.entity';
|
||||
import { PagoKiosco } from 'src/database/Monedero/entities/pago-kiosco.entity';
|
||||
import { NombreTransaccion } from 'src/database/Monedero/entities/nombre-transaccion.entity';
|
||||
|
||||
@Entity('Transaccion')
|
||||
export class Transaccion {
|
||||
@PrimaryGeneratedColumn({ name: 'idTransaccion', type: 'int' })
|
||||
idTransaccion: number;
|
||||
|
||||
@ManyToOne(
|
||||
() => NombreTransaccion,
|
||||
(nombreTransaccion) => nombreTransaccion.transacciones,
|
||||
{ eager: true },
|
||||
)
|
||||
@JoinColumn({ name: 'idNombreTransaccion' })
|
||||
nombreTransaccion: NombreTransaccion;
|
||||
|
||||
@ManyToOne(() => Persona, (people) => people.transacciones, { eager: true })
|
||||
@JoinColumn({ name: 'idPersona' })
|
||||
persona: Persona;
|
||||
|
||||
@Column({ type: 'datetime' })
|
||||
fecha: Date;
|
||||
|
||||
@Column({ type: 'float' })
|
||||
saldoDespuesTransaccion: number;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: ['Impresion', 'PagoKiosco', 'AbonoTickect', 'Inscripcion'],
|
||||
})
|
||||
tipoTransaccion: number;
|
||||
|
||||
@OneToMany(() => AbonoTicket, (abono) => abono.transaccion)
|
||||
abonos: AbonoTicket[];
|
||||
|
||||
@OneToMany(() => PagoKiosco, (pago) => pago.kiosco)
|
||||
pagoKiosco: PagoKiosco[];
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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',
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: async (config: ConfigService) => ({
|
||||
type: 'mariadb',
|
||||
host: config.get<string>('DB_AT_HOST'),
|
||||
port: config.get<number>('DB_AT_PORT'),
|
||||
username: config.get<string>('DB_AT_USER'),
|
||||
password: config.get<string>('DB_AT_PASSWORD'),
|
||||
database: config.get<string>('DB_AT_NAME'),
|
||||
entities: [
|
||||
Alumno,
|
||||
AlumnoInscrito,
|
||||
Plataforma,
|
||||
Equipo,
|
||||
AreaUbicacion,
|
||||
ProgramaEquipo,
|
||||
Programa,
|
||||
Carrera,
|
||||
DetalleServicio,
|
||||
Sancion,
|
||||
Servicio,
|
||||
User,
|
||||
Perfil,
|
||||
Recibo,
|
||||
Periodo,
|
||||
AlumnoSancion,
|
||||
],
|
||||
synchronize: false,
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
import { TypeOrmModuleAsyncOptions } from '@nestjs/typeorm';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AbonoTicket } from '../Monedero/entities/abono-ticket.entity';
|
||||
import { Kiosco } from '../Monedero/entities/kiosco.entity';
|
||||
import { NombreTransaccion } from '../Monedero/entities/nombre-transaccion.entity';
|
||||
import { PagoKiosco } from '../Monedero/entities/pago-kiosco.entity';
|
||||
import { PagoPatronato } from '../Monedero/entities/pago-patronato.entity';
|
||||
import { Persona } from '../Monedero/entities/persona.entity';
|
||||
import { Transaccion } from '../Monedero/entities/transaccion.entity';
|
||||
|
||||
export const dbMonedero: TypeOrmModuleAsyncOptions = {
|
||||
name: 'dbMonedero',
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: async (config: ConfigService) => ({
|
||||
type: 'mariadb',
|
||||
host: config.get<string>('DB_MONEDERO_HOST'),
|
||||
port: config.get<number>('DB_MONEDERO_PORT'),
|
||||
username: config.get<string>('DB_MONEDERO_USER'),
|
||||
password: config.get<string>('DB_MONEDERO_PASS'),
|
||||
database: config.get<string>('DB_MONEDERO_NAME'),
|
||||
entities: [
|
||||
AbonoTicket,
|
||||
Kiosco,
|
||||
NombreTransaccion,
|
||||
PagoKiosco,
|
||||
PagoPatronato,
|
||||
Persona,
|
||||
Transaccion,
|
||||
],
|
||||
synchronize: false,
|
||||
}),
|
||||
};
|
||||
@@ -1,8 +1,13 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.enableCors({});
|
||||
app.useGlobalPipes(new ValidationPipe());
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
|
||||
console.log(`successfully connected at the port ${process.env.PORT ?? 3000}`);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { IsDate, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional, 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;
|
||||
}
|
||||
|
||||
export class CreateAlumnoDto {
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
nombre: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDate()
|
||||
fecha_nacimiento?: Date | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
correo?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
credito?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(['si', 'no'])
|
||||
vigente?: 'si' | 'no';
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
id_periodo?: number | null;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsDate()
|
||||
fecha_registro: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
generacion?: number | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
id_carrera?: number | null;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Controller, Get, 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
|
||||
@@ -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
|
||||
@@ -0,0 +1,95 @@
|
||||
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 alumnoRepository: Repository<Alumno>,
|
||||
// @InjectRepository(Carrera, 'dbAT')
|
||||
// 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.alumnoRepository.create(createStudent);
|
||||
// return await this.alumnoRepository.save(student);
|
||||
// }
|
||||
|
||||
async findOne(id_cuenta: number): Promise<Alumno> {
|
||||
const student = await this.alumnoRepository.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.alumnoRepository.findOne({
|
||||
where: { nombre },
|
||||
});
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Alumno not found`);
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
async findOneById(id_cuenta: number): Promise<Alumno> {
|
||||
const student = await this.alumnoRepository.findOne({
|
||||
where: { id_cuenta },
|
||||
});
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException('Alumno 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
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { AlumnoInscrito } from 'src/database/AT/entities/alumno_inscrito.entity';
|
||||
|
||||
@Controller('alumno-inscrito')
|
||||
export class AlumnoInscritoController {
|
||||
constructor(private readonly alumnoInscritoService: AlumnoInscritoService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id_cuenta')
|
||||
async findByAlumno(
|
||||
@Param('id_cuenta') id_cuenta: number,
|
||||
): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoService.findByAlumno(id_cuenta);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AlumnoInscritoService } from './alumno_inscrito.service';
|
||||
import { AlumnoInscritoController } from './alumno_inscrito.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AlumnoInscrito } from 'src/database/AT/entities/alumno_inscrito.entity';
|
||||
import { PeriodoModule } from '../periodo/periodo.module';
|
||||
import { PlataformaModule } from '../plataforma/periodo.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AlumnoInscrito], 'dbAT'),PeriodoModule,PlataformaModule],
|
||||
controllers: [AlumnoInscritoController],
|
||||
providers: [AlumnoInscritoService],
|
||||
exports: [AlumnoInscritoService],
|
||||
})
|
||||
export class AlumnoInscritoModule {}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { AlumnoInscrito } from 'src/database/AT/entities/alumno_inscrito.entity';
|
||||
import { PeriodoService } from '../periodo/periodo.service';
|
||||
import { CreateAlumnoDto } from '../alumno/dto/create-student.dto';
|
||||
import { PlataformaService } from '../plataforma/periodo.service';
|
||||
|
||||
@Injectable()
|
||||
export class AlumnoInscritoService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoInscrito, 'dbAT')
|
||||
private readonly alumnoInscritoRepo: Repository<AlumnoInscrito>,
|
||||
private readonly periodoService: PeriodoService,
|
||||
private readonly plataformaService: PlataformaService,
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoRepo.find({
|
||||
relations: ['alumno', 'periodo', 'plataforma'],
|
||||
});
|
||||
}
|
||||
|
||||
async findByAlumno(id_cuenta: number): Promise<AlumnoInscrito[]> {
|
||||
return this.alumnoInscritoRepo.find({
|
||||
where: { alumno: { id_cuenta } },
|
||||
relations: ['alumno', 'periodo', 'plataforma'],
|
||||
});
|
||||
}
|
||||
|
||||
async create(
|
||||
alumno: CreateAlumnoDto,
|
||||
namePlataforma: string,
|
||||
): Promise<AlumnoInscrito> {
|
||||
const periodo = await this.periodoService.getLatestPeriodo();
|
||||
|
||||
const plataforma = await this.plataformaService.getByName(namePlataforma);
|
||||
|
||||
const existing = await this.alumnoInscritoRepo.findOne({
|
||||
where: {
|
||||
alumno: { id_cuenta: alumno.id_cuenta },
|
||||
periodo: { id_periodo: periodo?.id_periodo },
|
||||
plataforma: { id_plataforma: plataforma?.id_plataforma },
|
||||
},
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
throw new BadRequestException(
|
||||
'El alumno ya está inscrito en este periodo y plataforma',
|
||||
);
|
||||
}
|
||||
|
||||
const alumnoInscrito = this.alumnoInscritoRepo.create({
|
||||
alumno: { id_cuenta: alumno.id_cuenta },
|
||||
periodo: { id_periodo: periodo.id_periodo },
|
||||
plataforma: { id_plataforma: plataforma.id_plataforma },
|
||||
});
|
||||
|
||||
return this.alumnoInscritoRepo.save(alumnoInscrito);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { IsNotEmpty, IsNumber, IsBoolean } from 'class-validator';
|
||||
|
||||
export class CreateAlumnoInscritoDto {
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_periodo?: number;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNumber()
|
||||
id_plataforma: number;
|
||||
|
||||
@IsBoolean()
|
||||
realizo_pago?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
platica?: boolean;
|
||||
|
||||
@IsNumber()
|
||||
tiempo_disponible?: number;
|
||||
|
||||
@IsBoolean()
|
||||
ad?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
IsString,
|
||||
Length,
|
||||
IsDateString,
|
||||
IsOptional,
|
||||
IsBoolean,
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreatePeriodoDto {
|
||||
@IsString()
|
||||
@Length(6, 6)
|
||||
semestre: string;
|
||||
|
||||
@IsDateString()
|
||||
fecha_inicio_servicio: string;
|
||||
|
||||
@IsDateString()
|
||||
fecha_fin_servicio: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
activo?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('periodo')
|
||||
export class PeriodoController {}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { PeriodoController } from './periodo.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Periodo } from 'src/database/AT/entities/periodo.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Periodo], 'dbAT')],
|
||||
controllers: [PeriodoController],
|
||||
providers: [PeriodoService],
|
||||
exports: [PeriodoService],
|
||||
})
|
||||
export class PeriodoModule {}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Periodo } from 'src/database/AT/entities/periodo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class PeriodoService {
|
||||
constructor(
|
||||
@InjectRepository(Periodo, 'dbAT')
|
||||
private readonly periodoRepository: Repository<Periodo>,
|
||||
) {}
|
||||
|
||||
async getById(id_periodo: number): Promise<Periodo> {
|
||||
const periodo = await this.periodoRepository.findOne({
|
||||
where: { id_periodo },
|
||||
});
|
||||
|
||||
if (!periodo) {
|
||||
throw new NotFoundException('periodo no encontrado');
|
||||
}
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async getLatestPeriodo(): Promise<Periodo> {
|
||||
const periodos = await this.periodoRepository.find({
|
||||
order: { id_periodo: 'DESC' },
|
||||
take: 1,
|
||||
});
|
||||
|
||||
const periodo = periodos[0];
|
||||
|
||||
if (!periodo) {
|
||||
throw new NotFoundException('No hay periodos registrados');
|
||||
}
|
||||
|
||||
return periodo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class PlataformaDto {}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { PlataformaService } from './periodo.service';
|
||||
|
||||
@Controller('plataforma')
|
||||
export class PlataformaController {
|
||||
constructor(private readonly plataformaService:PlataformaService){}
|
||||
|
||||
//test
|
||||
@Get()
|
||||
GetPlataforma(){
|
||||
return this.plataformaService.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PlataformaController } from './periodo.controller';
|
||||
import { PlataformaService } from './periodo.service';
|
||||
import { Plataforma } from 'src/database/AT/entities/alumno_inscrito.entity';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Plataforma],'dbAT')],
|
||||
controllers: [PlataformaController],
|
||||
providers: [PlataformaService],
|
||||
exports: [PlataformaService],
|
||||
})
|
||||
export class PlataformaModule {}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Plataforma } from 'src/database/AT/entities/alumno_inscrito.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class PlataformaService {
|
||||
constructor(
|
||||
@InjectRepository(Plataforma,"dbAT")
|
||||
private readonly plataformaRepository: Repository<Plataforma>,
|
||||
) {}
|
||||
|
||||
async getAll(){
|
||||
return this.plataformaRepository.find()
|
||||
}
|
||||
|
||||
async getByName(nombre: string): Promise<Plataforma> {
|
||||
const plataforma = await this.plataformaRepository.findOne({
|
||||
where: { nombre },
|
||||
});
|
||||
|
||||
if (!plataforma) {
|
||||
throw new NotFoundException('plataforma no encontrado');
|
||||
}
|
||||
return plataforma;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AbonoTicketController } from './abono-ticket.controller';
|
||||
import { AbonoTicketService } from './abono-ticket.service';
|
||||
|
||||
describe('AbonoTicketController', () => {
|
||||
let controller: AbonoTicketController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AbonoTicketController],
|
||||
providers: [AbonoTicketService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AbonoTicketController>(AbonoTicketController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Controller, Get, Post, Body } from '@nestjs/common';
|
||||
import { AbonoTicketService } from './abono-ticket.service';
|
||||
import { CreateAbonoTicketDto } from './dto/create-abono-ticket.dto';
|
||||
|
||||
@Controller('abono-ticket')
|
||||
export class AbonoTicketController {
|
||||
constructor(private readonly abonoTicketService: AbonoTicketService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createAbonoTicketDto: CreateAbonoTicketDto) {
|
||||
return this.abonoTicketService.create(createAbonoTicketDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
all() {
|
||||
return this.abonoTicketService.find();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AbonoTicketService } from './abono-ticket.service';
|
||||
import { AbonoTicketController } from './abono-ticket.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AbonoTicket } from '../../../database/Monedero/entities/abono-ticket.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AbonoTicket], 'dbMonedero')],
|
||||
controllers: [AbonoTicketController],
|
||||
providers: [AbonoTicketService],
|
||||
exports: [AbonoTicketService],
|
||||
})
|
||||
export class AbonoTicketModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AbonoTicketService } from './abono-ticket.service';
|
||||
|
||||
describe('AbonoTicketService', () => {
|
||||
let service: AbonoTicketService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AbonoTicketService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AbonoTicketService>(AbonoTicketService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateAbonoTicketDto } from './dto/create-abono-ticket.dto';
|
||||
import { AbonoTicket } from '../../../database/Monedero/entities/abono-ticket.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Transaccion } from 'src/database/Monedero/entities/transaccion.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AbonoTicketService {
|
||||
constructor(
|
||||
@InjectRepository(AbonoTicket, 'dbMonedero')
|
||||
private readonly abonoTicketRepository: Repository<AbonoTicket>,
|
||||
) {}
|
||||
|
||||
async find() {
|
||||
return await this.abonoTicketRepository.find();
|
||||
}
|
||||
|
||||
async findByTransaccion(transaccion: Transaccion): Promise<AbonoTicket> {
|
||||
const abonoTicket = await this.abonoTicketRepository.findOne({
|
||||
where: { transaccion },
|
||||
});
|
||||
if (!abonoTicket) {
|
||||
throw new NotFoundException('abonoTicket not found');
|
||||
}
|
||||
return abonoTicket;
|
||||
}
|
||||
|
||||
async create(createAbonoTicketDto: CreateAbonoTicketDto) {
|
||||
const create = this.abonoTicketRepository.create(createAbonoTicketDto);
|
||||
await this.abonoTicketRepository.save(create);
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateAbonoTicketDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateAbonoTicketDto } from './create-abono-ticket.dto';
|
||||
|
||||
export class UpdateAbonoTicketDto extends PartialType(CreateAbonoTicketDto) {}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateKioscoDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateKioscoDto } from './create-kiosco.dto';
|
||||
|
||||
export class UpdateKioscoDto extends PartialType(CreateKioscoDto) {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { KioscoController } from './kiosco.controller';
|
||||
import { KioscoService } from './kiosco.service';
|
||||
|
||||
describe('KioscoController', () => {
|
||||
let controller: KioscoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [KioscoController],
|
||||
providers: [KioscoService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<KioscoController>(KioscoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { KioscoService } from './kiosco.service';
|
||||
import { CreateKioscoDto } from './dto/create-kiosco.dto';
|
||||
import { UpdateKioscoDto } from './dto/update-kiosco.dto';
|
||||
|
||||
@Controller('kiosco')
|
||||
export class KioscoController {
|
||||
constructor(private readonly kioscoService: KioscoService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.kioscoService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { KioscoService } from './kiosco.service';
|
||||
import { KioscoController } from './kiosco.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Kiosco } from 'src/database/Monedero/entities/kiosco.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Kiosco], 'dbMonedero')],
|
||||
controllers: [KioscoController],
|
||||
providers: [KioscoService],
|
||||
exports: [KioscoService],
|
||||
})
|
||||
export class KioscoModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { KioscoService } from './kiosco.service';
|
||||
|
||||
describe('KioscoService', () => {
|
||||
let service: KioscoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [KioscoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<KioscoService>(KioscoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateKioscoDto } from './dto/create-kiosco.dto';
|
||||
import { UpdateKioscoDto } from './dto/update-kiosco.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Kiosco } from 'src/database/Monedero/entities/kiosco.entity';
|
||||
|
||||
@Injectable()
|
||||
export class KioscoService {
|
||||
constructor(
|
||||
@InjectRepository(Kiosco, 'dbMonedero')
|
||||
private readonly KioscoRepository: Repository<Kiosco>,
|
||||
) {}
|
||||
findAll() {
|
||||
return this.KioscoRepository.find();
|
||||
}
|
||||
|
||||
async findById(idKiosco: number): Promise<Kiosco> {
|
||||
const kiosco = await this.KioscoRepository.findOne({ where: { idKiosco } });
|
||||
|
||||
if (!kiosco) {
|
||||
throw new NotFoundException('kiosco not found');
|
||||
}
|
||||
|
||||
return kiosco;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateNombreTransaccionDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateNombreTransaccionDto } from './create-nombre-transaccion.dto';
|
||||
|
||||
export class UpdateNombreTransaccionDto extends PartialType(CreateNombreTransaccionDto) {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NombreTransaccionController } from './nombre-transaccion.controller';
|
||||
import { NombreTransaccionService } from './nombre-transaccion.service';
|
||||
|
||||
describe('NombreTransaccionController', () => {
|
||||
let controller: NombreTransaccionController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [NombreTransaccionController],
|
||||
providers: [NombreTransaccionService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<NombreTransaccionController>(NombreTransaccionController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { NombreTransaccionService } from './nombre-transaccion.service';
|
||||
|
||||
@Controller('nombre-transaccion')
|
||||
export class NombreTransaccionController {
|
||||
constructor(
|
||||
private readonly nombreTransaccionService: NombreTransaccionService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.nombreTransaccionService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { NombreTransaccionService } from './nombre-transaccion.service';
|
||||
import { NombreTransaccionController } from './nombre-transaccion.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { NombreTransaccion } from 'src/database/Monedero/entities/nombre-transaccion.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([NombreTransaccion], 'dbMonedero')],
|
||||
controllers: [NombreTransaccionController],
|
||||
providers: [NombreTransaccionService],
|
||||
exports: [NombreTransaccionService],
|
||||
})
|
||||
export class NombreTransaccionModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NombreTransaccionService } from './nombre-transaccion.service';
|
||||
|
||||
describe('NombreTransaccionService', () => {
|
||||
let service: NombreTransaccionService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [NombreTransaccionService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<NombreTransaccionService>(NombreTransaccionService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { NombreTransaccion } from 'src/database/Monedero/entities/nombre-transaccion.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class NombreTransaccionService {
|
||||
constructor(
|
||||
@InjectRepository(NombreTransaccion, 'dbMonedero')
|
||||
private readonly nombreTransaccionRepository: Repository<NombreTransaccion>,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.nombreTransaccionRepository.find();
|
||||
}
|
||||
|
||||
async findById(idNombreTransaccion: number): Promise<NombreTransaccion> {
|
||||
const nameTransaccion = await this.nombreTransaccionRepository.findOne({
|
||||
where: { idNombreTransaccion },
|
||||
});
|
||||
|
||||
if (!nameTransaccion) {
|
||||
throw new NotFoundException('name transaction not found');
|
||||
}
|
||||
|
||||
return nameTransaccion;
|
||||
}
|
||||
|
||||
async findByName(nombreTransaccion: string): Promise<NombreTransaccion> {
|
||||
const transaccion = await this.nombreTransaccionRepository.findOne({
|
||||
where: { nombreTransaccion },
|
||||
});
|
||||
|
||||
if (!transaccion) {
|
||||
throw new NotFoundException('transaction not found');
|
||||
}
|
||||
|
||||
return transaccion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { IsBoolean, IsDateString, IsNumber } from 'class-validator';
|
||||
|
||||
export class CreatePagoKioscoDto {
|
||||
@IsNumber()
|
||||
idTransaccion: number;
|
||||
|
||||
@IsNumber()
|
||||
monto: number;
|
||||
|
||||
@IsDateString()
|
||||
fecha: string;
|
||||
|
||||
@IsNumber()
|
||||
idKiosco: number;
|
||||
|
||||
@IsBoolean()
|
||||
pagoPatronatoCreado: boolean;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PagoKioscoController } from './pago-kiosco.controller';
|
||||
import { PagoKioscoService } from './pago-kiosco.service';
|
||||
|
||||
describe('PagoKioscoController', () => {
|
||||
let controller: PagoKioscoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PagoKioscoController],
|
||||
providers: [PagoKioscoService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PagoKioscoController>(PagoKioscoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { PagoKioscoService } from './pago-kiosco.service';
|
||||
import { CreatePagoKioscoDto } from './dto/create-pago-kiosco.dto';
|
||||
|
||||
@Controller('pago-kiosco')
|
||||
export class PagoKioscoController {
|
||||
constructor(private readonly pagoKioscoService: PagoKioscoService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createPagoKioscoDto: CreatePagoKioscoDto) {
|
||||
return this.pagoKioscoService.create(createPagoKioscoDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
all() {
|
||||
return this.pagoKioscoService.all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PagoKioscoService } from './pago-kiosco.service';
|
||||
import { PagoKioscoController } from './pago-kiosco.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { KioscoModule } from 'src/modules/Monedero/kiosco/kiosco.module';
|
||||
import { TransaccionModule } from 'src/modules/Monedero/transaccion/transaccion.module';
|
||||
import { PagoKiosco } from 'src/database/Monedero/entities/pago-kiosco.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([PagoKiosco], 'dbMonedero'),
|
||||
KioscoModule,
|
||||
TransaccionModule,
|
||||
],
|
||||
controllers: [PagoKioscoController],
|
||||
providers: [PagoKioscoService],
|
||||
exports: [PagoKioscoService],
|
||||
})
|
||||
export class PagoKioscoModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PagoKioscoService } from './pago-kiosco.service';
|
||||
|
||||
describe('PagoKioscoService', () => {
|
||||
let service: PagoKioscoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PagoKioscoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PagoKioscoService>(PagoKioscoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreatePagoKioscoDto } from './dto/create-pago-kiosco.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { KioscoService } from 'src/modules/Monedero/kiosco/kiosco.service';
|
||||
import { TransaccionService } from 'src/modules/Monedero/transaccion/transaccion.service';
|
||||
import { PagoKiosco } from 'src/database/Monedero/entities/pago-kiosco.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PagoKioscoService {
|
||||
constructor(
|
||||
@InjectRepository(PagoKiosco, 'dbMonedero')
|
||||
private readonly pagoKioscoRepository: Repository<PagoKiosco>,
|
||||
private readonly kioscoService: KioscoService,
|
||||
private readonly transaccionService: TransaccionService,
|
||||
) {}
|
||||
|
||||
async all() {
|
||||
return this.pagoKioscoRepository.find();
|
||||
}
|
||||
|
||||
async create(createPagoKiosco: CreatePagoKioscoDto) {
|
||||
const { idKiosco, idTransaccion, ...rest } = createPagoKiosco;
|
||||
|
||||
const kiosco = this.kioscoService.findById(idKiosco);
|
||||
|
||||
const transaccion = this.transaccionService.findById(idTransaccion);
|
||||
|
||||
const data = {
|
||||
...rest,
|
||||
kiosco: await kiosco,
|
||||
transaccion: await transaccion,
|
||||
};
|
||||
|
||||
const create = this.pagoKioscoRepository.create(data);
|
||||
await this.pagoKioscoRepository.save(create);
|
||||
return await this.pagoKioscoRepository.save(create);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreatePagoPatronatoDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreatePagoPatronatoDto } from './create-pago-patronato.dto';
|
||||
|
||||
export class UpdatePagoPatronatoDto extends PartialType(CreatePagoPatronatoDto) {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PagoPatronatoController } from './pago-patronato.controller';
|
||||
import { PagoPatronatoService } from './pago-patronato.service';
|
||||
|
||||
describe('PagoPatronatoController', () => {
|
||||
let controller: PagoPatronatoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PagoPatronatoController],
|
||||
providers: [PagoPatronatoService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PagoPatronatoController>(PagoPatronatoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { PagoPatronatoService } from './pago-patronato.service';
|
||||
|
||||
@Controller('pago-patronato')
|
||||
export class PagoPatronatoController {
|
||||
constructor(private readonly pagoPatronatoService: PagoPatronatoService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.pagoPatronatoService.findAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PagoPatronatoService } from './pago-patronato.service';
|
||||
import { PagoPatronatoController } from './pago-patronato.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PagoPatronato } from '../../../database/Monedero/entities/pago-patronato.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([PagoPatronato], 'dbMonedero')],
|
||||
controllers: [PagoPatronatoController],
|
||||
providers: [PagoPatronatoService],
|
||||
exports: [PagoPatronatoService],
|
||||
})
|
||||
export class PagoPatronatoModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PagoPatronatoService } from './pago-patronato.service';
|
||||
|
||||
describe('PagoPatronatoService', () => {
|
||||
let service: PagoPatronatoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PagoPatronatoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PagoPatronatoService>(PagoPatronatoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreatePagoPatronatoDto } from './dto/create-pago-patronato.dto';
|
||||
import { UpdatePagoPatronatoDto } from './dto/update-pago-patronato.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { PagoPatronato } from '../../../database/Monedero/entities/pago-patronato.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class PagoPatronatoService {
|
||||
constructor(
|
||||
@InjectRepository(PagoPatronato, 'dbMonedero')
|
||||
private readonly pagoPatronatoRepository: Repository<PagoPatronato>,
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.pagoPatronatoRepository.find();
|
||||
}
|
||||
|
||||
findById(idPagoPatronato: number) {
|
||||
return this.pagoPatronatoRepository.findOne({ where: { idPagoPatronato } });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class CreatePersonaDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreatePersonaDto } from './create-persona.dto';
|
||||
|
||||
export class UpdatePersonaDto extends PartialType(CreatePersonaDto) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Injectable, ExecutionContext } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleAuthGuard extends AuthGuard('google') {
|
||||
handleRequest(err, user, info, context: ExecutionContext) {
|
||||
const res = context.switchToHttp().getResponse();
|
||||
|
||||
if (err || !user) {
|
||||
return res.redirect(
|
||||
`${process.env.FRONTEND_URL}/oauth-callback?error=${info.message || info}`,
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PersonaService } from './persona.service';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
constructor(
|
||||
private readonly personaService: PersonaService,
|
||||
private readonly config: ConfigService,
|
||||
) {
|
||||
const clientID = config.get<string>('GOOGLE_CLIENT_ID');
|
||||
const clientSecret = config.get<string>('GOOGLE_CLIENT_SECRET');
|
||||
const callbackURL = config.get<string>('GOOGLE_CALLBACK_URL');
|
||||
|
||||
if (!clientID || !clientSecret || !callbackURL) {
|
||||
throw new Error(
|
||||
'Las variables de entorno de Google OAuth no están definidas',
|
||||
);
|
||||
}
|
||||
|
||||
super({
|
||||
clientID,
|
||||
clientSecret,
|
||||
callbackURL,
|
||||
scope: ['email', 'profile'],
|
||||
passReqToCallback: true,
|
||||
});
|
||||
}
|
||||
|
||||
authorizationParams() {
|
||||
return {
|
||||
prompt: 'select_account',
|
||||
hd: 'pcpuma.acatlan.unam.mx',
|
||||
};
|
||||
}
|
||||
|
||||
async validate(
|
||||
req: any,
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: any,
|
||||
done: VerifyCallback,
|
||||
): Promise<any> {
|
||||
try {
|
||||
const email = profile.emails?.[0]?.value || '';
|
||||
|
||||
if (!email.endsWith('@pcpuma.acatlan.unam.mx')) {
|
||||
return done(
|
||||
new Error('El correo no pertenece al dominio permitido'),
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
const user = await this.personaService.validateOrCreateGoogleUser({
|
||||
email,
|
||||
});
|
||||
|
||||
done(null, user);
|
||||
} catch (error) {
|
||||
done(error, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
ForbiddenException,
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {
|
||||
handleRequest(err: any, user: any, info: any, context: ExecutionContext) {
|
||||
if (err || !user) {
|
||||
throw new ForbiddenException('Access denied: token inválido o ausente');
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Injectable, ForbiddenException } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
export interface JwtPayload {
|
||||
idPersona: string;
|
||||
user: string;
|
||||
userType: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private configService: ConfigService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: configService.get<string>('JWT_SECRET')!,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: JwtPayload) {
|
||||
if (!payload || !payload.idPersona || !payload.user || !payload.userType) {
|
||||
throw new ForbiddenException('Token inválido o corrupto');
|
||||
}
|
||||
return {
|
||||
idPersona: payload.idPersona,
|
||||
user: payload.user,
|
||||
userType: payload.userType,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export default function passwordRand(length: number): string {
|
||||
const characters =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let pass = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
pass += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
}
|
||||
|
||||
return pass;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PersonaController } from './persona.controller';
|
||||
import { PersonaService } from './persona.service';
|
||||
|
||||
describe('PersonaController', () => {
|
||||
let controller: PersonaController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PersonaController],
|
||||
providers: [PersonaService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PersonaController>(PersonaController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Controller, Get, UseGuards, Req, Res } from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { PersonaService } from './persona.service';
|
||||
import { GoogleAuthGuard } from './google-auth.guard';
|
||||
import { JwtAuthGuard } from './jwt.guard';
|
||||
|
||||
@Controller('persona')
|
||||
export class PersonaController {
|
||||
constructor(private readonly personaService: PersonaService) {}
|
||||
|
||||
@Get()
|
||||
getAll() {
|
||||
return this.personaService.findAll();
|
||||
}
|
||||
|
||||
@Get('google')
|
||||
@UseGuards(GoogleAuthGuard)
|
||||
async googleLogin() {}
|
||||
|
||||
@Get('google/callback')
|
||||
@UseGuards(GoogleAuthGuard)
|
||||
async googleCallback(@Req() req, @Res() res: Response) {
|
||||
const persona = req.user;
|
||||
|
||||
if (!persona) return;
|
||||
|
||||
const jwt = await this.personaService.generateJwt(persona);
|
||||
|
||||
return res.redirect(
|
||||
`${process.env.FRONTEND_URL}/oauth-callback?token=${jwt.access_token}`,
|
||||
);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('me')
|
||||
async getMe(@Req() req) {
|
||||
const idPersona = req.user.idPersona;
|
||||
|
||||
const persona = await this.personaService.findById(idPersona);
|
||||
|
||||
return {
|
||||
error: false,
|
||||
msj: `Bienvenido ${persona.nombre} ${persona.apellidoP} ${persona.apellidoM}`,
|
||||
data: {
|
||||
userId: persona.idPersona,
|
||||
nombre: persona.nombre,
|
||||
apellidoP: persona.apellidoP,
|
||||
apellidoM: persona.apellidoM,
|
||||
saldo: persona.cantidadCuenta,
|
||||
carreraAds: persona.carreraAds,
|
||||
numeroCuenta: persona.numeroIdentificar,
|
||||
tipoUsuario: persona.tipoUsuario,
|
||||
primerLogin: persona.primerLogin,
|
||||
cambioPassword: persona.cambioPasswordReq,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('saldo')
|
||||
async saldo(@Req() req) {
|
||||
const idPersona = req.user.idPersona;
|
||||
return this.personaService.saldo(idPersona);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PersonaService } from './persona.service';
|
||||
import { PersonaController } from './persona.controller';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { GoogleStrategy } from './google.strategy';
|
||||
import { JwtStrategy } from './jwt.strategy';
|
||||
import { Persona } from 'src/database/Monedero/entities/persona.entity';
|
||||
import { AlumnoModule } from 'src/modules/AT/alumno/student.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Persona], 'dbMonedero'),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
global: true,
|
||||
secret: configService.get<string>('JWT_SECRET'),
|
||||
signOptions: { expiresIn: '1h' },
|
||||
};
|
||||
},
|
||||
}),
|
||||
AlumnoModule,
|
||||
],
|
||||
controllers: [PersonaController],
|
||||
providers: [PersonaService, GoogleStrategy, JwtStrategy],
|
||||
exports: [PersonaService],
|
||||
})
|
||||
export class PersonaModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PersonaService } from './persona.service';
|
||||
|
||||
describe('PersonaService', () => {
|
||||
let service: PersonaService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PersonaService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PersonaService>(PersonaService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Persona } from 'src/database/Monedero/entities/persona.entity';
|
||||
import { AlumnoService } from 'src/modules/AT/alumno/student.service';
|
||||
|
||||
@Injectable()
|
||||
export class PersonaService {
|
||||
constructor(
|
||||
@InjectRepository(Persona, 'dbMonedero')
|
||||
private readonly personaRepository: Repository<Persona>,
|
||||
private readonly jwtService: JwtService,
|
||||
//AT
|
||||
private readonly alumnoService: AlumnoService,
|
||||
) {}
|
||||
|
||||
async findAll() {
|
||||
return this.personaRepository.find();
|
||||
}
|
||||
|
||||
async findByEmail(correo: string): Promise<Persona | null> {
|
||||
const user = await this.personaRepository.findOne({
|
||||
where: { correo },
|
||||
});
|
||||
console.log('service', user);
|
||||
return user;
|
||||
}
|
||||
|
||||
async create(data: Partial<Persona>): Promise<Persona> {
|
||||
const persona = this.personaRepository.create(data);
|
||||
return this.personaRepository.save(persona);
|
||||
}
|
||||
|
||||
async findById(idPersona: number): Promise<Persona> {
|
||||
const user = await this.personaRepository.findOne({ where: { idPersona } });
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('user not found');
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async generateJwt(user: Persona) {
|
||||
const payload = {
|
||||
userType: 'usuario',
|
||||
user: 'alumno',
|
||||
idPersona: user.idPersona,
|
||||
};
|
||||
return {
|
||||
access_token: this.jwtService.sign(payload),
|
||||
};
|
||||
}
|
||||
|
||||
async validateOrCreateGoogleUser(data: { email: string }) {
|
||||
let persona = await this.findByEmail(data.email);
|
||||
|
||||
const numeroIdentificar = data.email.split('@')[0];
|
||||
|
||||
const alum = await this.alumnoService.findOneById(
|
||||
Number(numeroIdentificar),
|
||||
);
|
||||
|
||||
if (!persona) {
|
||||
const apellidoArray = alum.nombre.split(' ');
|
||||
|
||||
const apellidoP = apellidoArray[0] || '';
|
||||
const apellidoM = apellidoArray[1] || '';
|
||||
|
||||
const nombre = apellidoArray.slice(2).join(' ');
|
||||
|
||||
let tipo;
|
||||
if (numeroIdentificar.length === 9) {
|
||||
tipo = 'Alumno';
|
||||
} else {
|
||||
tipo = 'Academico';
|
||||
}
|
||||
|
||||
persona = this.personaRepository.create({
|
||||
nombre,
|
||||
apellidoP,
|
||||
apellidoM,
|
||||
password: '',
|
||||
fechaPasswordTem: new Date(),
|
||||
correo: data.email,
|
||||
carreraAds: alum.carrera.carrera,
|
||||
cantidadCuenta: alum.credito,
|
||||
usuario: numeroIdentificar,
|
||||
numeroIdentificar: numeroIdentificar || '',
|
||||
tipoUsuario: tipo,
|
||||
correoEnviado: false,
|
||||
fechaRegistro: new Date(),
|
||||
cambioPasswordReq: true,
|
||||
primerLogin: false,
|
||||
});
|
||||
} else {
|
||||
const monto = this.alumnoService.GetCredit(
|
||||
Number(persona.numeroIdentificar),
|
||||
);
|
||||
|
||||
persona.cantidadCuenta = await monto;
|
||||
}
|
||||
|
||||
await this.personaRepository.save(persona);
|
||||
return persona;
|
||||
}
|
||||
|
||||
async saldo(idPersona: number) {
|
||||
const persona = await this.personaRepository.findOne({
|
||||
where: { idPersona },
|
||||
select: { cantidadCuenta: true },
|
||||
});
|
||||
|
||||
if (!persona) {
|
||||
throw new NotFoundException('user not found');
|
||||
}
|
||||
|
||||
return persona?.cantidadCuenta;
|
||||
}
|
||||
|
||||
async updateSaldo(idPersona: number, monto: number) {
|
||||
const persona = await this.findById(idPersona);
|
||||
|
||||
const newSaldo = (persona.cantidadCuenta || 0) + monto;
|
||||
await this.personaRepository.update(idPersona, {
|
||||
cantidadCuenta: newSaldo,
|
||||
});
|
||||
return newSaldo;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,19 @@
|
||||
import { IsInt, IsNotEmpty, IsDateString, IsNumber } from 'class-validator';
|
||||
|
||||
export class CreateTransaccionDto {
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
nombreTransaccion: string;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
idPersona: number;
|
||||
|
||||
@IsDateString()
|
||||
@IsNotEmpty()
|
||||
fecha: string;
|
||||
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
tipoTransaccion: number;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TransaccionController } from './transaccion.controller';
|
||||
import { TransaccionService } from './transaccion.service';
|
||||
|
||||
describe('TransaccionController', () => {
|
||||
let controller: TransaccionController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [TransaccionController],
|
||||
providers: [TransaccionService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<TransaccionController>(TransaccionController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Controller, Get, Post, Body } from '@nestjs/common';
|
||||
import { TransaccionService } from './transaccion.service';
|
||||
import { CreateTransaccionDto } from './dto/create-transaccion.dto';
|
||||
|
||||
@Controller('transaccion')
|
||||
export class TransaccionController {
|
||||
constructor(private readonly transaccionService: TransaccionService) {}
|
||||
|
||||
@Get()
|
||||
all() {
|
||||
return this.transaccionService.all();
|
||||
}
|
||||
|
||||
@Post('abonoKiosco')
|
||||
abonoKiosco(@Body() createTransaccionDto: CreateTransaccionDto) {
|
||||
const { ...rest } = createTransaccionDto;
|
||||
|
||||
const data = {
|
||||
...rest,
|
||||
fecha: new Date().toString(),
|
||||
tipoTransaccion: 2,
|
||||
};
|
||||
return this.transaccionService.create(data);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TransaccionService } from './transaccion.service';
|
||||
import { TransaccionController } from './transaccion.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { NombreTransaccionModule } from 'src/modules/Monedero/nombre-transaccion/nombre-transaccion.module';
|
||||
import { PersonaModule } from 'src/modules/Monedero/persona/persona.module';
|
||||
import { Transaccion } from 'src/database/Monedero/entities/transaccion.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Transaccion], 'dbMonedero'),
|
||||
NombreTransaccionModule,
|
||||
PersonaModule,
|
||||
],
|
||||
controllers: [TransaccionController],
|
||||
providers: [TransaccionService],
|
||||
exports: [TransaccionService],
|
||||
})
|
||||
export class TransaccionModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TransaccionService } from './transaccion.service';
|
||||
|
||||
describe('TransaccionService', () => {
|
||||
let service: TransaccionService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [TransaccionService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<TransaccionService>(TransaccionService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateTransaccionDto } from './dto/create-transaccion.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Transaccion } from '../../../database/Monedero/entities/transaccion.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { NombreTransaccionService } from 'src/modules/Monedero/nombre-transaccion/nombre-transaccion.service';
|
||||
import { PersonaService } from 'src/modules/Monedero/persona/persona.service';
|
||||
|
||||
@Injectable()
|
||||
export class TransaccionService {
|
||||
constructor(
|
||||
@InjectRepository(Transaccion, 'dbMonedero')
|
||||
private readonly transaccionRepository: Repository<Transaccion>,
|
||||
private readonly nombreTransaccionService: NombreTransaccionService,
|
||||
private readonly personaService: PersonaService,
|
||||
) {}
|
||||
|
||||
async all() {
|
||||
return await this.transaccionRepository.find();
|
||||
}
|
||||
|
||||
async findById(idTransaccion: number): Promise<Transaccion> {
|
||||
const transaccion = await this.transaccionRepository.findOne({
|
||||
where: { idTransaccion },
|
||||
});
|
||||
|
||||
if (!transaccion) {
|
||||
throw new NotFoundException('transaccion not found');
|
||||
}
|
||||
|
||||
return transaccion;
|
||||
}
|
||||
|
||||
async create(createTransaccion: CreateTransaccionDto): Promise<Transaccion> {
|
||||
const { nombreTransaccion, idPersona, ...rest } = createTransaccion;
|
||||
|
||||
const Transaccion =
|
||||
this.nombreTransaccionService.findByName(nombreTransaccion);
|
||||
|
||||
const persona = this.personaService.findById(idPersona);
|
||||
|
||||
const data = {
|
||||
nombreTransaccion: await Transaccion,
|
||||
persona: await persona,
|
||||
...rest,
|
||||
};
|
||||
|
||||
const create = this.transaccionRepository.create(data);
|
||||
return await this.transaccionRepository.save(create);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,16 @@
|
||||
import { IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class abonoKioscoDto {
|
||||
@IsNumber()
|
||||
cantidad: number;
|
||||
|
||||
@IsNumber()
|
||||
idKiosco: number;
|
||||
|
||||
@IsString()
|
||||
transaccion: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
plataforma?: string;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OperationsController } from './operations.controller';
|
||||
import { OperationsService } from './operations.service';
|
||||
|
||||
describe('OperationsController', () => {
|
||||
let controller: OperationsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<OperationsController>(OperationsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Controller, Post, Body, UseGuards, Req } from '@nestjs/common';
|
||||
import { OperationsService } from './operations.service';
|
||||
import { abonoKioscoDto } from './dto/create-operation.dto';
|
||||
import { JwtAuthGuard } from 'src/modules/Monedero/persona/jwt.guard';
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController {
|
||||
constructor(private readonly operationsService: OperationsService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('abonoKiosco')
|
||||
async depositKiosco(@Body() abonoKiosco: abonoKioscoDto, @Req() req) {
|
||||
const idPersona = req.user.idPersona;
|
||||
return await this.operationsService.depositKiosco(abonoKiosco, idPersona);
|
||||
}
|
||||
|
||||
//test
|
||||
@Post('inscription')
|
||||
async inscription(@Body() body: { plataforma: string; idPersona: number }) {
|
||||
const { plataforma, idPersona } = body;
|
||||
return await this.operationsService.inscriptionAT(plataforma, idPersona);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user