add Ep receipt
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import { Body, Controller, Post } from "@nestjs/common";
|
||||
import { Body, Controller, Post, UseGuards } from "@nestjs/common";
|
||||
import { OperationsService } from "./operations.services";
|
||||
import { chargePrintDto } from "./dto/operations.dto";
|
||||
import { JwtAuthGuard } from "src/user/jwt.guard";
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController{
|
||||
constructor(private readonly operationsService:OperationsService){}
|
||||
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data) {
|
||||
return this.operationsService.chargePrint(data,data.userid);
|
||||
async Login(@Body() data:chargePrintDto) {
|
||||
return this.operationsService.chargePrint(data,data.id_cuenta);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,14 @@ import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { OperationsController } from './operations.controller';
|
||||
import { OperationsService } from './operations.services';
|
||||
import { DetalleServicioModule } from 'src/detalle_servicio/detalle_servicio.module';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Alumno, DetalleServicio]),
|
||||
DetalleServicioModule,
|
||||
AlumnoModule,
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { AlumnoSancion } from 'src/alumno_sancion/entities/alumno_sancion.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Recibo } from 'src/recibo/entities/recibo.entity';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
@@ -95,4 +96,7 @@ export class Alumno {
|
||||
|
||||
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
|
||||
sanciones: AlumnoSancion[];
|
||||
|
||||
@OneToMany(() => Recibo, (recibo) => recibo.alum)
|
||||
recibo: Recibo[];
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ export class AlumnoSancionService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoSancion)
|
||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||
|
||||
private readonly alumnoService: AlumnoService,
|
||||
private readonly sancionService: SancionService,
|
||||
) {}
|
||||
|
||||
@@ -17,6 +17,9 @@ import { SancionModule } from './sancion/sancion.module';
|
||||
import { AlumnoSancionModule } from './alumno_sancion/alumno_sancion.module';
|
||||
import { AlumnoSancion } from './alumno_sancion/entities/alumno_sancion.entity';
|
||||
import { Sancion } from './sancion/entities/sancion.entity';
|
||||
import { OperationsModule } from './Operations/operations.module';
|
||||
import { Recibo } from './recibo/entities/recibo.entity';
|
||||
import { ReciboModule } from './recibo/recibo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -43,6 +46,7 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
AlumnoSancion,
|
||||
Sancion,
|
||||
Carrera,
|
||||
Recibo,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -54,6 +58,8 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
ServicioModule,
|
||||
SancionModule,
|
||||
AlumnoSancionModule,
|
||||
OperationsModule,
|
||||
ReciboModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -5,5 +5,6 @@ import { DetalleServicioController } from './detalle_servicio.controller';
|
||||
@Module({
|
||||
controllers: [DetalleServicioController],
|
||||
providers: [DetalleServicioService],
|
||||
exports:[DetalleServicioService]
|
||||
})
|
||||
export class DetalleServicioModule {}
|
||||
|
||||
@@ -44,7 +44,6 @@ export class DetalleServicio {
|
||||
@Column()
|
||||
id_servicio:number
|
||||
|
||||
|
||||
@ManyToOne(() => Alumno, (id_cuenta) => id_cuenta.detalles_servicio, {
|
||||
eager: true,
|
||||
})
|
||||
|
||||
@@ -1,34 +1,6 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { CreatePeriodoDto } from './dto/create-periodo.dto';
|
||||
import { UpdatePeriodoDto } from './dto/update-periodo.dto';
|
||||
|
||||
@Controller('periodo')
|
||||
export class PeriodoController {
|
||||
constructor(private readonly periodoService: PeriodoService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createPeriodoDto: CreatePeriodoDto) {
|
||||
return this.periodoService.create(createPeriodoDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.periodoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.periodoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updatePeriodoDto: UpdatePeriodoDto) {
|
||||
return this.periodoService.update(+id, updatePeriodoDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.periodoService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,4 @@ import { UpdatePeriodoDto } from './dto/update-periodo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PeriodoService {
|
||||
create(createPeriodoDto: CreatePeriodoDto) {
|
||||
return 'This action adds a new periodo';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all periodo`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} periodo`;
|
||||
}
|
||||
|
||||
update(id: number, updatePeriodoDto: UpdatePeriodoDto) {
|
||||
return `This action updates a #${id} periodo`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} periodo`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDate, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateReciboDto {
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsNumber()
|
||||
monto: number;
|
||||
|
||||
@IsString()
|
||||
folio_recibo: string;
|
||||
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
fecha_recibo: Date;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export class Ticket {}
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
@@ -7,6 +6,7 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
|
||||
@Entity({ name: 'recibo' })
|
||||
export class Recibo {
|
||||
@@ -29,20 +29,11 @@ export class Recibo {
|
||||
monto: number;
|
||||
|
||||
@Column({ name: 'fecha_recibo', type: 'date', nullable: false })
|
||||
fecha_recibo: Date | null;
|
||||
fecha_recibo: Date ;
|
||||
|
||||
@Column({
|
||||
name: 'id_cuenta',
|
||||
type: 'int',
|
||||
})
|
||||
id_cuenta: number;
|
||||
|
||||
@Column({
|
||||
name: 'id_usuario',
|
||||
type: 'int',
|
||||
nullable: false,
|
||||
})
|
||||
id_usuario: number;
|
||||
@ManyToOne(() => Alumno, (alum) => alum.id_cuenta, {})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
alum: Alumno;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.id_usuario, {})
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ReciboService } from './recibo.service';
|
||||
import { CreateReciboDto } from './dto/create-recibo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
|
||||
@Controller('recibo')
|
||||
export class ReciboController {
|
||||
constructor(private readonly reciboService: ReciboService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post()
|
||||
async createReceipt(@Body() data: CreateReciboDto, @Req() req: any) {
|
||||
const userId = req.user.id;
|
||||
return this.reciboService.create(data, +userId);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ReciboService } from './recibo.service';
|
||||
import { ReciboController } from './recibo.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Recibo } from './entities/recibo.entity';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { UserModule } from 'src/user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Recibo]), AlumnoModule, UserModule],
|
||||
controllers: [ReciboController],
|
||||
providers: [ReciboService],
|
||||
})
|
||||
export class ReciboModule {}
|
||||
//IO
|
||||
@@ -0,0 +1,50 @@
|
||||
import { ConflictException, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Recibo } from './entities/recibo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateReciboDto } from './dto/create-recibo.dto';
|
||||
import { AlumnoService } from 'src/alumno/student.service';
|
||||
import { UserService } from 'src/user/user.service';
|
||||
|
||||
@Injectable()
|
||||
export class ReciboService {
|
||||
constructor(
|
||||
@InjectRepository(Recibo)
|
||||
private readonly reciboRepository:Repository<Recibo>,
|
||||
private readonly alumnoService:AlumnoService,
|
||||
private readonly usuarioService:UserService,
|
||||
){}
|
||||
|
||||
async findOne(folio_recibo: string) {
|
||||
const recibo = await this.reciboRepository.findOne({
|
||||
where: { folio_recibo },
|
||||
});
|
||||
return recibo;
|
||||
}
|
||||
|
||||
async create(data: CreateReciboDto, id_usuario: number) {
|
||||
const {id_cuenta,folio_recibo} = data
|
||||
const receipt = await this.findOne(folio_recibo)
|
||||
|
||||
if(receipt){
|
||||
throw new ConflictException('Recibo ya existe');
|
||||
}
|
||||
|
||||
const alumno = await this.alumnoService.findOne(id_cuenta)
|
||||
const usuario = await this.usuarioService.findOne(id_usuario)
|
||||
|
||||
console.log(usuario)
|
||||
const recibo = this.reciboRepository.create({
|
||||
folio_recibo: data.folio_recibo,
|
||||
monto: data.monto,
|
||||
fecha_recibo: data.fecha_recibo,
|
||||
alum: alumno,
|
||||
user:usuario
|
||||
});
|
||||
|
||||
console.log(recibo)
|
||||
await this.reciboRepository.save(recibo)
|
||||
return;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -1 +0,0 @@
|
||||
export class CreateTicketDto {}
|
||||
@@ -1,4 +0,0 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateTicketDto } from './create-ticket.dto';
|
||||
|
||||
export class UpdateTicketDto extends PartialType(CreateTicketDto) {}
|
||||
@@ -1,34 +0,0 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { TicketService } from './ticket.service';
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { UpdateTicketDto } from './dto/update-ticket.dto';
|
||||
|
||||
@Controller('ticket')
|
||||
export class TicketController {
|
||||
constructor(private readonly ticketService: TicketService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createTicketDto: CreateTicketDto) {
|
||||
return this.ticketService.create(createTicketDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.ticketService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.ticketService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateTicketDto: UpdateTicketDto) {
|
||||
return this.ticketService.update(+id, updateTicketDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.ticketService.remove(+id);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TicketService } from './ticket.service';
|
||||
import { TicketController } from './ticket.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [TicketController],
|
||||
providers: [TicketService],
|
||||
})
|
||||
export class TicketModule {}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { UpdateTicketDto } from './dto/update-ticket.dto';
|
||||
|
||||
@Injectable()
|
||||
export class TicketService {
|
||||
create(createTicketDto: CreateTicketDto) {
|
||||
return 'This action adds a new ticket';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all ticket`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} ticket`;
|
||||
}
|
||||
|
||||
update(id: number, updateTicketDto: UpdateTicketDto) {
|
||||
return `This action updates a #${id} ticket`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} ticket`;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Recibo } from 'src/recibo/entities/recibo.entity';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
@@ -58,4 +59,7 @@ export class User {
|
||||
(id_detalle_servicio) => id_detalle_servicio.id_perfil,
|
||||
)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@OneToMany(() => Recibo, (recibo) => recibo.user)
|
||||
recibo: Recibo[];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { UserService } from './user.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
@@ -15,6 +14,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
}
|
||||
|
||||
async validate(payload: any) {
|
||||
return { userId: payload.id, username: payload.usuario };
|
||||
console.log('payload:', payload);
|
||||
return { id: payload.id, usuario: payload.usuario };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,10 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
signOptions: { expiresIn: '1h' },
|
||||
};
|
||||
},
|
||||
|
||||
}),
|
||||
],
|
||||
controllers: [UserController],
|
||||
providers: [UserService,JwtStrategy],
|
||||
exports: [UserService],
|
||||
providers: [UserService, JwtStrategy],
|
||||
exports: [UserService,PassportModule,JwtModule],
|
||||
})
|
||||
export class UserModule { }
|
||||
export class UserModule {}
|
||||
|
||||
@@ -41,7 +41,20 @@ export class UserService {
|
||||
path: '/',
|
||||
});
|
||||
|
||||
return res.json({ message: 'Inicio de sesión exitoso' });
|
||||
return res.json({
|
||||
message: 'Inicio de sesión exitoso',
|
||||
access_token: token,
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id_usuario: number): Promise<User> {
|
||||
const student = await this.userRepository.findOne({
|
||||
where: { id_usuario },
|
||||
});
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Student not found`);
|
||||
}
|
||||
return student;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user