correo forzoso en registro
This commit is contained in:
parent
13dd9a0cfb
commit
f9849326aa
14
src/institucion-usuario/dto/input/update.dto.ts
Normal file
14
src/institucion-usuario/dto/input/update.dto.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { IsBoolean, IsInt, IsOptional } from 'class-validator';
|
||||
|
||||
export class UpdateInstitucionUsuarioInputDto {
|
||||
@IsInt()
|
||||
id_institucion_usuario: number;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
activo?: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
multa?: boolean;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { InstitucionUsuarioController } from './institucion-usuario.controller';
|
||||
|
||||
describe('InstitucionUsuarioController', () => {
|
||||
let controller: InstitucionUsuarioController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [InstitucionUsuarioController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<InstitucionUsuarioController>(InstitucionUsuarioController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
51
src/institucion-usuario/institucion-usuario.controller.ts
Normal file
51
src/institucion-usuario/institucion-usuario.controller.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
ForbiddenException,
|
||||
Put,
|
||||
Request,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { InstitucionUsuarioService } from './institucion-usuario.service';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { UpdateInstitucionUsuarioInputDto } from './dto/input/update.dto';
|
||||
|
||||
@Controller('institucion-usuario')
|
||||
@ApiTags('institucion-usuario')
|
||||
export class InstitucionUsuarioController {
|
||||
constructor(private institucionUsuarioService: InstitucionUsuarioService) {}
|
||||
|
||||
@Put()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description: 'Enpoint que actualiza la información de un usuario.',
|
||||
})
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiBody({
|
||||
description: 'Todas las variables a excepción de id_ son opcionales.',
|
||||
examples: {
|
||||
ejemplo: {
|
||||
value: {
|
||||
correo: '',
|
||||
id_usuario: 1,
|
||||
telefono: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
update(@Request() req, @Body() body: UpdateInstitucionUsuarioInputDto) {
|
||||
const admin: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
!admin ||
|
||||
(admin.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
admin.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
return this.institucionUsuarioService.update(body);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import { PassportModule } from '@nestjs/passport';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { InstitucionUsuarioService } from './institucion-usuario.service';
|
||||
import { InstitucionUsuario } from './entity/institucion-usuario.entity';
|
||||
import { InstitucionUsuarioController } from './institucion-usuario.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -11,5 +12,6 @@ import { InstitucionUsuario } from './entity/institucion-usuario.entity';
|
||||
],
|
||||
providers: [InstitucionUsuarioService],
|
||||
exports: [InstitucionUsuarioService],
|
||||
controllers: [InstitucionUsuarioController],
|
||||
})
|
||||
export class InstitucionUsuarioModule {}
|
||||
|
@ -30,10 +30,6 @@ export class UpdateInstitucionDto {
|
||||
@IsOptional()
|
||||
dominio?: string;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
email_institucional?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsOptional()
|
||||
|
@ -19,9 +19,6 @@ export class InstitucionOutputDto {
|
||||
@Expose()
|
||||
dominio;
|
||||
|
||||
@Expose()
|
||||
email_institucional;
|
||||
|
||||
@Expose()
|
||||
institucion;
|
||||
|
||||
|
@ -8,5 +8,5 @@ export class InstitucionesMinOutputDto {
|
||||
institucion;
|
||||
|
||||
@Expose()
|
||||
email_institucional;
|
||||
dominio;
|
||||
}
|
||||
|
@ -127,7 +127,6 @@ export class InstitucionController {
|
||||
_activo: true,
|
||||
_dias_multa_retraso: 7,
|
||||
_dominio: '@pcpuma.acatlan.unam.mx',
|
||||
_email_institucional: true,
|
||||
_responsable: '',
|
||||
_telefono: '',
|
||||
_tiempo_entrega: 15,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IsEmail, IsInt, IsOptional, IsPhoneNumber } from 'class-validator';
|
||||
import { IsEmail, IsInt, IsPhoneNumber } from 'class-validator';
|
||||
|
||||
export class RegistrarUsuarioInputDto {
|
||||
@IsInt()
|
||||
@ -8,6 +8,5 @@ export class RegistrarUsuarioInputDto {
|
||||
telefono: string;
|
||||
|
||||
@IsEmail()
|
||||
@IsOptional()
|
||||
correo?: string;
|
||||
correo: string;
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ import {
|
||||
ApiTags,
|
||||
} from '@nestjs/swagger';
|
||||
import { Recaptcha } from '@nestlab/google-recaptcha';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { UsuarioService } from './usuario.service';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { DgaeInputDto } from './dto/input/dgae.dto';
|
||||
import { DgpInputDto } from './dto/input/dgp.dto';
|
||||
import { RegistrarUsuarioInputDto } from './dto/input/registrar.dto';
|
||||
@ -94,8 +94,8 @@ export class UsuarioController {
|
||||
registrar(@Body() body: RegistrarUsuarioInputDto) {
|
||||
return this.usuarioService.registrar(
|
||||
body.id_institucion_usuario,
|
||||
body.telefono,
|
||||
body.correo,
|
||||
body.telefono,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -221,10 +221,9 @@ export class UsuarioService {
|
||||
}));
|
||||
}
|
||||
|
||||
registrar(id_institucion_usuario: number, telefono: string, correo?: string) {
|
||||
registrar(id_institucion_usuario: number, correo: string, telefono: string) {
|
||||
const password = this.bcryptService.generarPassword();
|
||||
let message =
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
||||
let message: string;
|
||||
|
||||
return this.institucionUsuarioService
|
||||
.findById(id_institucion_usuario)
|
||||
@ -236,15 +235,17 @@ export class UsuarioService {
|
||||
throw new ConflictException(
|
||||
'Ya fue registrado este número de cuenta.',
|
||||
);
|
||||
if (!institucion.email_institucional) {
|
||||
if (!correo)
|
||||
if (usuario.correo && correo != usuario.correo)
|
||||
throw new ConflictException(
|
||||
'No se envió un correo electrónico para el regístro.',
|
||||
'El correo ingresado no concuerda con el ingresado a escolares.',
|
||||
);
|
||||
else usuario.correo = correo;
|
||||
if (!institucion.dominio)
|
||||
message =
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo y consulta tu contraseña para acceder a este servicio.';
|
||||
} else usuario.correo = `${usuario.usuario}${institucion.dominio}`;
|
||||
else
|
||||
message =
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
||||
usuario.correo = correo;
|
||||
usuario.telefono = telefono;
|
||||
usuario.password = this.bcryptService.encriptar(password);
|
||||
return this.repository.save(usuario);
|
||||
|
Loading…
Reference in New Issue
Block a user