listo tipo usuario
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class TipoUsuarioUpdateDto {
|
||||
@IsString()
|
||||
tipo_usuario: string;
|
||||
}
|
||||
@@ -1,10 +1,17 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { TipoUsuarioService } from './tipo-usuario.service';
|
||||
|
||||
import { TipoUsuarioUpdateDto } from './dto/tipo-usuario-update.dto';
|
||||
@Controller('tipo-usuario')
|
||||
export class TipoUsuarioController {
|
||||
constructor(private tipoUsuarioService: TipoUsuarioService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: TipoUsuarioUpdateDto) {
|
||||
return this.tipoUsuarioService.create(body.tipo_usuario);
|
||||
}
|
||||
|
||||
@Get()
|
||||
get() {}
|
||||
get() {
|
||||
return this.tipoUsuarioService.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import {
|
||||
ConflictException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { TipoUsuario } from './entity/tipo-usuario.entity';
|
||||
@@ -9,6 +13,21 @@ export class TipoUsuarioService {
|
||||
@InjectRepository(TipoUsuario) private repository: Repository<TipoUsuario>,
|
||||
) {}
|
||||
|
||||
create(tipo_usuario: string) {
|
||||
return this.repository
|
||||
.findOne({ tipo_usuario })
|
||||
.then((existeTipoUsuario) => {
|
||||
if (existeTipoUsuario)
|
||||
throw new ConflictException('Ya existe este tipo usuario');
|
||||
return this.repository.save(this.repository.create({ tipo_usuario }));
|
||||
})
|
||||
.then((_) => ({ message: 'Se creo correctamente el tipo usuario.' }));
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.repository.find();
|
||||
}
|
||||
|
||||
findById(id_tipo_usuario: number) {
|
||||
return this.repository.findOne({ id_tipo_usuario }).then((tipoUsuario) => {
|
||||
if (!tipoUsuario)
|
||||
|
||||
Reference in New Issue
Block a user