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 { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { InstitucionUsuarioService } from './institucion-usuario.service';
|
import { InstitucionUsuarioService } from './institucion-usuario.service';
|
||||||
import { InstitucionUsuario } from './entity/institucion-usuario.entity';
|
import { InstitucionUsuario } from './entity/institucion-usuario.entity';
|
||||||
|
import { InstitucionUsuarioController } from './institucion-usuario.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -11,5 +12,6 @@ import { InstitucionUsuario } from './entity/institucion-usuario.entity';
|
|||||||
],
|
],
|
||||||
providers: [InstitucionUsuarioService],
|
providers: [InstitucionUsuarioService],
|
||||||
exports: [InstitucionUsuarioService],
|
exports: [InstitucionUsuarioService],
|
||||||
|
controllers: [InstitucionUsuarioController],
|
||||||
})
|
})
|
||||||
export class InstitucionUsuarioModule {}
|
export class InstitucionUsuarioModule {}
|
||||||
|
@ -30,10 +30,6 @@ export class UpdateInstitucionDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
dominio?: string;
|
dominio?: string;
|
||||||
|
|
||||||
@IsBoolean()
|
|
||||||
@IsOptional()
|
|
||||||
email_institucional?: boolean;
|
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
@ -19,9 +19,6 @@ export class InstitucionOutputDto {
|
|||||||
@Expose()
|
@Expose()
|
||||||
dominio;
|
dominio;
|
||||||
|
|
||||||
@Expose()
|
|
||||||
email_institucional;
|
|
||||||
|
|
||||||
@Expose()
|
@Expose()
|
||||||
institucion;
|
institucion;
|
||||||
|
|
||||||
|
@ -8,5 +8,5 @@ export class InstitucionesMinOutputDto {
|
|||||||
institucion;
|
institucion;
|
||||||
|
|
||||||
@Expose()
|
@Expose()
|
||||||
email_institucional;
|
dominio;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,6 @@ export class InstitucionController {
|
|||||||
_activo: true,
|
_activo: true,
|
||||||
_dias_multa_retraso: 7,
|
_dias_multa_retraso: 7,
|
||||||
_dominio: '@pcpuma.acatlan.unam.mx',
|
_dominio: '@pcpuma.acatlan.unam.mx',
|
||||||
_email_institucional: true,
|
|
||||||
_responsable: '',
|
_responsable: '',
|
||||||
_telefono: '',
|
_telefono: '',
|
||||||
_tiempo_entrega: 15,
|
_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 {
|
export class RegistrarUsuarioInputDto {
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@ -8,6 +8,5 @@ export class RegistrarUsuarioInputDto {
|
|||||||
telefono: string;
|
telefono: string;
|
||||||
|
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
@IsOptional()
|
correo: string;
|
||||||
correo?: string;
|
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ import {
|
|||||||
ApiTags,
|
ApiTags,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { Recaptcha } from '@nestlab/google-recaptcha';
|
import { Recaptcha } from '@nestlab/google-recaptcha';
|
||||||
import { Operador } from '../operador/entity/operador.entity';
|
|
||||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||||
import { UsuarioService } from './usuario.service';
|
import { UsuarioService } from './usuario.service';
|
||||||
|
import { Operador } from '../operador/entity/operador.entity';
|
||||||
import { DgaeInputDto } from './dto/input/dgae.dto';
|
import { DgaeInputDto } from './dto/input/dgae.dto';
|
||||||
import { DgpInputDto } from './dto/input/dgp.dto';
|
import { DgpInputDto } from './dto/input/dgp.dto';
|
||||||
import { RegistrarUsuarioInputDto } from './dto/input/registrar.dto';
|
import { RegistrarUsuarioInputDto } from './dto/input/registrar.dto';
|
||||||
@ -94,8 +94,8 @@ export class UsuarioController {
|
|||||||
registrar(@Body() body: RegistrarUsuarioInputDto) {
|
registrar(@Body() body: RegistrarUsuarioInputDto) {
|
||||||
return this.usuarioService.registrar(
|
return this.usuarioService.registrar(
|
||||||
body.id_institucion_usuario,
|
body.id_institucion_usuario,
|
||||||
body.telefono,
|
|
||||||
body.correo,
|
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();
|
const password = this.bcryptService.generarPassword();
|
||||||
let message =
|
let message: string;
|
||||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
|
||||||
|
|
||||||
return this.institucionUsuarioService
|
return this.institucionUsuarioService
|
||||||
.findById(id_institucion_usuario)
|
.findById(id_institucion_usuario)
|
||||||
@ -236,15 +235,17 @@ export class UsuarioService {
|
|||||||
throw new ConflictException(
|
throw new ConflictException(
|
||||||
'Ya fue registrado este número de cuenta.',
|
'Ya fue registrado este número de cuenta.',
|
||||||
);
|
);
|
||||||
if (!institucion.email_institucional) {
|
if (usuario.correo && correo != usuario.correo)
|
||||||
if (!correo)
|
throw new ConflictException(
|
||||||
throw new ConflictException(
|
'El correo ingresado no concuerda con el ingresado a escolares.',
|
||||||
'No se envió un correo electrónico para el regístro.',
|
);
|
||||||
);
|
if (!institucion.dominio)
|
||||||
else usuario.correo = correo;
|
|
||||||
message =
|
message =
|
||||||
'Se creó correctamente tu cuenta, ingresa a tu correo y consulta tu contraseña para acceder a este servicio.';
|
'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.telefono = telefono;
|
||||||
usuario.password = this.bcryptService.encriptar(password);
|
usuario.password = this.bcryptService.encriptar(password);
|
||||||
return this.repository.save(usuario);
|
return this.repository.save(usuario);
|
||||||
|
Loading…
Reference in New Issue
Block a user