a medias
This commit is contained in:
parent
2845660f05
commit
74c05d5071
@ -1,9 +1,4 @@
|
||||
import {
|
||||
IsBoolean,
|
||||
IsInt,
|
||||
IsMilitaryTime,
|
||||
IsOptional,
|
||||
} from 'class-validator';
|
||||
import { IsBoolean, IsInt, IsMilitaryTime, IsOptional } from 'class-validator';
|
||||
|
||||
export class InstitucionDiaUpdateDto {
|
||||
@IsInt()
|
||||
@ -11,13 +6,13 @@ export class InstitucionDiaUpdateDto {
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
activo: boolean;
|
||||
activo?: boolean;
|
||||
|
||||
@IsMilitaryTime()
|
||||
@IsOptional()
|
||||
hora_fin: string;
|
||||
hora_fin?: string;
|
||||
|
||||
@IsMilitaryTime()
|
||||
@IsOptional()
|
||||
hora_inicio: string;
|
||||
hora_inicio?: string;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InstitucionInfraccion } from './entity/institucion-infraccion.entity';
|
||||
import { Infraccion } from './entity/infraccion.entity';
|
||||
import { InstitucionService } from 'src/institucion/institucion.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@Injectable()
|
||||
export class InstitucionInfraccionService {
|
||||
|
@ -7,7 +7,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InstitucionTipoCarrito } from './entity/institucion-tipo-carrito.entity';
|
||||
import { TipoCarrito } from './entity/tipo-carrito.entity';
|
||||
import { InstitucionService } from 'src/institucion/institucion.service';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
|
||||
@Injectable()
|
||||
export class InstitucionTipoCarritoService {
|
||||
|
@ -6,17 +6,17 @@ export class InstitucionUpdateDto {
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
dias_multa_retraso: number;
|
||||
dias_multa_retraso?: number;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
tiempo_entrega: number;
|
||||
tiempo_entrega?: number;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
tiempo_prestamo: number;
|
||||
tiempo_prestamo?: number;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
tiempo_recoger: number;
|
||||
tiempo_recoger?: number;
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ import { TipoUsuario } from './entity/tipo-usuario.entity';
|
||||
imports: [TypeOrmModule.forFeature([TipoUsuario])],
|
||||
controllers: [TipoUsuarioController],
|
||||
providers: [TipoUsuarioService],
|
||||
exports: [TipoUsuarioService],
|
||||
})
|
||||
export class TipoUsuarioModule {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { TipoUsuario } from './entity/tipo-usuario.entity';
|
||||
@ -8,4 +8,12 @@ export class TipoUsuarioService {
|
||||
constructor(
|
||||
@InjectRepository(TipoUsuario) private repository: Repository<TipoUsuario>,
|
||||
) {}
|
||||
|
||||
findById(id_tipo_usuario: number) {
|
||||
return this.repository.findOne({ id_tipo_usuario }).then((tipoUsuario) => {
|
||||
if (!tipoUsuario)
|
||||
throw new NotFoundException('No existe este tipo usuairo');
|
||||
return tipoUsuario;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
6
src/usuario/dto/usuario-escolares.dto.ts
Normal file
6
src/usuario/dto/usuario-escolares.dto.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class UsuarioEscolaresDto {
|
||||
@IsNumberString()
|
||||
usuario: string;
|
||||
}
|
9
src/usuario/dto/usuario-login.dto.ts
Normal file
9
src/usuario/dto/usuario-login.dto.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { IsNumberString, IsString } from 'class-validator';
|
||||
|
||||
export class UsuarioLoginDto {
|
||||
@IsNumberString()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
9
src/usuario/dto/usuario-registrar.dto.ts
Normal file
9
src/usuario/dto/usuario-registrar.dto.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { IsInt, IsPhoneNumber } from 'class-validator';
|
||||
|
||||
export class UsuarioRegistrarDto {
|
||||
@IsInt()
|
||||
id_usuario: number;
|
||||
|
||||
@IsPhoneNumber('MX')
|
||||
telefono: string;
|
||||
}
|
18
src/usuario/dto/usuario-update.dto.ts
Normal file
18
src/usuario/dto/usuario-update.dto.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { IsBoolean, IsInt, IsOptional, IsPhoneNumber } from 'class-validator';
|
||||
|
||||
export class UsuarioUpdateDto {
|
||||
@IsInt()
|
||||
id_usuario: number;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
activo?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
multa?: boolean;
|
||||
|
||||
@IsPhoneNumber()
|
||||
@IsOptional()
|
||||
telefono?: string;
|
||||
}
|
22
src/usuario/dto/usuario-usuarios.dto.ts
Normal file
22
src/usuario/dto/usuario-usuarios.dto.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { IsNumberString, IsOptional } from 'class-validator';
|
||||
|
||||
export class UsuarioUsuariosDto {
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_carrera: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_institucion: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_tipo_usuario: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
usuario: string;
|
||||
}
|
6
src/usuario/dto/usuario.dto.ts
Normal file
6
src/usuario/dto/usuario.dto.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class UsuarioDto {
|
||||
@IsNumberString()
|
||||
usuario: string;
|
||||
}
|
@ -25,6 +25,9 @@ export class Usuario {
|
||||
@Column({ type: String, nullable: false, length: 60 })
|
||||
password: string;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 10 })
|
||||
telefono: string;
|
||||
|
||||
@Column({ type: String, nullable: false, length: 10 })
|
||||
usuario: string;
|
||||
|
||||
|
@ -1,25 +1,42 @@
|
||||
import { Controller, Get, Post, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { UsuarioService } from './usuario.service';
|
||||
import { UsuarioEscolaresDto } from './dto/usuario-escolares.dto';
|
||||
import { UsuarioLoginDto } from './dto/usuario-login.dto';
|
||||
import { UsuarioRegistrarDto } from './dto/usuario-registrar.dto';
|
||||
import { UsuarioUpdateDto } from './dto/usuario-update.dto';
|
||||
import { UsuarioUsuariosDto } from './dto/usuario-usuarios.dto';
|
||||
import { UsuarioDto } from './dto/usuario.dto';
|
||||
|
||||
@Controller('usuario')
|
||||
export class UsuarioController {
|
||||
constructor(private usuarioService: UsuarioService) {}
|
||||
|
||||
@Get()
|
||||
get() {}
|
||||
/* Pendiente por conexión */
|
||||
@Get('escolares')
|
||||
escolares(@Query() query: UsuarioEscolaresDto) {}
|
||||
|
||||
@Post('login')
|
||||
login() {}
|
||||
login(@Body() body: UsuarioLoginDto) {
|
||||
return this.usuarioService.login(body.usuario, body.password);
|
||||
}
|
||||
|
||||
@Post('registrar')
|
||||
registrar() {}
|
||||
registrar(@Body() body: UsuarioRegistrarDto) {
|
||||
return this.usuarioService.registrar(body.id_usuario, body.telefono);
|
||||
}
|
||||
|
||||
@Put()
|
||||
update() {}
|
||||
update(@Body() body: UsuarioUpdateDto) {
|
||||
return this.usuarioService.update(body);
|
||||
}
|
||||
|
||||
@Get('usuario')
|
||||
usuario() {}
|
||||
usuario(@Query() query: UsuarioDto) {
|
||||
return this.usuarioService.findByUsuario(query.usuario);
|
||||
}
|
||||
|
||||
@Get('usuarios')
|
||||
usuarios() {}
|
||||
usuarios(@Query() query: UsuarioUsuariosDto) {
|
||||
return this.usuarioService.findAll(query);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,15 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { UsuarioController } from './usuario.controller';
|
||||
import { UsuarioService } from './usuario.service';
|
||||
import { Usuario } from './entity/usuario.entity';
|
||||
import { InstitucionModule } from '../institucion/institucion.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Usuario])],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Usuario]),
|
||||
InstitucionModule,
|
||||
TipoUsuarioModule,
|
||||
],
|
||||
controllers: [UsuarioController],
|
||||
providers: [UsuarioService],
|
||||
})
|
||||
|
@ -1,11 +1,81 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Usuario } from './entity/usuario.entity';
|
||||
import { InstitucionService } from '../institucion/institucion.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
|
||||
@Injectable()
|
||||
export class UsuarioService {
|
||||
constructor(
|
||||
@InjectRepository(Usuario) private repository: Repository<Usuario>,
|
||||
private institucionService: InstitucionService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
) {}
|
||||
|
||||
async findAll(filtros: {
|
||||
pagina: string;
|
||||
id_carrera?: string;
|
||||
id_institucion?: string;
|
||||
id_tipo_usuario?: string;
|
||||
usuario?: string;
|
||||
}) {
|
||||
const institucion = filtros.id_institucion
|
||||
? this.institucionService.findById(Number(filtros.id_institucion))
|
||||
: null;
|
||||
const tipoUsuario = filtros.id_tipo_usuario
|
||||
? this.tipoUsuarioService.findById(Number(filtros.id_tipo_usuario))
|
||||
: null;
|
||||
const updtae = {};
|
||||
/* Terminar cuando se tengan las fuinciones faltantes */
|
||||
}
|
||||
|
||||
findById(id_usuario: number) {
|
||||
return this.repository.findOne({ id_usuario }).then((usuario) => {
|
||||
if (!usuario) throw new NotFoundException('No existe este usuario.');
|
||||
return usuario;
|
||||
});
|
||||
}
|
||||
|
||||
findByUsuario(usuario: string) {
|
||||
return this.repository.findOne({ usuario }).then((usuario) => {
|
||||
if (!usuario) throw new NotFoundException('No existe este usuario.');
|
||||
return usuario;
|
||||
});
|
||||
}
|
||||
|
||||
login(usuario: string, password: string) {
|
||||
return this.findByUsuario(usuario).then((usuario) => {
|
||||
if (password !== usuario.password)
|
||||
throw new UnauthorizedException('Contraseña incorrecta');
|
||||
/* Crear JWT y regresarlo */
|
||||
return usuario;
|
||||
});
|
||||
}
|
||||
|
||||
registrar(id_usuario: number, telefono: string) {
|
||||
return this.findById(id_usuario)
|
||||
.then((usuario) => {
|
||||
usuario.telefono = telefono;
|
||||
/* crear contraseña, encriptarla y mandarla por correo */
|
||||
usuario.password = 'hola';
|
||||
return this.repository.save(usuario);
|
||||
})
|
||||
.then((_) => ({ message: 'Se creo correctamente un usuario.' }));
|
||||
}
|
||||
|
||||
async update(attrs: Partial<Usuario>) {
|
||||
return this.findById(attrs.id_usuario)
|
||||
.then((usuario) => {
|
||||
Object.assign(usuario, attrs);
|
||||
return this.repository.save(usuario);
|
||||
})
|
||||
.then((_) => ({
|
||||
message: 'Se actualizo correctamente la información del usuario.',
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user