add Ep receipt
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.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, {})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
alum: Alumno;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.id_usuario, {})
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
user: User;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user