formateo
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user