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 { CreateAlumnoSancionDto } from './dto/create-alumno_sancion.dto';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
|
||||
@Controller('alumno-sancion')
|
||||
export class AlumnoSancionController {
|
||||
constructor(private readonly alumnoSancionService: AlumnoSancionService) {}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Body() createAlumnoSancionDto: CreateAlumnoSancionDto,
|
||||
): Promise<AlumnoSancion> {
|
||||
return this.alumnoSancionService.create(createAlumnoSancionDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.alumnoSancionService.findAll();
|
||||
|
||||
@@ -2,6 +2,9 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AlumnoSancion } from './entities/alumno_sancion.entity';
|
||||
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()
|
||||
export class AlumnoSancionService {
|
||||
@@ -10,13 +13,27 @@ export class AlumnoSancionService {
|
||||
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() {
|
||||
return `This action returns all alumnoSancion`;
|
||||
}
|
||||
|
||||
async findOne(id_cuenta: number): Promise<AlumnoSancion> {
|
||||
const alusancion = await this.alumnosancionRepository.findOne({
|
||||
where: { id_cuenta:{id_cuenta} },
|
||||
where: { id_cuenta: { id_cuenta } },
|
||||
});
|
||||
if (!alusancion) {
|
||||
throw new NotFoundException(`Student with ID ${id_cuenta} not found`);
|
||||
|
||||
@@ -8,8 +8,4 @@ export class CreateAlumnoSancionDto {
|
||||
@IsNotEmpty()
|
||||
@IsInt()
|
||||
id_cuenta: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
fecha_inicio?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user