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,12 +1,20 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||||
import { TipoEntradaService } from './tipo-entrada.service';
|
import { TipoEntradaService } from './tipo-entrada.service';
|
||||||
import {ApiTags} from '@nestjs/swagger'
|
import { TipoEntradaCreateDto } from './dto/tipo-entrada-create.dto'
|
||||||
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
|
|
||||||
@Controller('tipo-entrada')
|
@Controller('tipo-entrada')
|
||||||
@ApiTags('tipo-entrada')
|
@ApiTags('tipo-entrada')
|
||||||
export class TipoEntradaController {
|
export class TipoEntradaController {
|
||||||
constructor(private tipoEntradaService: TipoEntradaService) {}
|
constructor(private tipoEntradaService: TipoEntradaService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() body: TipoEntradaCreateDto) {
|
||||||
|
return this.tipoEntradaService.create(body.tipo_entrada)
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
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 { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
import { TipoEntrada } from './entity/tipo-entrada.entity';
|
||||||
@ -7,5 +7,22 @@ import { TipoEntrada } from './entity/tipo-entrada.entity';
|
|||||||
export class TipoEntradaService {
|
export class TipoEntradaService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(TipoEntrada) private repository: Repository<TipoEntrada>,
|
@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