tipo ussuario service final
This commit is contained in:
parent
b6bd3c8baa
commit
54a6214e6f
@ -27,7 +27,7 @@ export class ModuloMotivoService {
|
||||
motivo: string,
|
||||
numero_alumnos: number,
|
||||
fecha_creacion: string,
|
||||
) {
|
||||
): Promise<ModuloMotivo> {
|
||||
// Cramos y guardamos registro
|
||||
return this.repository.save(
|
||||
this.repository.create({
|
||||
|
@ -4,7 +4,7 @@ import {
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { FindOptionsWhere, MoreThan, Repository } from 'typeorm';
|
||||
import { TipoUsuario } from './entity/tipo-usuario.entity';
|
||||
|
||||
@Injectable()
|
||||
@ -13,14 +13,14 @@ export class TipoUsuarioService {
|
||||
@InjectRepository(TipoUsuario) private repository: Repository<TipoUsuario>,
|
||||
) {}
|
||||
|
||||
create(tipo_usuario: string) {
|
||||
// Buscamos un tipo de usuario con ese nombre
|
||||
create(tipo_usuario: string): Promise<{ message: string }> {
|
||||
// Buscamos un registro con ese nombre
|
||||
return this.repository
|
||||
.findOne({ where: { tipo_usuario } })
|
||||
.then((existeTipoUsuario) => {
|
||||
// Sacamos error si existe
|
||||
if (existeTipoUsuario)
|
||||
throw new ConflictException('Ya existe este tipo usuario');
|
||||
throw new ConflictException('Ya existe este tipo de usuario');
|
||||
// Creamos y guardamos un registro
|
||||
return this.repository.save(this.repository.create({ tipo_usuario }));
|
||||
})
|
||||
@ -29,22 +29,24 @@ export class TipoUsuarioService {
|
||||
}));
|
||||
}
|
||||
|
||||
crearTipoUsuario(id_tipo_usuario: number) {
|
||||
crearTipoUsuario(id_tipo_usuario: number): TipoUsuario {
|
||||
return this.repository.create({ id_tipo_usuario });
|
||||
}
|
||||
|
||||
findAll(informacion?: string) {
|
||||
const query = this.repository
|
||||
.createQueryBuilder('tu')
|
||||
.where('tu.id_tipo_usuario != 1 AND tu.id_tipo_usuario != 2')
|
||||
.orderBy('tu.tipo_usuario');
|
||||
findAll(informacion?: string): Promise<TipoUsuario[]> {
|
||||
const busqueda: FindOptionsWhere<TipoUsuario> = {
|
||||
id_tipo_usuario: MoreThan(2),
|
||||
};
|
||||
|
||||
if (informacion && informacion === 'operador')
|
||||
query.andWhere('tu.id_tipo_usuario > 4');
|
||||
return query.getMany();
|
||||
busqueda.id_tipo_usuario = MoreThan(4);
|
||||
return this.repository.find({
|
||||
where: busqueda,
|
||||
order: { tipo_usuario: 'ASC' },
|
||||
});
|
||||
}
|
||||
|
||||
findById(id_tipo_usuario: number) {
|
||||
findById(id_tipo_usuario: number): Promise<TipoUsuario> {
|
||||
return this.repository
|
||||
.findOne({ where: { id_tipo_usuario } })
|
||||
.then((tipoUsuario) => {
|
||||
@ -54,13 +56,7 @@ export class TipoUsuarioService {
|
||||
});
|
||||
}
|
||||
|
||||
findByTipoUsuario(tipo_usuario: string, validarNoExiste = true) {
|
||||
return this.repository
|
||||
.findOne({ where: { tipo_usuario } })
|
||||
.then((tipoUsuario) => {
|
||||
if (validarNoExiste && !tipoUsuario)
|
||||
throw new NotFoundException('No existe este tipo usuario');
|
||||
return tipoUsuario;
|
||||
});
|
||||
findByTipoUsuario(tipo_usuario: string): Promise<TipoUsuario> {
|
||||
return this.repository.findOne({ where: { tipo_usuario } });
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +359,6 @@ export class UploadFileService {
|
||||
|
||||
const tipoUsuario = await this.tipoUsuarioService.findByTipoUsuario(
|
||||
dataUsuario.tipo_usuario,
|
||||
false,
|
||||
);
|
||||
const usuario = await this.usuarioService.findByUsuario(
|
||||
dataUsuario.numero_cuenta,
|
||||
|
Loading…
Reference in New Issue
Block a user