add comments
This commit is contained in:
@@ -22,12 +22,14 @@ import { LineasProgramaticasController } from './lineasProgramaticas/lineasProgr
|
||||
import { LineasProgramaticasService } from './lineasProgramaticas/lineasProgramaticas.service';
|
||||
import { LineasProgramaticasModule } from './lineasProgramaticas/lineasProgramaticas.module';
|
||||
import { CarreraModule } from './carrera/carreras.module';
|
||||
import { ComentariosModule } from './comentarios/comentarios.module';
|
||||
config({ path: '.env' });
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule,
|
||||
UsersModule,
|
||||
EjesEstrategicosModule,
|
||||
ComentariosModule,
|
||||
LineasProgramaticasModule,
|
||||
CarreraModule,
|
||||
ConfigModule.forRoot({
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Header,
|
||||
HttpCode,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { Controller, Get, Header, HttpCode, Logger } from '@nestjs/common';
|
||||
|
||||
import { CarrerasService } from './carreras.service';
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { EjeEstrategico } from '../entities/ejesEstrategicos.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Carrera } from '../entities/carreras.entity';
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Header,
|
||||
HttpCode,
|
||||
Logger,
|
||||
Post,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
|
||||
import { ComentariosService } from './comentarios.service';
|
||||
import { AuthGuard } from '../auth/auth.guard';
|
||||
import { ComentarioDTO } from '../dtos/comentarioDTO';
|
||||
|
||||
@Controller('comentario')
|
||||
export class ComentariosController {
|
||||
constructor(private readonly comentariosService: ComentariosService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Header('content-type', 'application/json')
|
||||
@Get('comentarios')
|
||||
@HttpCode(200)
|
||||
getComentarios() {
|
||||
Logger.log('Comentarios', 'getComentarios');
|
||||
return this.comentariosService.findComentarios();
|
||||
}
|
||||
@UseGuards(AuthGuard)
|
||||
@Header('content-type', 'application/json')
|
||||
@Post('addComentario')
|
||||
@HttpCode(200)
|
||||
setComentario(@Body() comentario: ComentarioDTO) {
|
||||
Logger.log('Comentarios', 'setComentario');
|
||||
return this.comentariosService.addComentarios(comentario);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ComentarioEje } from '../entities/comentarioEjes.entity';
|
||||
import { ComentariosService } from './comentarios.service';
|
||||
import { ComentariosController } from './comentarios.controller';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([ComentarioEje])],
|
||||
providers: [ComentariosService],
|
||||
controllers: [ComentariosController],
|
||||
exports: [TypeOrmModule.forFeature([ComentariosService])],
|
||||
})
|
||||
export class ComentariosModule {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ComentarioEje } from '../entities/comentarioEjes.entity';
|
||||
import { ComentarioDTO } from '../dtos/comentarioDTO';
|
||||
|
||||
@Injectable()
|
||||
export class ComentariosService {
|
||||
constructor(
|
||||
@InjectRepository(ComentarioEje)
|
||||
private comentariosRepository: Repository<ComentarioEje>,
|
||||
) {}
|
||||
|
||||
findComentarios(): Promise<ComentarioEje[]> {
|
||||
return this.comentariosRepository.find({});
|
||||
}
|
||||
|
||||
addComentarios(comentario: ComentarioDTO): Promise<ComentarioEje> {
|
||||
return this.comentariosRepository.save(comentario);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
IsDefined,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsString,
|
||||
} from '@nestjs/class-validator';
|
||||
|
||||
export class ComentarioDTO {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsDefined()
|
||||
readonly comentario: string;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
readonly usuario_id: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
readonly linea_programatica_id: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
readonly eje_estrategico_id: number;
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
import { IsDefined, IsNotEmpty, IsNumber, IsString } from "@nestjs/class-validator";
|
||||
import {
|
||||
IsDefined,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsString,
|
||||
} from '@nestjs/class-validator';
|
||||
|
||||
export class LoginDTO {
|
||||
@IsString()
|
||||
@@ -12,11 +17,10 @@ export class LoginDTO {
|
||||
@IsString()
|
||||
readonly fecha_nacimiento: string;
|
||||
|
||||
@IsNumber()
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
readonly tipo_usuario: number;
|
||||
|
||||
|
||||
@IsNumber()
|
||||
@IsInt()
|
||||
readonly id_carrera: number;
|
||||
}
|
||||
|
||||
@@ -36,4 +36,13 @@ export class ComentarioEje {
|
||||
|
||||
@Column('text')
|
||||
comentario: string;
|
||||
|
||||
@Column({ name: 'eje_estrategico_id' })
|
||||
eje_estrategico_id: number;
|
||||
|
||||
@Column({ name: 'usuario_id' })
|
||||
usuario_id: number;
|
||||
|
||||
@Column({ name: 'linea_programatica_id' })
|
||||
linea_programatica_id: number;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { UsuarioEntity } from '../entities/usuario.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { LoginDTO } from '../dtos/loginDTO';
|
||||
import { isUndefined } from '@nestjs/common/utils/shared.utils';
|
||||
import { isInt } from '@nestjs/class-validator';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -19,6 +24,10 @@ export class UsersService {
|
||||
const numero_identificacion = loginDto.numero_identificacion;
|
||||
const fecha_nacimiento = loginDto.fecha_nacimiento;
|
||||
const carrera_id = loginDto.id_carrera;
|
||||
|
||||
if (isUndefined(carrera_id) || !isInt(carrera_id)) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
return this.usersRepository.findOneBy({
|
||||
numero_identificacion,
|
||||
fecha_nacimiento,
|
||||
|
||||
Reference in New Issue
Block a user