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