fixed transaccion

This commit is contained in:
2025-10-20 17:23:52 -06:00
parent 2f6137d874
commit cb766083e6
6 changed files with 32 additions and 9 deletions
@@ -8,5 +8,6 @@ import { NombreTransaccion } from './entities/nombre-transaccion.entity';
imports: [TypeOrmModule.forFeature([NombreTransaccion])],
controllers: [NombreTransaccionController],
providers: [NombreTransaccionService],
exports: [NombreTransaccionService],
})
export class NombreTransaccionModule {}
@@ -16,13 +16,13 @@ export class NombreTransaccionService {
return this.nombreTransaccionRepository.find();
}
findById(idNombreTransaccion: number): Promise<NombreTransaccion | null> {
const nameTransaccion = this.nombreTransaccionRepository.findOne({
async findById(idNombreTransaccion: number): Promise<NombreTransaccion> {
const nameTransaccion = await this.nombreTransaccionRepository.findOne({
where: { idNombreTransaccion },
});
if (!nameTransaccion) {
throw new NotFoundException('name transaccion not found');
throw new NotFoundException('name transaction not found');
}
return nameTransaccion;
+2 -1
View File
@@ -31,12 +31,13 @@ export class PersonaService {
return this.personaRepository.save(persona);
}
async findById(idPersona): Promise<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;
}
@@ -36,7 +36,7 @@ export class Transaccion {
@Column({
type: 'enum',
enum: ['deposito', 'retiro', 'transferencia', 'ajuste'],
enum: ['PagoKiosco'],
})
tipoTransaccion: number;
+7 -1
View File
@@ -3,9 +3,15 @@ import { TransaccionService } from './transaccion.service';
import { TransaccionController } from './transaccion.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Transaccion } from './entities/transaccion.entity';
import { NombreTransaccionModule } from 'src/nombre-transaccion/nombre-transaccion.module';
import { PersonaModule } from 'src/persona/persona.module';
@Module({
imports: [TypeOrmModule.forFeature([Transaccion])],
imports: [
TypeOrmModule.forFeature([Transaccion]),
NombreTransaccionModule,
PersonaModule,
],
controllers: [TransaccionController],
providers: [TransaccionService],
exports: [TransaccionService],
+18 -3
View File
@@ -3,12 +3,16 @@ import { CreateTransaccionDto } from './dto/create-transaccion.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Transaccion } from './entities/transaccion.entity';
import { Repository } from 'typeorm';
import { NombreTransaccionService } from 'src/nombre-transaccion/nombre-transaccion.service';
import { PersonaService } from 'src/persona/persona.service';
@Injectable()
export class TransaccionService {
constructor(
@InjectRepository(Transaccion)
private readonly transaccionRepository: Repository<Transaccion>,
private readonly nombreTransaccionService: NombreTransaccionService,
private readonly personaService: PersonaService,
) {}
async all() {
@@ -16,9 +20,20 @@ export class TransaccionService {
}
async create(createTransaccion: CreateTransaccionDto): Promise<Transaccion> {
const { idNombreTransaccion } = createTransaccion;
const create = this.transaccionRepository.create(createTransaccion);
const { idNombreTransaccion, idPersona, ...rest } = createTransaccion;
const nombreTransaccion =
this.nombreTransaccionService.findById(idNombreTransaccion);
const persona = this.personaService.findById(idPersona);
const data = {
nombreTransaccion: await nombreTransaccion,
persona: await persona,
...rest,
};
const create = this.transaccionRepository.create(data);
return await this.transaccionRepository.save(create);
}
}