fixed pago kiosco
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
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';
|
||||
@@ -7,28 +15,8 @@ import { UpdateKioscoDto } from './dto/update-kiosco.dto';
|
||||
export class KioscoController {
|
||||
constructor(private readonly kioscoService: KioscoService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createKioscoDto: CreateKioscoDto) {
|
||||
return this.kioscoService.create(createKioscoDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.kioscoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.kioscoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateKioscoDto: UpdateKioscoDto) {
|
||||
return this.kioscoService.update(+id, updateKioscoDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.kioscoService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +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 './entities/kiosco.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Kiosco])],
|
||||
controllers: [KioscoController],
|
||||
providers: [KioscoService],
|
||||
exports: [KioscoService],
|
||||
})
|
||||
export class KioscoModule {}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
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 { Kiosco } from './entities/kiosco.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class KioscoService {
|
||||
create(createKioscoDto: CreateKioscoDto) {
|
||||
return 'This action adds a new kiosco';
|
||||
}
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Kiosco)
|
||||
private readonly KioscoRepository: Repository<Kiosco>,
|
||||
) {}
|
||||
findAll() {
|
||||
return `This action returns all kiosco`;
|
||||
return this.KioscoRepository.find();
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} kiosco`;
|
||||
}
|
||||
async findById(idKiosco: number): Promise<Kiosco> {
|
||||
const kiosco = await this.KioscoRepository.findOne({ where: { idKiosco } });
|
||||
|
||||
update(id: number, updateKioscoDto: UpdateKioscoDto) {
|
||||
return `This action updates a #${id} kiosco`;
|
||||
}
|
||||
if (!kiosco) {
|
||||
throw new NotFoundException('kiosco not found');
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} kiosco`;
|
||||
return kiosco;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,15 @@ import { PagoKioscoService } from './pago-kiosco.service';
|
||||
import { PagoKioscoController } from './pago-kiosco.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PagoKiosco } from './entities/pago-kiosco.entity';
|
||||
import { KioscoModule } from 'src/kiosco/kiosco.module';
|
||||
import { TransaccionModule } from 'src/transaccion/transaccion.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([PagoKiosco])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([PagoKiosco]),
|
||||
KioscoModule,
|
||||
TransaccionModule,
|
||||
],
|
||||
controllers: [PagoKioscoController],
|
||||
providers: [PagoKioscoService],
|
||||
exports: [PagoKioscoService],
|
||||
|
||||
@@ -3,12 +3,16 @@ import { CreatePagoKioscoDto } from './dto/create-pago-kiosco.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { PagoKiosco } from './entities/pago-kiosco.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { KioscoService } from 'src/kiosco/kiosco.service';
|
||||
import { TransaccionService } from 'src/transaccion/transaccion.service';
|
||||
|
||||
@Injectable()
|
||||
export class PagoKioscoService {
|
||||
constructor(
|
||||
@InjectRepository(PagoKiosco)
|
||||
private readonly pagoKioscoRepository: Repository<PagoKiosco>,
|
||||
private readonly kioscoService: KioscoService,
|
||||
private readonly transaccionService: TransaccionService,
|
||||
) {}
|
||||
|
||||
async all() {
|
||||
@@ -16,7 +20,19 @@ export class PagoKioscoService {
|
||||
}
|
||||
|
||||
async create(createPagoKiosco: CreatePagoKioscoDto) {
|
||||
const create = this.pagoKioscoRepository.create(createPagoKiosco);
|
||||
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 { statusCode: 200, message: 'success' };
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateTransaccionDto } from './dto/create-transaccion.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Transaccion } from './entities/transaccion.entity';
|
||||
@@ -19,6 +19,18 @@ export class TransaccionService {
|
||||
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 { idNombreTransaccion, idPersona, ...rest } = createTransaccion;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user