From e04091d74ff61e56b32299120f77f0481fb39a7c Mon Sep 17 00:00:00 2001 From: lemuel Date: Fri, 22 Apr 2022 13:36:18 -0500 Subject: [PATCH] formateo --- .../carrera-programa.controller.ts | 13 ++-- .../carrera-programa.module.ts | 8 ++- .../carrera-programa.service.ts | 56 +++++++++-------- .../dto/carrera-programa-create.dto.ts | 10 +-- .../dto/carrera-programa-update.dto.ts | 14 ++--- src/carrera/carrera.controller.ts | 9 +-- src/carrera/carrera.service.ts | 16 ++--- src/carrera/dto/carrera-get-dto.ts | 6 +- src/carrito/carrito.controller.ts | 29 ++++++--- src/carrito/carrito.service.ts | 61 +++++++++++-------- src/carrito/dto/carrito-create.dto.ts | 12 ++-- src/carrito/dto/carrito-update.dto.ts | 18 +++--- src/carrito/dto/carrtio-get-dto.ts | 24 ++++---- src/equipo/dto/equipo.dto.ts | 4 +- src/equipo/equipo.controller.ts | 6 +- src/equipo/equipo.service.ts | 24 +++++--- 16 files changed, 179 insertions(+), 131 deletions(-) diff --git a/src/carrera-programa/carrera-programa.controller.ts b/src/carrera-programa/carrera-programa.controller.ts index 8c26f8a..f5f36d4 100644 --- a/src/carrera-programa/carrera-programa.controller.ts +++ b/src/carrera-programa/carrera-programa.controller.ts @@ -1,7 +1,7 @@ import { Body, Controller, Delete, Get, Post, Put } from '@nestjs/common'; import { CarreraProgramaService } from './carrera-programa.service'; -import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto' -import { CarreraProgramaUpdateDto } from './dto/carrera-programa-update.dto' +import { CarreraProgramaCreateDto } from './dto/carrera-programa-create.dto'; +import { CarreraProgramaUpdateDto } from './dto/carrera-programa-update.dto'; @Controller('carrera-programa') export class CarreraProgramaController { @@ -9,7 +9,10 @@ export class CarreraProgramaController { @Post() create(@Body() body: CarreraProgramaCreateDto) { - return this.carreraProgramaService.create(body.id_carrera, body.id_programa) + return this.carreraProgramaService.create( + body.id_carrera, + body.id_programa, + ); } @Delete() @@ -17,11 +20,11 @@ export class CarreraProgramaController { @Get() get() { - return this.carreraProgramaService.findAll() + return this.carreraProgramaService.findAll(); } @Put() update(@Body() body: CarreraProgramaUpdateDto) { - return this.carreraProgramaService.update(body) + return this.carreraProgramaService.update(body); } } diff --git a/src/carrera-programa/carrera-programa.module.ts b/src/carrera-programa/carrera-programa.module.ts index 596dead..173b7a1 100644 --- a/src/carrera-programa/carrera-programa.module.ts +++ b/src/carrera-programa/carrera-programa.module.ts @@ -3,9 +3,15 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { CarreraProgramaController } from './carrera-programa.controller'; import { CarreraProgramaService } from './carrera-programa.service'; import { CarreraPrograma } from './entity/carrera-programa.entity'; +import { CarritoModule } from 'src/carrito/carrito.module'; +import { ProgramaModule } from 'src/programa/programa.module'; @Module({ - imports: [TypeOrmModule.forFeature([CarreraPrograma])], + imports: [ + TypeOrmModule.forFeature([CarreraPrograma]), + CarritoModule, + ProgramaModule, + ], controllers: [CarreraProgramaController], providers: [CarreraProgramaService], }) diff --git a/src/carrera-programa/carrera-programa.service.ts b/src/carrera-programa/carrera-programa.service.ts index 8e044f8..2615638 100644 --- a/src/carrera-programa/carrera-programa.service.ts +++ b/src/carrera-programa/carrera-programa.service.ts @@ -1,11 +1,13 @@ -import {ConflictException, +import { + ConflictException, Injectable, - NotFoundException, } from '@nestjs/common'; + NotFoundException, +} from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { CarreraPrograma } from './entity/carrera-programa.entity'; -import { CarreraService } from '../carrera/carrera.service' -import { ProgramaService } from '../programa/programa.service' +import { CarreraService } from '../carrera/carrera.service'; +import { ProgramaService } from '../programa/programa.service'; @Injectable() export class CarreraProgramaService { @@ -14,49 +16,55 @@ export class CarreraProgramaService { private repository: Repository, private carreraService: CarreraService, private programaService: ProgramaService, - ) { } - + ) {} + async create(id_carrera: number, id_programa: number) { - const carrera = await this.carreraService.findById(id_carrera) - const programa = await this.programaService.findById(id_programa) + const carrera = await this.carreraService.findById(id_carrera); + const programa = await this.programaService.findById(id_programa); const nuevoCarreraPrograma = this.repository.create({ - carrera, programa, + carrera, + programa, }); return this.repository .findOne({ carrera, programa }) .then((existeCarretaPrograma) => { if (existeCarretaPrograma) - throw new ConflictException('Ya existe una carrera programa con este nombre, intente con uno diferente') - return this.repository.save(nuevoCarreraPrograma) + throw new ConflictException( + 'Ya existe una carrera programa con este nombre, intente con uno diferente', + ); + return this.repository.save(nuevoCarreraPrograma); }) - .then(() => ({message: 'se creo correctamente la carrera programa'})) + .then(() => ({ message: 'se creo correctamente la carrera programa' })); } findAll() { - return this.repository.find() + return this.repository.find(); } findById(id_carrera_programa: number) { - return this.repository.findOne({ id_carrera_programa }).then((carreraPrograma) => { - if(!carreraPrograma) throw new NotFoundException('No existe esta carrera programa') - return carreraPrograma - }) + return this.repository + .findOne({ id_carrera_programa }) + .then((carreraPrograma) => { + if (!carreraPrograma) + throw new NotFoundException('No existe esta carrera programa'); + return carreraPrograma; + }); } async update(attrs: Partial) { - const carreraPrograma = await this.findById(attrs.id_carrera_programa) + const carreraPrograma = await this.findById(attrs.id_carrera_programa); return this.repository - .findOne({ id_carrera_programa: attrs.id_carrera_programa}) + .findOne({ id_carrera_programa: attrs.id_carrera_programa }) .then((existeCarreraPrograma) => { if (existeCarreraPrograma) - throw new ConflictException('Ya existe esta carrera programa') - Object.assign(carreraPrograma, attrs) - return this.repository.save(carreraPrograma) + throw new ConflictException('Ya existe esta carrera programa'); + Object.assign(carreraPrograma, attrs); + return this.repository.save(carreraPrograma); }) .then(() => ({ - message: "Se actualizo correctamente la carrera programa" - })) + message: 'Se actualizo correctamente la carrera programa', + })); } } diff --git a/src/carrera-programa/dto/carrera-programa-create.dto.ts b/src/carrera-programa/dto/carrera-programa-create.dto.ts index f10a54f..6905da5 100644 --- a/src/carrera-programa/dto/carrera-programa-create.dto.ts +++ b/src/carrera-programa/dto/carrera-programa-create.dto.ts @@ -1,9 +1,9 @@ -import {IsNumber} from 'class-validator'; +import { IsNumber } from 'class-validator'; export class CarreraProgramaCreateDto { - @IsNumber() - id_carrera: number; + @IsNumber() + id_carrera: number; - @IsNumber() - id_programa: number; + @IsNumber() + id_programa: number; } diff --git a/src/carrera-programa/dto/carrera-programa-update.dto.ts b/src/carrera-programa/dto/carrera-programa-update.dto.ts index 05b1891..05c9ccc 100644 --- a/src/carrera-programa/dto/carrera-programa-update.dto.ts +++ b/src/carrera-programa/dto/carrera-programa-update.dto.ts @@ -1,12 +1,12 @@ -import {IsNumber} from 'class-validator'; +import { IsNumber } from 'class-validator'; export class CarreraProgramaUpdateDto { - @IsNumber() - id_carrera_programa: number; + @IsNumber() + id_carrera_programa: number; - @IsNumber() - id_carrera: number; + @IsNumber() + id_carrera: number; - @IsNumber() - id_programa: number; + @IsNumber() + id_programa: number; } diff --git a/src/carrera/carrera.controller.ts b/src/carrera/carrera.controller.ts index e363c90..1d11cf8 100644 --- a/src/carrera/carrera.controller.ts +++ b/src/carrera/carrera.controller.ts @@ -1,6 +1,6 @@ import { Controller, Get, Query } from '@nestjs/common'; import { CarreraService } from './carrera.service'; -import {CarritoGetDto} from './dto/carrera-get-dto' +import { CarritoGetDto } from './dto/carrera-get-dto'; @Controller('carrera') export class CarreraController { @@ -8,11 +8,12 @@ export class CarreraController { @Get() get() { - return this.carreraService.findAll() + // recibir id_institucion y traer todoas las carreras de esa institiucion + return this.carreraService.findAll(); } - @Get("carreras") + @Get('carreras') carreras(@Query() query: CarritoGetDto) { - return this.carreraService.findById(Number(query.id_carrera)) + return this.carreraService.findById(Number(query.id_carrera)); } } diff --git a/src/carrera/carrera.service.ts b/src/carrera/carrera.service.ts index 7534f83..835e07c 100644 --- a/src/carrera/carrera.service.ts +++ b/src/carrera/carrera.service.ts @@ -1,6 +1,8 @@ -import { ConflictException, +import { + ConflictException, Injectable, - NotFoundException,} from '@nestjs/common'; + NotFoundException, +} from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Carrera } from './entity/carrera.entity'; @@ -9,16 +11,16 @@ import { Carrera } from './entity/carrera.entity'; export class CarreraService { constructor( @InjectRepository(Carrera) private repository: Repository, - ) { } - + ) {} + findAll() { return this.repository.find(); } findById(id_carrera: number) { return this.repository.findOne({ id_carrera }).then((carrera) => { - if (!carrera) throw new NotFoundException('No existe esta carrera') - return carrera - }) + if (!carrera) throw new NotFoundException('No existe esta carrera'); + return carrera; + }); } } diff --git a/src/carrera/dto/carrera-get-dto.ts b/src/carrera/dto/carrera-get-dto.ts index 9e0ea33..2ff0853 100644 --- a/src/carrera/dto/carrera-get-dto.ts +++ b/src/carrera/dto/carrera-get-dto.ts @@ -1,6 +1,6 @@ -import { IsString } from 'class-validator'; +import { IsString } from 'class-validator'; export class CarritoGetDto { - @IsString() - id_carrera: string; + @IsString() + id_carrera: string; } diff --git a/src/carrito/carrito.controller.ts b/src/carrito/carrito.controller.ts index 7fbdbe3..6a2334f 100644 --- a/src/carrito/carrito.controller.ts +++ b/src/carrito/carrito.controller.ts @@ -1,8 +1,8 @@ import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; import { CarritoService } from './carrito.service'; -import { CarritoCreateDto } from './dto/carrito-create.dto' -import { CarritoUpdateDto } from './dto/carrito-update.dto' -import { CarritoGetDto} from './dto/carrtio-get-dto' +import { CarritoCreateDto } from './dto/carrito-create.dto'; +import { CarritoUpdateDto } from './dto/carrito-update.dto'; +import { CarritoGetDto } from './dto/carrtio-get-dto'; @Controller('carrito') export class CarritoController { @@ -10,7 +10,11 @@ export class CarritoController { @Post() create(@Body() body: CarritoCreateDto) { - return this.carritoService.create(body.id_tipo_carrito, body.id_modulo, body.carrito) + return this.carritoService.create( + body.id_tipo_carrito, + body.id_modulo, + body.carrito, + ); } @Get() @@ -20,19 +24,24 @@ export class CarritoController { @Get('carrito') carrito(@Query() query: CarritoGetDto) { - return this.carritoService.findById(Number(query.id_carrito)) + return this.carritoService.findById(Number(query.id_carrito)); } @Get('carritos') - carritos(@Query() query: CarritoGetDto) { - return this.carritoService.findByIdModulo(Number(query.pagina), Number(query.id_modulo), Number(query.id_tipo_carrito), query.activo === "true") + carritos(@Query() query: CarritoGetDto) { + return this.carritoService.findByIdModulo( + Number(query.pagina), + Number(query.id_modulo), + Number(query.id_tipo_carrito), + query.activo === 'true', + ); } - + @Get('carritoInstitucion') - carritosInstitucion() { } + carritosInstitucion() {} @Put() update(@Body() body: CarritoUpdateDto) { - return this.carritoService.update(body) + return this.carritoService.update(body); } } diff --git a/src/carrito/carrito.service.ts b/src/carrito/carrito.service.ts index bc566a7..7224497 100644 --- a/src/carrito/carrito.service.ts +++ b/src/carrito/carrito.service.ts @@ -1,55 +1,70 @@ -import { ConflictException, Injectable, NotFoundException } from '@nestjs/common'; +import { + ConflictException, + Injectable, + NotFoundException, +} from '@nestjs/common'; import { Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; import { Carrito } from './entity/carrito.entity'; -import { ModuloService } from '../modulo/modulo.service' -import {InstitucionTipoCarritoService } from '../institucion-tipo-carrito/institucion-tipo-carrito.service' +import { ModuloService } from '../modulo/modulo.service'; +import { InstitucionTipoCarritoService } from '../institucion-tipo-carrito/institucion-tipo-carrito.service'; @Injectable() export class CarritoService { constructor( @InjectRepository(Carrito) private repository: Repository, private moduloService: ModuloService, - private institucionTipoCarritoService: InstitucionTipoCarritoService - ) { } - + private institucionTipoCarritoService: InstitucionTipoCarritoService, + ) {} + async create(id_tipo_carrito: number, id_modulo: number, carrito: string) { - const modulo = await this.moduloService.findById(id_modulo) - const tipoCarrito = await this.institucionTipoCarritoService.findByIdTipoCarito(id_tipo_carrito) + const modulo = await this.moduloService.findById(id_modulo); + const tipoCarrito = + await this.institucionTipoCarritoService.findByIdTipoCarito( + id_tipo_carrito, + ); const nuevoCarrito = this.repository.create({ tipoCarrito, modulo, - carrito + carrito, }); return this.repository .findOne({ carrito, modulo }) .then((existeCarrito) => { if (existeCarrito) - throw new ConflictException('Este carrito ya existe en este modulo') - return this.repository.save(nuevoCarrito); + throw new ConflictException('Este carrito ya existe en este modulo'); + return this.repository.save(nuevoCarrito); }) - .then(()=>({message: 'Se creo correctamente el carrito en el modulo.'})) + .then(() => ({ + message: 'Se creo correctamente el carrito en el modulo.', + })); } findAll() { - return this.repository.find() + return this.repository.find(); } findById(id_carrito: number) { return this.repository.findOne({ id_carrito }).then((carrito) => { if (!carrito) throw new NotFoundException('No existe este carrito'); - return carrito - }) + return carrito; + }); } - findByIdModulo(pagina: number, id_modulo: number, id_tipo_carrito: number, activo: boolean) { - return this.repository.findOne( id_modulo ).then((modulo) => { - if (!modulo) throw new NotFoundException('No existen carritos es este modulo'); - return modulo - }) + findByIdModulo( + pagina: number, + id_modulo: number, + id_tipo_carrito: number, + activo: boolean, + ) { + return this.repository.findOne(id_modulo).then((modulo) => { + if (!modulo) + throw new NotFoundException('No existen carritos es este modulo'); + return modulo; + }); } - + async update(attrs: Partial) { const carrito = await this.findById(attrs.id_carrito); @@ -57,9 +72,7 @@ export class CarritoService { .findOne({ carrito: attrs.carrito, modulo: carrito.modulo }) .then((existeCarrito) => { if (existeCarrito) - throw new ConflictException( - 'Ya existe un carrito con este número.' - ); + throw new ConflictException('Ya existe un carrito con este número.'); Object.assign(carrito, attrs); return this.repository.save(carrito); }) diff --git a/src/carrito/dto/carrito-create.dto.ts b/src/carrito/dto/carrito-create.dto.ts index cc26cbd..9c354ac 100644 --- a/src/carrito/dto/carrito-create.dto.ts +++ b/src/carrito/dto/carrito-create.dto.ts @@ -1,12 +1,12 @@ import { IsNumber } from 'class-validator'; export class CarritoCreateDto { - @IsNumber() - id_tipo_carrito: number; + @IsNumber() + id_tipo_carrito: number; - @IsNumber() - id_modulo: number; + @IsNumber() + id_modulo: number; - @IsNumber() - carrito: string; + @IsNumber() + carrito: string; } diff --git a/src/carrito/dto/carrito-update.dto.ts b/src/carrito/dto/carrito-update.dto.ts index 134d3be..89c2f2c 100644 --- a/src/carrito/dto/carrito-update.dto.ts +++ b/src/carrito/dto/carrito-update.dto.ts @@ -1,14 +1,14 @@ import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator'; export class CarritoUpdateDto { - @IsNumber() - id_carrito: number; - - @IsNumber() - @IsOptional() - carrito?: string; + @IsNumber() + id_carrito: number; - @IsBoolean() - @IsOptional() - activo?: boolean; + @IsNumber() + @IsOptional() + carrito?: string; + + @IsBoolean() + @IsOptional() + activo?: boolean; } diff --git a/src/carrito/dto/carrtio-get-dto.ts b/src/carrito/dto/carrtio-get-dto.ts index bb84fde..c3e9459 100644 --- a/src/carrito/dto/carrtio-get-dto.ts +++ b/src/carrito/dto/carrtio-get-dto.ts @@ -1,19 +1,19 @@ import { IsOptional, IsString } from 'class-validator'; export class CarritoGetDto { - @IsString() - pagina: string; + @IsString() + pagina: string; - @IsString() - id_carrito: string; + @IsString() + id_carrito: string; - @IsString() - id_tipo_carrito: string; + @IsString() + id_tipo_carrito: string; - @IsString() - id_modulo: string; - - @IsString() - @IsOptional() - activo?: string; + @IsString() + id_modulo: string; + + @IsString() + @IsOptional() + activo?: string; } diff --git a/src/equipo/dto/equipo.dto.ts b/src/equipo/dto/equipo.dto.ts index 5ef2489..cee744a 100644 --- a/src/equipo/dto/equipo.dto.ts +++ b/src/equipo/dto/equipo.dto.ts @@ -1,6 +1,6 @@ import { IsString } from 'class-validator'; export class EquipoDto { - @IsString() - id_equipo: string; + @IsString() + id_equipo: string; } diff --git a/src/equipo/equipo.controller.ts b/src/equipo/equipo.controller.ts index f0676d0..23fc0c6 100644 --- a/src/equipo/equipo.controller.ts +++ b/src/equipo/equipo.controller.ts @@ -1,6 +1,6 @@ import { Controller, Get, Post, Put, Query } from '@nestjs/common'; import { EquipoService } from './equipo.service'; -import { EquipoDto } from './dto/equipo.dto' +import { EquipoDto } from './dto/equipo.dto'; @Controller('equipo') export class EquipoController { @@ -11,12 +11,12 @@ export class EquipoController { @Get() get() { - return this.equipoService.findAll() + return this.equipoService.findAll(); } @Get('equipo') equipo(@Query() query: EquipoDto) { - return this.equipoService.findById(Number(query.id_equipo)) + return this.equipoService.findById(Number(query.id_equipo)); } @Get('equipos') diff --git a/src/equipo/equipo.service.ts b/src/equipo/equipo.service.ts index 3dbfbe8..9f1e53e 100644 --- a/src/equipo/equipo.service.ts +++ b/src/equipo/equipo.service.ts @@ -7,20 +7,26 @@ import { Equipo } from './entity/equipo.entity'; export class EquipoService { constructor( @InjectRepository(Equipo) private repository: Repository, - ) { } - - async create(equipo: string, numero_inventario: string, numero_serie: string, prestado: boolean, id_carrito: number, id_programa: number, id_status: number) { - - } + ) {} + + async create( + equipo: string, + numero_inventario: string, + numero_serie: string, + prestado: boolean, + id_carrito: number, + id_programa: number, + id_status: number, + ) {} findAll() { - return this.repository.find() + return this.repository.find(); } findById(id_equipo: number) { return this.repository.findOne({ id_equipo }).then((equipo) => { - if(!equipo) throw new NotFoundException('No existe este equipo') - return equipo - }) + if (!equipo) throw new NotFoundException('No existe este equipo'); + return equipo; + }); } }