tipo-entrada
This commit is contained in:
parent
3eab1c937b
commit
6c1acdcd16
6
src/tipo-entrada/dto/tipo-entrada-create.dto.ts
Normal file
6
src/tipo-entrada/dto/tipo-entrada-create.dto.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class TipoEntradaCreateDto {
|
||||
@IsString()
|
||||
tipo_entrada: string;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { TipoEntradaService } from './tipo-entrada.service';
|
||||
import { TipoEntradaCreateDto } from './dto/tipo-entrada-create.dto'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
|
||||
@Controller('tipo-entrada')
|
||||
@ -7,6 +8,13 @@ import {ApiTags} from '@nestjs/swagger'
|
||||
export class TipoEntradaController {
|
||||
constructor(private tipoEntradaService: TipoEntradaService) {}
|
||||
|
||||
@Get()
|
||||
get() {}
|
||||
@Post()
|
||||
create(@Body() body: TipoEntradaCreateDto) {
|
||||
return this.tipoEntradaService.create(body.tipo_entrada)
|
||||
}
|
||||
|
||||
@Get()
|
||||
get() {
|
||||
return this.tipoEntradaService.findAll()
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, ConflictException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||
@ -8,4 +8,21 @@ export class TipoEntradaService {
|
||||
constructor(
|
||||
@InjectRepository(TipoEntrada) private repository: Repository<TipoEntrada>,
|
||||
) { }
|
||||
|
||||
async create(tipo_entrada: string) {
|
||||
const nuevoTipoEntrada = this.repository.create({
|
||||
tipo_entrada
|
||||
})
|
||||
|
||||
return this.repository.findOne({ tipo_entrada })
|
||||
.then((existeTipoEntrada) => {
|
||||
if(existeTipoEntrada) throw new ConflictException('Ya existe este tipo de entrada')
|
||||
return this.repository.save(nuevoTipoEntrada)
|
||||
})
|
||||
.then(()=> ({message: 'Se creo correctamente la nueva entrada'}))
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.repository.find()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user