formateo
This commit is contained in:
parent
a164859043
commit
e04091d74f
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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],
|
||||
})
|
||||
|
@ -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<CarreraPrograma>,
|
||||
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<CarreraPrograma>) {
|
||||
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',
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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<Carrera>,
|
||||
) { }
|
||||
|
||||
) {}
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Carrito>,
|
||||
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<Carrito>) {
|
||||
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);
|
||||
})
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class EquipoDto {
|
||||
@IsString()
|
||||
id_equipo: string;
|
||||
@IsString()
|
||||
id_equipo: string;
|
||||
}
|
||||
|
@ -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')
|
||||
|
@ -7,20 +7,26 @@ import { Equipo } from './entity/equipo.entity';
|
||||
export class EquipoService {
|
||||
constructor(
|
||||
@InjectRepository(Equipo) private repository: Repository<Equipo>,
|
||||
) { }
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user