Verificacion de entities
This commit is contained in:
@@ -1,10 +1,19 @@
|
|||||||
import { Controller, Get, Param } from '@nestjs/common';
|
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||||
import { AlumnoSancionService } from './alumno_sancion.service';
|
import { AlumnoSancionService } from './alumno_sancion.service';
|
||||||
|
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||||
|
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||||
|
|
||||||
@Controller('alumno-sancion')
|
@Controller('alumno-sancion')
|
||||||
export class AlumnoSancionController {
|
export class AlumnoSancionController {
|
||||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
async create(
|
||||||
|
@Body() createAlumnoSancionDto: CreateAlumnoSancionDto,
|
||||||
|
): Promise<AlumnoSancion> {
|
||||||
|
return this.alumnoSancionService.create(createAlumnoSancionDto);
|
||||||
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.alumnoSancionService.findAll();
|
return this.alumnoSancionService.findAll();
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||||
|
import { Sancion } from 'src/sancion/entities/sancion.entity';
|
||||||
|
import { AlumnoService } from 'src/alumno/student.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlumnoSancionService {
|
export class AlumnoSancionService {
|
||||||
@@ -10,13 +13,27 @@ export class AlumnoSancionService {
|
|||||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
createAlumnoSancionDto: CreateAlumnoSancionDto,
|
||||||
|
): Promise<AlumnoSancion> {
|
||||||
|
const { id_sancion, id_cuenta } = createAlumnoSancionDto;
|
||||||
|
|
||||||
|
// Crear la entidad con relaciones
|
||||||
|
const alumnosancion = this.alumnosancionRepository.create({
|
||||||
|
id_sancion: { id_sancion }, // se asigna por FK
|
||||||
|
id_cuenta: { id_cuenta }, // se asigna por FK
|
||||||
|
});
|
||||||
|
|
||||||
|
return await this.alumnosancionRepository.save(alumnosancion);
|
||||||
|
}
|
||||||
|
|
||||||
findAll() {
|
findAll() {
|
||||||
return `This action returns all alumnoSancion`;
|
return `This action returns all alumnoSancion`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id_cuenta: number): Promise<AlumnoSancion> {
|
async findOne(id_cuenta: number): Promise<AlumnoSancion> {
|
||||||
const alusancion = await this.alumnosancionRepository.findOne({
|
const alusancion = await this.alumnosancionRepository.findOne({
|
||||||
where: { id_cuenta:{id_cuenta} },
|
where: { id_cuenta: { id_cuenta } },
|
||||||
});
|
});
|
||||||
if (!alusancion) {
|
if (!alusancion) {
|
||||||
throw new NotFoundException(`Student with ID ${id_cuenta} not found`);
|
throw new NotFoundException(`Student with ID ${id_cuenta} not found`);
|
||||||
|
|||||||
@@ -8,8 +8,4 @@ export class CreateAlumnoSancionDto {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsInt()
|
@IsInt()
|
||||||
id_cuenta: number;
|
id_cuenta: number;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsDateString()
|
|
||||||
fecha_inicio?: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user