Compare commits
93 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47b3933079 | |||
| 1c6f92658d | |||
| 08ed18ff4b | |||
| 655e45a876 | |||
| 3c9a28a960 | |||
| 29ffb0e327 | |||
| 3dc49766cc | |||
| 36cf0d217b | |||
| 970a6acc0b | |||
| cd5f2efc54 | |||
| b76c98b7fc | |||
| a3eea6bf2e | |||
| d2910bbdd7 | |||
| 379f6844fb | |||
| 435c61586d | |||
| 19bde0d891 | |||
| 0e9e179bd8 | |||
| 4a70ad3aa7 | |||
| 45fdc9fbde | |||
| ae1cec3bee | |||
| 483f8cd203 | |||
| 495d611486 | |||
| a7ee97f2f1 | |||
| b3673fbae4 | |||
| ba5e95a50a | |||
| 6e4112d9fa | |||
| c321917ed3 | |||
| 62f1776a5e | |||
| 9c6f9ef3fd | |||
| 7afd16566a | |||
| 7b7892fca7 | |||
| 9b2e675afb | |||
| b737064d93 | |||
| 99c08b11b5 | |||
| 806a5ac130 | |||
| 5d8a379a7e | |||
| 9d513c3439 | |||
| 3472aa911d | |||
| f57d8d114d | |||
| df87cb3c58 | |||
| 519dba72fe | |||
| 882160432d | |||
| 6630dc2f4e | |||
| 75167caee1 | |||
| 2be7270c05 | |||
| 118d5f1abf | |||
| 4905111922 | |||
| 6b29c582c7 | |||
| 85f62efd7e | |||
| fa1aa3c11b | |||
| 8ebc2deba0 | |||
| 1467fe769a | |||
| d99155186f | |||
| 5f68509986 | |||
| 0e56bdcf61 | |||
| ab452aa4c8 | |||
| df293f6f7c | |||
| 764ee7e5d3 | |||
| 01867a2dcd | |||
| 4c758062dd | |||
| 679b1d5f20 | |||
| 61b9dbc3bf | |||
| 090c5af0b3 | |||
| 0cbc8b8f68 | |||
| c38e7be6a0 | |||
| 37c721ef87 | |||
| 34736b965e | |||
| 339b4dd548 | |||
| 978db238d4 | |||
| ad4114144c | |||
| a59922213d | |||
| ef710d8461 | |||
| 7e7ee75511 | |||
| 5861064c8d | |||
| 91f151d14b | |||
| dec89fd9e7 | |||
| 3ac0e9e78c | |||
| b853d02be4 | |||
| bf2d6d6907 | |||
| fb44748315 | |||
| d092980f4a | |||
| 74df68c5e0 | |||
| d421a23443 | |||
| dcd217c26f | |||
| d514cf8714 | |||
| 4a9c6e5eb7 | |||
| 14ac2bd0d1 | |||
| 3317b7bdbe | |||
| e6cafdfb78 | |||
| 7d48df9830 | |||
| 332575a8e1 | |||
| 578c42b959 | |||
| a3bcb0e3aa |
+22
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
PORT=""
|
||||||
|
JWT=
|
||||||
|
|
||||||
|
DB_HOST=
|
||||||
|
DB_PORT=
|
||||||
|
DB_USER=
|
||||||
|
DB_PASS=
|
||||||
|
DB_NAME=
|
||||||
|
|
||||||
|
#Aqui va la direccion del forntend
|
||||||
|
CORS_ORIGINS=""
|
||||||
|
|
||||||
|
SINCRONIZAR="true"
|
||||||
|
AUTOLOAD="false"
|
||||||
|
|
||||||
|
#Aqui va la direccion de la API de Directorio Funcionarios
|
||||||
|
API_FUNCIONARIOS=""
|
||||||
|
|
||||||
|
MODO="pruebas"
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Generated
+2673
-2424
File diff suppressed because it is too large
Load Diff
+23
-19
@@ -20,16 +20,19 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.1.6",
|
"@nestjs/common": "^11.1.28",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/jwt": "^11.0.1",
|
"@nestjs/jwt": "^11.0.2",
|
||||||
"@nestjs/mapped-types": "*",
|
"@nestjs/mapped-types": "^2.1.1",
|
||||||
"@nestjs/passport": "^11.0.5",
|
"@nestjs/passport": "^11.0.5",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"@nestjs/typeorm": "^11.0.0",
|
"@nestjs/schedule": "^6.1.3",
|
||||||
"argon2": "^0.44.0",
|
"@nestjs/typeorm": "^11.0.3",
|
||||||
|
"axios": "^1.13.1",
|
||||||
|
"bcryptjs": "^3.0.2",
|
||||||
"class-transformer": "0.5.1",
|
"class-transformer": "0.5.1",
|
||||||
"class-validator": "0.14.2",
|
"class-validator": "0.14.2",
|
||||||
|
"exceljs": "^4.4.0",
|
||||||
"mysql2": "^3.15.2",
|
"mysql2": "^3.15.2",
|
||||||
"passport": "^0.7.0",
|
"passport": "^0.7.0",
|
||||||
"passport-jwt": "^4.0.1",
|
"passport-jwt": "^4.0.1",
|
||||||
@@ -39,31 +42,32 @@
|
|||||||
"typeorm": "^0.3.27"
|
"typeorm": "^0.3.27"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.3.6",
|
||||||
"@eslint/js": "^9.18.0",
|
"@eslint/js": "^9.18.0",
|
||||||
"@nestjs/cli": "^11.0.0",
|
"@nestjs/cli": "^11.0.0",
|
||||||
"@nestjs/config": "^4.0.2",
|
"@nestjs/config": "^4.0.2",
|
||||||
"@nestjs/schematics": "^11.0.0",
|
"@nestjs/schematics": "^11.0.0",
|
||||||
"@nestjs/testing": "^11.0.1",
|
"@nestjs/testing": "^11.1.28",
|
||||||
"@types/express": "^5.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
|
"@types/express": "^5.0.6",
|
||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^22.10.7",
|
"@types/node": "^22.20.1",
|
||||||
"@types/passport-jwt": "^4.0.1",
|
"@types/passport-jwt": "^4.0.1",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^10.8.0",
|
||||||
"eslint-config-prettier": "^10.0.1",
|
"eslint-config-prettier": "^10.0.1",
|
||||||
"eslint-plugin-prettier": "^5.2.2",
|
"eslint-plugin-prettier": "^5.5.6",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.5.0",
|
||||||
"jest": "^30.0.0",
|
"jest": "^30.4.2",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.9.6",
|
||||||
"source-map-support": "^0.5.21",
|
"source-map-support": "^0.5.21",
|
||||||
"supertest": "^7.0.0",
|
"supertest": "^7.2.2",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.4.12",
|
||||||
"ts-loader": "^9.5.2",
|
"ts-loader": "^9.6.2",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsconfig-paths": "^4.2.0",
|
"tsconfig-paths": "^4.2.0",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.7.3",
|
||||||
"typescript-eslint": "^8.20.0"
|
"typescript-eslint": "^8.65.0"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"moduleFileExtensions": [
|
"moduleFileExtensions": [
|
||||||
@@ -82,4 +86,4 @@
|
|||||||
"coverageDirectory": "../coverage",
|
"coverageDirectory": "../coverage",
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-3
@@ -13,6 +13,7 @@ import { AppController } from './app.controller';
|
|||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
TypeOrmModule.forRoot({
|
TypeOrmModule.forRoot({
|
||||||
type: 'mariadb',
|
type: 'mariadb',
|
||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
@@ -23,10 +24,13 @@ import { AppController } from './app.controller';
|
|||||||
autoLoadEntities: process.env.AUTOLOAD === 'true',
|
autoLoadEntities: process.env.AUTOLOAD === 'true',
|
||||||
synchronize: process.env.SINCRONIZAR === 'true',
|
synchronize: process.env.SINCRONIZAR === 'true',
|
||||||
logger: 'advanced-console',
|
logger: 'advanced-console',
|
||||||
logging: 'all',
|
logging: ['error', 'warn','log'],
|
||||||
|
|
||||||
|
extra: {
|
||||||
|
connectionLimit: 10,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
UsuariosModule,
|
UsuariosModule,
|
||||||
|
|
||||||
MovimientoModule,
|
MovimientoModule,
|
||||||
EquipoModule,
|
EquipoModule,
|
||||||
AuthModule,
|
AuthModule,
|
||||||
@@ -34,4 +38,4 @@ import { AppController } from './app.controller';
|
|||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule { }
|
||||||
|
|||||||
+43
-15
@@ -1,27 +1,55 @@
|
|||||||
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
NotFoundException,
|
||||||
|
Patch,
|
||||||
|
Post,
|
||||||
|
Req,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
||||||
import { LoginDto } from './dto/login.dto';
|
import { LoginDto } from './dto/login.dto';
|
||||||
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
|
import { UpdateUsuarioDto } from 'src/usuarios/dto/update-usuario.dto';
|
||||||
|
import { not } from 'rxjs/internal/util/not';
|
||||||
|
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor( private readonly authService:AuthService){}
|
constructor(private readonly authService: AuthService) {}
|
||||||
|
|
||||||
@Post("registro")
|
@UseGuards(AuthGuard('jwt'))
|
||||||
registro(@Body() registroDto:CreateUsuarioDto ){
|
@Post('registro')
|
||||||
return this.authService.registro(registroDto);
|
registro(@Body() registroDto: CreateUsuarioDto) {
|
||||||
|
return this.authService.registro(registroDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('registro/Masivo')
|
||||||
|
registroMasivo(@Body() registroDto: CreateUsuarioDto[]) {
|
||||||
|
return this.authService.registroMasivo(registroDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('buscar')
|
||||||
|
search() {
|
||||||
|
return this.authService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Patch('update')
|
||||||
|
update(@Body() registroDto: UpdateUsuarioDto, @Req() req: any) {
|
||||||
|
const id_usuario = req.user.id;
|
||||||
|
|
||||||
|
if (!id_usuario) {
|
||||||
|
throw new NotFoundException('token sin id_usuario');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.authService.update(registroDto, id_usuario);
|
||||||
@Post("login")
|
}
|
||||||
login(@Body() loginDto:LoginDto){
|
|
||||||
return this.authService.login(loginDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Post('login')
|
||||||
|
login(@Body() loginDto: LoginDto) {
|
||||||
|
return this.authService.login(loginDto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import {
|
|||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UsuariosService } from 'src/usuarios/usuarios.service';
|
import { UsuariosService } from 'src/usuarios/usuarios.service';
|
||||||
import * as argon2 from 'argon2';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import { LoginDto } from './dto/login.dto';
|
import { LoginDto } from './dto/login.dto';
|
||||||
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
|
import { UpdateUsuarioDto } from 'src/usuarios/dto/update-usuario.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
@@ -17,6 +18,20 @@ export class AuthService {
|
|||||||
private readonly jwtService: JwtService,
|
private readonly jwtService: JwtService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async update(registroDto: UpdateUsuarioDto, id_User: number) {
|
||||||
|
const update_data = await this.usuarioService.actualizarUsuario(id_User, {
|
||||||
|
nombre: registroDto.nombre,
|
||||||
|
contraseñaN: registroDto.contraseñaN,
|
||||||
|
id_tipo_usuario: registroDto.tipoUsuario,
|
||||||
|
contraseñaV: registroDto.contraseñaV,
|
||||||
|
});
|
||||||
|
return update_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAll() {
|
||||||
|
return await this.usuarioService.usuarios();
|
||||||
|
}
|
||||||
|
|
||||||
async registro({ nombre, contraseña, tipoUsuario }: CreateUsuarioDto) {
|
async registro({ nombre, contraseña, tipoUsuario }: CreateUsuarioDto) {
|
||||||
const usuario = await this.usuarioService.findOneByName(nombre);
|
const usuario = await this.usuarioService.findOneByName(nombre);
|
||||||
if (usuario) {
|
if (usuario) {
|
||||||
@@ -24,7 +39,8 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const hashedContraseña = await argon2.hash(contraseña);
|
const salt = await bcrypt.genSalt(10);
|
||||||
|
const hashedContraseña = await bcrypt.hash(contraseña, salt);
|
||||||
|
|
||||||
await this.usuarioService.create({
|
await this.usuarioService.create({
|
||||||
nombre,
|
nombre,
|
||||||
@@ -40,29 +56,42 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async registroMasivo(usuarios: CreateUsuarioDto[]) {
|
||||||
|
let resultados: string[] = [];
|
||||||
|
|
||||||
|
for (const usuario of usuarios) {
|
||||||
|
const creado = await this.registro(usuario);
|
||||||
|
resultados.push(creado.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultados;
|
||||||
|
}
|
||||||
|
|
||||||
async login({ nombre, contraseña }: LoginDto) {
|
async login({ nombre, contraseña }: LoginDto) {
|
||||||
const usuario = await this.usuarioService.findOneByName(nombre);
|
const usuario = await this.usuarioService.findOneByName(nombre);
|
||||||
if (!usuario) {
|
if (!usuario) {
|
||||||
throw new UnauthorizedException('Usuario no encontrado');
|
throw new UnauthorizedException('Usuario no encontrado');
|
||||||
}
|
}
|
||||||
|
|
||||||
const contraseñaValida = await argon2.verify(
|
const contraseñaValida = await bcrypt.compare(
|
||||||
usuario.contraseña,
|
|
||||||
contraseña,
|
contraseña,
|
||||||
|
usuario.contraseña,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!contraseñaValida) {
|
if (!contraseñaValida) {
|
||||||
throw new UnauthorizedException('Contraseña invalida');
|
throw new UnauthorizedException('Contraseña inválida');
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataUser = {
|
const dataUser = {
|
||||||
id: usuario.id_usuario,
|
id: usuario.id_usuario,
|
||||||
nombre: usuario.nombre,
|
nombre: usuario.nombre,
|
||||||
tipoUsuario: usuario.tipoUsuario.id_tipo_usuario,
|
tipoUsuario: usuario.tipoUsuario.id_tipo_usuario,
|
||||||
};
|
};
|
||||||
|
|
||||||
const token = await this.jwtService.sign(dataUser);
|
const token = this.jwtService.sign(dataUser);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
token: token,
|
token,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,65 @@
|
|||||||
|
import {
|
||||||
|
IsString,
|
||||||
|
IsOptional,
|
||||||
|
IsDateString,
|
||||||
|
IsInt,
|
||||||
|
IsNotEmpty,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class CreateEquipoDto {
|
export class CreateEquipoDto {
|
||||||
|
@IsString()
|
||||||
|
inventario: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
serie?: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
lugar: string;
|
||||||
|
|
||||||
|
@IsDateString()
|
||||||
|
fechaFactura: Date;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
antiguedad: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
modelo: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_estado: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_adscripcion: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_tipo_equipo: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_sistema_operativo: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_procesador?: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_uso: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_marca: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
id_periferico: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_laboratorio?: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_proyecto?: number;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsOptional()
|
||||||
|
isImpresora?: Boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import { IsArray, IsOptional, IsString } from "class-validator";
|
||||||
|
|
||||||
|
export class FiltrosGraficaDto {
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
adscripciones?: number[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
procesadores?: number[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
sistemas?: number[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
usos?: number[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
antiguedad?: string[]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FiltrosTablaDto {
|
||||||
|
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
adscripciones?: string[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
procesadores?: string[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
sistemas?: string[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
usos?: string[]
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
antiguedad?: string[]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class FiltrosPolarDto {
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
adscripciones?: string[]
|
||||||
|
}
|
||||||
@@ -1,38 +1,56 @@
|
|||||||
import { PartialType } from '@nestjs/mapped-types';
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
import { CreateEquipoDto } from './create-equipo.dto';
|
import { CreateEquipoDto } from './create-equipo.dto';
|
||||||
import { IsInt, IsOptional, IsString } from 'class-validator';
|
import { IsInt, IsOptional, IsString } from 'class-validator';
|
||||||
|
|
||||||
export class UpdateEquipoDto extends PartialType(CreateEquipoDto) {
|
export class UpdateEquipoDto extends PartialType(CreateEquipoDto) {
|
||||||
@IsInt()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
id_estado?:number
|
serie?: string;
|
||||||
|
|
||||||
@IsInt()
|
|
||||||
@IsOptional()
|
|
||||||
id_adscripcion?: number;
|
|
||||||
|
|
||||||
@IsString()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
lugar?: string;
|
id_estado?: number;
|
||||||
|
|
||||||
@IsInt()
|
|
||||||
@IsOptional()
|
|
||||||
id_sistema_operativo?: number;
|
|
||||||
|
|
||||||
@IsInt()
|
|
||||||
@IsOptional()
|
|
||||||
id_procesador?: number;
|
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
id_tipo_uso?: number;
|
id_adscripcion?: number;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
modelo?: string;
|
lugar?: string;
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
id_marca?: number;
|
id_sistema_operativo?: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_procesador?: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_tipo_uso?: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
modelo?: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_marca?: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
observaciones: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_periferico?: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_proyecto?: number;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
id_laboratorio?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,54 @@
|
|||||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
import {
|
||||||
|
Column,
|
||||||
|
Entity,
|
||||||
|
OneToMany,
|
||||||
|
PrimaryColumn,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
} from 'typeorm';
|
||||||
import { Equipo } from './equipo.entity';
|
import { Equipo } from './equipo.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Uso {
|
export class Uso {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn({ name: 'id_uso' })
|
||||||
id_tipo_uso: number;
|
id_uso: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 100 })
|
||||||
tipo_uso: string;
|
tipo_uso: string;
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.tipoUso)
|
@OneToMany(() => Equipo, (equipo) => equipo.tipoUso)
|
||||||
equipo: Equipo[];
|
equipo: Equipo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Laboratorio {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id_laboratorio: number;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 20 })
|
||||||
|
laboratorio: string;
|
||||||
|
|
||||||
|
@OneToMany(() => Equipo, (equipo) => equipo.laboratorio)
|
||||||
|
equipo: Equipo[];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Proyecto {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id_proyecto: number;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 10 })
|
||||||
|
proyecto: string;
|
||||||
|
|
||||||
|
@OneToMany(() => Equipo, (equipo) => equipo.proyecto)
|
||||||
|
equipo: Equipo[];
|
||||||
|
}
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Marca {
|
export class Marca {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_marca: number;
|
id_marca: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 100 })
|
||||||
tipo_marca: string;
|
marca: string;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.marca)
|
@OneToMany(() => Equipo, (equipo) => equipo.marca)
|
||||||
equipo: Equipo[];
|
equipo: Equipo[];
|
||||||
@@ -29,7 +59,7 @@ export class Estado {
|
|||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_estado: number;
|
id_estado: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 100 })
|
||||||
estado: string;
|
estado: string;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.estado)
|
@OneToMany(() => Equipo, (equipo) => equipo.estado)
|
||||||
@@ -38,10 +68,10 @@ export class Estado {
|
|||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Adscripcion {
|
export class Adscripcion {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryColumn()
|
||||||
id_adscripcion: number;
|
id_adscripcion: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 300 })
|
||||||
adscripcion: string;
|
adscripcion: string;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.adscripcion)
|
@OneToMany(() => Equipo, (equipo) => equipo.adscripcion)
|
||||||
@@ -53,10 +83,10 @@ export class TipoEquipo {
|
|||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_tipo_de_equipo: number;
|
id_tipo_de_equipo: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 200 })
|
||||||
tipo_equipo: string;
|
tipo_equipo: string;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.tipoEquipo)
|
@OneToMany(() => Equipo, (eqp) => eqp.tipoEquipo)
|
||||||
equipo: Equipo[];
|
equipo: Equipo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +95,7 @@ export class SistemaOperativo {
|
|||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_sistema_operativo: number;
|
id_sistema_operativo: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 200 })
|
||||||
sistema_operativo: string;
|
sistema_operativo: string;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.sistemaOperativo)
|
@OneToMany(() => Equipo, (equipo) => equipo.sistemaOperativo)
|
||||||
@@ -77,9 +107,21 @@ export class Procesador {
|
|||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_procesador: number;
|
id_procesador: number;
|
||||||
|
|
||||||
@Column()
|
@Column({ type: 'varchar', length: 200 })
|
||||||
procesador: string;
|
procesador: string;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.procesador)
|
@OneToMany(() => Equipo, (equipo) => equipo.procesador)
|
||||||
equipo: Equipo[];
|
equipo: Equipo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Periferico {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id_periferico: number;
|
||||||
|
|
||||||
|
@Column({ type: 'varchar', length: 100 })
|
||||||
|
periferico: string;
|
||||||
|
|
||||||
|
@OneToMany(() => Equipo, (equipo) => equipo.periferico)
|
||||||
|
equipo: Equipo[];
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
Entity,
|
Entity,
|
||||||
|
JoinColumn,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
@@ -8,8 +9,11 @@ import {
|
|||||||
import {
|
import {
|
||||||
Adscripcion,
|
Adscripcion,
|
||||||
Estado,
|
Estado,
|
||||||
|
Laboratorio,
|
||||||
Marca,
|
Marca,
|
||||||
|
Periferico,
|
||||||
Procesador,
|
Procesador,
|
||||||
|
Proyecto,
|
||||||
SistemaOperativo,
|
SistemaOperativo,
|
||||||
TipoEquipo,
|
TipoEquipo,
|
||||||
Uso,
|
Uso,
|
||||||
@@ -22,52 +26,75 @@ export class Equipo {
|
|||||||
id_equipo: number;
|
id_equipo: number;
|
||||||
//checar bien aqui si estoy bien
|
//checar bien aqui si estoy bien
|
||||||
|
|
||||||
@Column({ length: 200, nullable: true })
|
@Column({ type: 'varchar', length: 10, nullable: true })
|
||||||
inventario: string;
|
inventario: string;
|
||||||
|
|
||||||
@Column({ length: 200, nullable: true })
|
@Column({ type: 'varchar', length: 30, nullable: true })
|
||||||
serie: string;
|
serie: string;
|
||||||
|
|
||||||
@Column({ length: 200, nullable: true })
|
@Column({ type: 'varchar', length: 200, nullable: true })
|
||||||
lugar: string;
|
lugar: string;
|
||||||
|
|
||||||
@Column({ name: 'fecha_factura' })
|
@Column({ name: 'fecha_factura' })
|
||||||
fechaFactura: Date;
|
fechaFactura: Date;
|
||||||
|
|
||||||
@Column({ length: 200, nullable: true })
|
@Column({ type: 'varchar', length: 30, nullable: true })
|
||||||
antiguedad: string;
|
antiguedad: string;
|
||||||
|
|
||||||
@Column({ length: 200, nullable: true })
|
@Column({ type: 'varchar', length: 40, nullable: true })
|
||||||
modelo: string;
|
modelo: string;
|
||||||
|
|
||||||
//Relaciones
|
//Relaciones
|
||||||
@OneToMany(() => Movimiento, (mov) => mov.equipo)
|
@OneToMany(() => Movimiento, (mov) => mov.equipo)
|
||||||
mov: Movimiento[];
|
mov: Movimiento[];
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_estado' })
|
||||||
@ManyToOne(() => Estado, (estado) => estado.equipo)
|
@ManyToOne(() => Estado, (estado) => estado.equipo)
|
||||||
estado: Estado;
|
estado: Estado;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_adscripcion' })
|
||||||
@ManyToOne(() => Adscripcion, (adscripcion) => adscripcion.equipo)
|
@ManyToOne(() => Adscripcion, (adscripcion) => adscripcion.equipo)
|
||||||
adscripcion: Adscripcion;
|
adscripcion: Adscripcion;
|
||||||
|
|
||||||
@ManyToOne(() => TipoEquipo, (tipoEquipo) => tipoEquipo.equipo)
|
@JoinColumn({ name: 'id_sistema_operativo' })
|
||||||
tipoEquipo: TipoEquipo;
|
|
||||||
|
|
||||||
@ManyToOne(
|
@ManyToOne(
|
||||||
() => SistemaOperativo,
|
() => SistemaOperativo,
|
||||||
(sistemaOperativo) => sistemaOperativo.equipo,
|
(sistemaOperativo) => sistemaOperativo.equipo,
|
||||||
)
|
)
|
||||||
sistemaOperativo: SistemaOperativo;
|
sistemaOperativo: SistemaOperativo;
|
||||||
|
|
||||||
@ManyToOne(() => Procesador, (procesador) => procesador.equipo)
|
@JoinColumn({ name: 'id_tipo_equipo' })
|
||||||
|
@ManyToOne(() => TipoEquipo, (tipoEquipo) => tipoEquipo.equipo)
|
||||||
|
tipoEquipo: TipoEquipo;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_procesador' })
|
||||||
|
@ManyToOne(() => Procesador, (procesador) => procesador.equipo, {
|
||||||
|
nullable: true,
|
||||||
|
onDelete: 'SET NULL',
|
||||||
|
})
|
||||||
procesador: Procesador;
|
procesador: Procesador;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_uso' })
|
||||||
@ManyToOne(() => Uso, (tipoUso) => tipoUso.equipo)
|
@ManyToOne(() => Uso, (tipoUso) => tipoUso.equipo)
|
||||||
tipoUso: Uso;
|
tipoUso: Uso;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_marca' })
|
||||||
@ManyToOne(() => Marca, (marca) => marca.equipo)
|
@ManyToOne(() => Marca, (marca) => marca.equipo)
|
||||||
marca: Marca;
|
marca: Marca;
|
||||||
|
|
||||||
@OneToMany(() => Equipo, (equipo) => equipo.marca)
|
@JoinColumn({ name: 'id_periferico' })
|
||||||
equipo: Equipo[];
|
@ManyToOne(() => Periferico, (Periferico) => Periferico.equipo)
|
||||||
|
periferico: Periferico;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_laboratorio' })
|
||||||
|
@ManyToOne(() => Laboratorio, (laboratorio) => laboratorio.equipo, {
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
laboratorio?: Laboratorio | null;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_proyecto' })
|
||||||
|
@ManyToOne(() => Proyecto, (proyecto) => proyecto.equipo, {
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
proyecto?: Proyecto | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,24 @@ import {
|
|||||||
UseGuards,
|
UseGuards,
|
||||||
Get,
|
Get,
|
||||||
Query,
|
Query,
|
||||||
|
Delete,
|
||||||
|
NotFoundException,
|
||||||
|
Post,
|
||||||
|
Res,
|
||||||
|
Request,
|
||||||
|
BadRequestException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { EquipoService } from './equipo.service';
|
import { EquipoService } from './equipo.service';
|
||||||
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
import { UpdateEquipoDto } from './dto/update-equipo.dto';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
|
import { CreateEquipoDto } from './dto/create-equipo.dto';
|
||||||
|
import type { Response } from 'express';
|
||||||
|
import { FiltrosGraficaDto, FiltrosPolarDto, FiltrosTablaDto } from './dto/grafica.dto';
|
||||||
|
|
||||||
@Controller('equipos')
|
@Controller('equipos')
|
||||||
export class EquipoController {
|
export class EquipoController {
|
||||||
constructor(private readonly equipoService: EquipoService) {}
|
constructor(private readonly equipoService: EquipoService) { }
|
||||||
|
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@Get('buscar')
|
@Get('buscar')
|
||||||
async buscarEquipos(
|
async buscarEquipos(
|
||||||
@@ -26,18 +36,110 @@ export class EquipoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@Get('buscar/:inv')
|
@Post('grafica/:tipo')
|
||||||
serch(@Param('inv') inv: string) {
|
async grafica(
|
||||||
return this.equipoService.findEquipo(inv);
|
@Param("tipo") tipo: 'antiguedad' | 'uso' | 'so' | 'procesador',
|
||||||
|
@Body() filtros: FiltrosGraficaDto
|
||||||
|
) {
|
||||||
|
return this.equipoService.grafica(tipo, filtros);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('graficaPolar/:tipo')
|
||||||
|
async graficaPolar(
|
||||||
|
@Param("tipo") tipo: 'ALUMNO' | 'PROFESOR' | 'ADMINISTRATIVO',
|
||||||
|
@Body() filtros: FiltrosPolarDto
|
||||||
|
) {
|
||||||
|
return this.equipoService.graficaPolar(tipo, filtros);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('graficaPerifericos/:tipo')
|
||||||
|
async graficaPerifericos(
|
||||||
|
@Param("tipo") tipo: 'antiguedad' | 'uso' | 'so' | 'procesador',
|
||||||
|
@Body() filtros: FiltrosGraficaDto
|
||||||
|
) {
|
||||||
|
return this.equipoService.graficaPerifericos(tipo, filtros);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('tabla')
|
||||||
|
async tabla(
|
||||||
|
@Body() filtros: FiltrosTablaDto
|
||||||
|
) {
|
||||||
|
return this.equipoService.tabla(filtros);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('tabla/count')
|
||||||
|
async tablacount(
|
||||||
|
@Body() filtros: FiltrosTablaDto
|
||||||
|
) {
|
||||||
|
return this.equipoService.tablaCount(filtros);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('excel/tabla')
|
||||||
|
async exceltabla(
|
||||||
|
@Res() res: Response,
|
||||||
|
@Body() filtros: FiltrosTablaDto
|
||||||
|
) {
|
||||||
|
const buffer = await this.equipoService.tablaExcel(filtros);
|
||||||
|
|
||||||
|
res.set({
|
||||||
|
'Content-Type':
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
'Content-Disposition': 'attachment; filename=tabla.xlsx',
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('excel/tabla/count')
|
||||||
|
async exceltablacount(
|
||||||
|
@Res() res: Response,
|
||||||
|
@Body() filtros: FiltrosGraficaDto
|
||||||
|
) {
|
||||||
|
const buffer = await this.equipoService.tablaCountExcel(filtros);
|
||||||
|
|
||||||
|
res.set({
|
||||||
|
'Content-Type':
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
'Content-Disposition': 'attachment; filename=tabla.xlsx',
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('buscar/:inv')
|
||||||
|
async serch(@Param('inv') inv: string) {
|
||||||
|
return await this.equipoService.findEquipo(inv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('crear')
|
||||||
|
async create(@Body() Equipo: CreateEquipoDto, @Request() req) {
|
||||||
|
return await this.equipoService.create(Equipo, req.user.id);
|
||||||
|
}
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@Patch('update/:id')
|
@Patch('update/:id')
|
||||||
update(
|
update(
|
||||||
|
@Request() req,
|
||||||
@Param('id', ParseIntPipe) id: number,
|
@Param('id', ParseIntPipe) id: number,
|
||||||
@Body() equipoNuevo: UpdateEquipoDto,
|
@Body() equipoNuevo: UpdateEquipoDto,
|
||||||
) {
|
) {
|
||||||
return this.equipoService.updateEquipo(equipoNuevo, id);
|
return this.equipoService.updateEquipo(equipoNuevo, id, req.user.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Delete(':id')
|
||||||
|
async deleteEquipo(@Param('id', ParseIntPipe) id_equipo: string) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.deleteEquipo(id_equipo);
|
||||||
|
} catch (error) {
|
||||||
|
throw new NotFoundException(error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@@ -51,11 +153,13 @@ export class EquipoController {
|
|||||||
findMarcas() {
|
findMarcas() {
|
||||||
return this.equipoService.findAllMarcas();
|
return this.equipoService.findAllMarcas();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@Get('estados')
|
@Get('estados')
|
||||||
findEstados() {
|
findEstados() {
|
||||||
return this.equipoService.findAllEstados();
|
return this.equipoService.findAllEstados();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@Get('adscripciones')
|
@Get('adscripciones')
|
||||||
findAdscripciones() {
|
findAdscripciones() {
|
||||||
@@ -66,6 +170,7 @@ export class EquipoController {
|
|||||||
findTiposEquipo() {
|
findTiposEquipo() {
|
||||||
return this.equipoService.findAllTiposEquipo();
|
return this.equipoService.findAllTiposEquipo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@Get('sistemas-operativos')
|
@Get('sistemas-operativos')
|
||||||
findSistemasOperativos() {
|
findSistemasOperativos() {
|
||||||
@@ -76,4 +181,303 @@ export class EquipoController {
|
|||||||
findProcesadores() {
|
findProcesadores() {
|
||||||
return this.equipoService.findAllProcesadores();
|
return this.equipoService.findAllProcesadores();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('laboratorios')
|
||||||
|
findLaboratorios() {
|
||||||
|
return this.equipoService.findAllLaboratorios();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('proyectos')
|
||||||
|
findProyectos() {
|
||||||
|
return this.equipoService.findAllProyectos();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('perifericos')
|
||||||
|
findPerifericos() {
|
||||||
|
return this.equipoService.findAllPerifericos();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('procesador-tipo-equipos')
|
||||||
|
findProcesadorTipoEquipos() {
|
||||||
|
return this.equipoService.findAllProcesadorTipoEquipos();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Post('daily')
|
||||||
|
// async daily() {
|
||||||
|
// return await this.equipoService.llenadoDeAntiguedad();
|
||||||
|
// }
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('reporteXLSX')
|
||||||
|
async generarReporte(@Res({ passthrough: true }) res: Response) {
|
||||||
|
try {
|
||||||
|
await this.equipoService.createEcxel(res);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error al generar el Excel:', error);
|
||||||
|
res.status(500).send('Error al generar el archivo Excel');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('reporte')
|
||||||
|
async reporte(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.generar_reporte(estado);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException('Error al generar el reporte:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/tipoEquipos_tipoUso')
|
||||||
|
async reportetipoEquipos_tipoUso(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.contar_tipoEquipos_tipoUso(estado);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte tipoEquipos_tipoUso:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/tipoEquipos_sistemasOperativos')
|
||||||
|
async reportetipoEquipos_sistemasOperativos(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await Promise.all([
|
||||||
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(
|
||||||
|
equpos_pc,
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(
|
||||||
|
[estritorio_mac],
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(
|
||||||
|
portatiles,
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(
|
||||||
|
[portatiles_mac],
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
this.equipoService.contar_tipoEquipos_sistemasOperativos(
|
||||||
|
[servidor],
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte tipoEquipos_sistemasOperativos:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/tipoEquipos_procesador')
|
||||||
|
async reportetipoEquipos_procesador(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await Promise.all([
|
||||||
|
this.equipoService.contar_tipoEquipos_procesador(equpos_pc, estado),
|
||||||
|
this.equipoService.contar_tipoEquipos_procesador(
|
||||||
|
[estritorio_mac],
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
this.equipoService.contar_tipoEquipos_procesador(portatiles, estado),
|
||||||
|
this.equipoService.contar_tipoEquipos_procesador(
|
||||||
|
[portatiles_mac],
|
||||||
|
estado,
|
||||||
|
),
|
||||||
|
this.equipoService.contar_tipoEquipos_procesador([servidor], estado),
|
||||||
|
]);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte tipoEquipos_procesador:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/tipoEquipos_antiguedad')
|
||||||
|
async reportetipoEquipos_antiguedad(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.contar_tipoEquipos_antiguedad(estado);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte contar_tipoEquipos_antiguedad:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/garantia')
|
||||||
|
async reportegarantia(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await Promise.all([
|
||||||
|
this.equipoService.garantia(escritorio, estado),
|
||||||
|
this.equipoService.garantia(portatil, estado),
|
||||||
|
this.equipoService.garantia([servidor], estado),
|
||||||
|
]);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte garantia:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/equipos_impesion_group/impresoras')
|
||||||
|
async reporteequipos_impesion_group(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.equipos_impesion_group(
|
||||||
|
impresoras,
|
||||||
|
estado,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte impesion_group impresoras:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/equipos_impesion_group/dijitales')
|
||||||
|
async reporteequipos_impesion_group_dijitales(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.equipos_impesion_group(dijitales, estado);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte impesion_group dijitales:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/contar_periferico_tipoUso/impresoras')
|
||||||
|
async reporte_contar_periferico_tipoUso_impresoras(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.contar_periferico_tipoUso(
|
||||||
|
impresoras,
|
||||||
|
estado,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte periferico_tipoUso impresoras:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/contar_periferico_tipoUso/dijtales')
|
||||||
|
async reporte_contar_periferico_tipoUso_dijtales(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.contar_periferico_tipoUso(
|
||||||
|
dijitales,
|
||||||
|
estado,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte periferico_tipoUso dijtales:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/contar_perifericos_antiguedad')
|
||||||
|
async reporte_contar_perifericos_antiguedad(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.contar_perifericos_antiguedad(
|
||||||
|
impresoras,
|
||||||
|
dijitales,
|
||||||
|
estado,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte perifericos_antiguedad:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/contar_laboratorio')
|
||||||
|
async reporte_contar_laboratorio(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.laboratorio_equipos(estado);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte perifericos_antiguedad:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Post('reporte/contar_proyecto')
|
||||||
|
async reporte_contar_proyecto(@Body() estado: string[]) {
|
||||||
|
try {
|
||||||
|
return await this.equipoService.proyecto_equipos(estado);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
'Error al generar el reporte perifericos_antiguedad:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('ranking/:year')
|
||||||
|
async ranking(@Param('year') year: string) {
|
||||||
|
return this.equipoService.ranking(Number(year));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let escritorio = ['ESCRITORIO PC', 'ESCRITORIO MAC OS ', 'ESCRITORIO LINUX'];
|
||||||
|
let portatil = [
|
||||||
|
'PORTÁTILES WINDOWS',
|
||||||
|
'PORTÁTILES CHROMEBOOK',
|
||||||
|
'PORTÁTILES MAC OS',
|
||||||
|
];
|
||||||
|
|
||||||
|
let equipos_mac = ['ESCRITORIO MAC OS ', 'PORTÁTILES MAC OS'];
|
||||||
|
|
||||||
|
let equpos_pc = ['ESCRITORIO PC', 'ESCRITORIO LINUX'];
|
||||||
|
let estritorio_mac = 'ESCRITORIO MAC OS ';
|
||||||
|
let portatiles_mac = 'PORTÁTILES MAC OS';
|
||||||
|
|
||||||
|
let portatiles = ['PORTÁTILES WINDOWS', 'PORTÁTILES CHROMEBOOK'];
|
||||||
|
|
||||||
|
let tabletas = ['TABLETA ANDROID', 'TABLETA iPAD OS'];
|
||||||
|
|
||||||
|
let impresoras = [
|
||||||
|
'INYECCIÓN TINTA',
|
||||||
|
'LÁSER DE ALTO VOLUMEN B/N',
|
||||||
|
'LÁSER DE ALTO VOLUMEN COLOR',
|
||||||
|
'LÁSER PEQUEÑA B/N',
|
||||||
|
'LÁSER PEQUEÑA COLOR',
|
||||||
|
'MATRIZ DE PUNTOS',
|
||||||
|
'MULTIFUNCIONALES',
|
||||||
|
'IMPRESORA TÉRMICA',
|
||||||
|
'IMPRESORA CREDENCIALES',
|
||||||
|
'PLOTTER',
|
||||||
|
];
|
||||||
|
|
||||||
|
let dijitales = [
|
||||||
|
'3D',
|
||||||
|
'DIGITALIZADOR DE CAMA PLANA PARA OFICINA',
|
||||||
|
'DIGITALIZADOR DE GRAN VOLUMEN',
|
||||||
|
'DIGITALIZADOR CON ALIMENTADOR DE HOJAS PARA OFICINA',
|
||||||
|
];
|
||||||
|
|
||||||
|
let servidor = 'SERVIDOR';
|
||||||
|
|||||||
@@ -3,12 +3,39 @@ import { EquipoService } from './equipo.service';
|
|||||||
import { EquipoController } from './equipo.controller';
|
import { EquipoController } from './equipo.controller';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Equipo } from './entities/equipo.entity';
|
import { Equipo } from './entities/equipo.entity';
|
||||||
import { Estado, Marca, Uso, Adscripcion, TipoEquipo, SistemaOperativo, Procesador } from './entities/catalogo.entities';
|
import {
|
||||||
|
Estado,
|
||||||
|
Marca,
|
||||||
|
Uso,
|
||||||
|
Adscripcion,
|
||||||
|
TipoEquipo,
|
||||||
|
SistemaOperativo,
|
||||||
|
Procesador,
|
||||||
|
Periferico,
|
||||||
|
Proyecto,
|
||||||
|
Laboratorio,
|
||||||
|
} from './entities/catalogo.entities';
|
||||||
|
import { MovimientoModule } from 'src/movimiento/movimiento.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports:[TypeOrmModule.forFeature([Equipo, Estado, Marca, Uso, Adscripcion, TipoEquipo, SistemaOperativo, Procesador])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([
|
||||||
|
Equipo,
|
||||||
|
Estado,
|
||||||
|
Marca,
|
||||||
|
Uso,
|
||||||
|
Adscripcion,
|
||||||
|
TipoEquipo,
|
||||||
|
SistemaOperativo,
|
||||||
|
Procesador,
|
||||||
|
Periferico,
|
||||||
|
Proyecto,
|
||||||
|
Laboratorio,
|
||||||
|
]),
|
||||||
|
MovimientoModule,
|
||||||
|
],
|
||||||
controllers: [EquipoController],
|
controllers: [EquipoController],
|
||||||
providers: [EquipoService],
|
providers: [EquipoService],
|
||||||
exports:[EquipoService],
|
exports: [EquipoService],
|
||||||
})
|
})
|
||||||
export class EquipoModule {}
|
export class EquipoModule {}
|
||||||
|
|||||||
+1657
-22
File diff suppressed because it is too large
Load Diff
+12
-1
@@ -4,7 +4,18 @@ import { ValidationPipe } from '@nestjs/common';
|
|||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
// Habilita validación global para que DTOs invalidos devuelvan 400 en lugar de 500
|
let origen
|
||||||
|
if (process.env.MODO === 'pruebas') {
|
||||||
|
origen = '*'
|
||||||
|
} else {
|
||||||
|
origen = [process.env.CORS_ORIGINS]
|
||||||
|
}
|
||||||
|
app.enableCors({
|
||||||
|
origin: origen,
|
||||||
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||||
|
credentials: true,
|
||||||
|
});
|
||||||
|
|
||||||
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class CreateMovimientoDto {
|
|||||||
@IsNumber()
|
@IsNumber()
|
||||||
idEquipo: number;
|
idEquipo: number;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
observaciones: string;
|
observaciones?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,29 @@
|
|||||||
import { Equipo } from 'src/equipo/entities/equipo.entity';
|
import { Equipo } from 'src/equipo/entities/equipo.entity';
|
||||||
import { Usuario } from 'src/usuarios/entities/usuario.entity';
|
import { Usuario } from 'src/usuarios/entities/usuario.entity';
|
||||||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
|
import {
|
||||||
|
Entity,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
Column,
|
||||||
|
ManyToOne,
|
||||||
|
JoinColumn,
|
||||||
|
} from 'typeorm';
|
||||||
|
|
||||||
@Entity('movimientos')
|
@Entity('movimientos')
|
||||||
export class Movimiento {
|
export class Movimiento {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_movimiento: number;
|
id_movimiento: number;
|
||||||
|
|
||||||
@ManyToOne(() => Usuario, user => user.movimiento)
|
@JoinColumn({ name: 'id_usuario' })
|
||||||
|
@ManyToOne(() => Usuario, (user) => user.movimiento)
|
||||||
user: Usuario;
|
user: Usuario;
|
||||||
|
|
||||||
@ManyToOne(() => Equipo, equipo=> equipo.mov)
|
@JoinColumn({ name: 'id_equipo' })
|
||||||
|
@ManyToOne(() => Equipo, (equipo) => equipo.mov)
|
||||||
equipo: Equipo;
|
equipo: Equipo;
|
||||||
|
|
||||||
@Column({ name: 'fecha_movimiento' })
|
@Column({ name: 'fecha_movimiento' })
|
||||||
fechaMovimiento: Date;
|
fechaMovimiento: Date;
|
||||||
|
|
||||||
@Column({ type: 'text', nullable: true })
|
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||||
observaciones: string;
|
observaciones: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,32 @@
|
|||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Post,
|
|
||||||
Get,
|
Get,
|
||||||
Body,
|
|
||||||
Param,
|
|
||||||
ParseIntPipe,
|
|
||||||
Patch,
|
|
||||||
UseGuards,
|
UseGuards,
|
||||||
|
Req,
|
||||||
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { MovimientoService } from './movimiento.service';
|
import { MovimientoService } from './movimiento.service';
|
||||||
import { CreateMovimientoDto } from './dto/create-movimiento.dto';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { UpdateMovimientoDto } from './dto/update-movimiento.dto';
|
|
||||||
|
|
||||||
@Controller('movimientos')
|
@Controller('movimientos')
|
||||||
export class MovimientoController {
|
export class MovimientoController {
|
||||||
constructor(private readonly movimientoService: MovimientoService) {}
|
constructor(private readonly movimientoService: MovimientoService) {}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('historial')
|
||||||
|
buscarEquipoPorToken(@Req() req: any) {
|
||||||
|
const id_usuario = req.user.id;
|
||||||
|
|
||||||
|
if (!id_usuario) {
|
||||||
|
throw new NotFoundException('token sin id_usuario');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.movimientoService.searchByIdUser(id_usuario);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard('jwt'))
|
||||||
|
@Get('dia')
|
||||||
|
EquiposCensadosPorDia() {
|
||||||
|
return this.movimientoService.countCensosPorDiaUnicos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,26 +6,84 @@ import { Usuario } from 'src/usuarios/entities/usuario.entity';
|
|||||||
import { Equipo } from 'src/equipo/entities/equipo.entity';
|
import { Equipo } from 'src/equipo/entities/equipo.entity';
|
||||||
import { CreateMovimientoDto } from './dto/create-movimiento.dto';
|
import { CreateMovimientoDto } from './dto/create-movimiento.dto';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MovimientoService {
|
export class MovimientoService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Movimiento)
|
@InjectRepository(Movimiento)
|
||||||
private readonly movimientoRepo: Repository<Movimiento>,
|
private readonly movimientoRepo: Repository<Movimiento>,
|
||||||
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async crear(dto: CreateMovimientoDto) {
|
async crear(dto: CreateMovimientoDto) {
|
||||||
|
const movimiento = this.movimientoRepo.create({
|
||||||
const movimiento = this.movimientoRepo.create({
|
user: { id_usuario: dto.idUsuario },
|
||||||
user:{id_usuario:dto.idUsuario},
|
equipo: { id_equipo: dto.idEquipo },
|
||||||
equipo:{id_equipo:dto.idEquipo},
|
fechaMovimiento: new Date(),
|
||||||
fechaMovimiento:new Date(),
|
observaciones: dto.observaciones,
|
||||||
observaciones:dto.observaciones
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return await this.movimientoRepo.save(movimiento);
|
return await this.movimientoRepo.save(movimiento);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async buscar(idEquipo: number) {
|
||||||
|
const movimiento = await this.movimientoRepo.findOne({
|
||||||
|
where: { equipo: { id_equipo: idEquipo } },
|
||||||
|
order: { fechaMovimiento: 'DESC' },
|
||||||
|
relations: ['user'],
|
||||||
|
});
|
||||||
|
|
||||||
|
return movimiento;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async searchByIdUser(id_usuario: number) {
|
||||||
|
const movimientos = await this.movimientoRepo
|
||||||
|
.createQueryBuilder('mov')
|
||||||
|
.leftJoinAndSelect('mov.equipo', 'equipo')
|
||||||
|
.leftJoinAndSelect('equipo.tipoEquipo', 'tipoEquipo')
|
||||||
|
.leftJoinAndSelect('equipo.periferico', 'periferico')
|
||||||
|
.leftJoin('mov.user', 'user')
|
||||||
|
.where('user.id_usuario = :id_usuario', { id_usuario })
|
||||||
|
.orderBy('mov.fechaMovimiento', 'DESC')
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
if (!movimientos.length) {
|
||||||
|
throw new NotFoundException('Sin equipos modificados o guardados');
|
||||||
|
}
|
||||||
|
|
||||||
|
const vistos = new Set<string>();
|
||||||
|
const unicos: Movimiento[] = [];
|
||||||
|
|
||||||
|
for (const mov of movimientos) {
|
||||||
|
const inventario = mov.equipo?.inventario;
|
||||||
|
|
||||||
|
if (!vistos.has(inventario)) {
|
||||||
|
vistos.add(inventario);
|
||||||
|
unicos.push(mov);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return unicos.map((mov) => ({
|
||||||
|
inventario: mov.equipo?.inventario,
|
||||||
|
tipo_equipo: mov.equipo?.tipoEquipo?.tipo_equipo,
|
||||||
|
periferico: mov.equipo?.periferico?.periferico,
|
||||||
|
fechaMovimiento: mov.fechaMovimiento,
|
||||||
|
lugar: mov.equipo?.lugar,
|
||||||
|
observaciones: mov.observaciones,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
async countCensosPorDiaUnicos() {
|
||||||
|
const result = await this.movimientoRepo
|
||||||
|
.createQueryBuilder('mov')
|
||||||
|
.innerJoin('mov.equipo', 'equipo')
|
||||||
|
.select('DATE(mov.fechaMovimiento)', 'fecha')
|
||||||
|
.addSelect('COUNT(DISTINCT equipo.inventario)', 'total')
|
||||||
|
.groupBy('DATE(mov.fechaMovimiento)')
|
||||||
|
.orderBy('fecha', 'DESC')
|
||||||
|
.getRawMany();
|
||||||
|
|
||||||
|
return result.map((r) => ({
|
||||||
|
fecha: r.fecha,
|
||||||
|
total: Number(r.total),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { DefaultValuePipe } from "@nestjs/common"
|
|
||||||
import { Transform } from "class-transformer"
|
import { Transform } from "class-transformer"
|
||||||
import { IsInt, IsNotEmpty, IsOptional, IsString, MinLength} from "class-validator"
|
import { IsInt, IsNotEmpty, IsOptional, IsString, MinLength} from "class-validator"
|
||||||
|
|
||||||
@@ -18,5 +17,4 @@ contraseña:string
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
tipoUsuario?:number
|
tipoUsuario?:number
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,31 @@
|
|||||||
import { PartialType } from '@nestjs/mapped-types';
|
import { DefaultValuePipe } from '@nestjs/common';
|
||||||
import { CreateUsuarioDto } from './create-usuario.dto';
|
import { Transform } from 'class-transformer';
|
||||||
|
import {
|
||||||
|
IsInt,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
MinLength,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class UpdateUsuarioDto extends PartialType(CreateUsuarioDto) {}
|
export class UpdateUsuarioDto {
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
nombre?: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@MinLength(5)
|
||||||
|
@Transform(({ value }) => value.trim())
|
||||||
|
@IsOptional()
|
||||||
|
contraseñaN?: string;
|
||||||
|
|
||||||
|
@IsInt()
|
||||||
|
@IsOptional()
|
||||||
|
tipoUsuario?: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@MinLength(5)
|
||||||
|
@Transform(({ value }) => value.trim())
|
||||||
|
@IsOptional()
|
||||||
|
contraseñaV?: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Movimiento } from 'src/movimiento/entities/movimiento.entity';
|
|||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
Entity,
|
Entity,
|
||||||
|
JoinColumn,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
@@ -12,7 +13,7 @@ export class Tipo_Usuario {
|
|||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_tipo_usuario: number;
|
id_tipo_usuario: number;
|
||||||
|
|
||||||
@Column({ length: 50, nullable: true })
|
@Column({ type: 'varchar', length: 50, nullable: true })
|
||||||
tipo_usuario: string;
|
tipo_usuario: string;
|
||||||
|
|
||||||
@OneToMany(() => Usuario, (usuarios) => usuarios.tipoUsuario)
|
@OneToMany(() => Usuario, (usuarios) => usuarios.tipoUsuario)
|
||||||
@@ -24,12 +25,13 @@ export class Usuario {
|
|||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id_usuario: number;
|
id_usuario: number;
|
||||||
|
|
||||||
@Column({ length: 100, nullable: true })
|
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||||
nombre: string;
|
nombre: string;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ type: 'varchar', length: 100, nullable: true })
|
||||||
contraseña: string;
|
contraseña: string;
|
||||||
|
|
||||||
|
@JoinColumn({ name: 'id_tipo_usuario' })
|
||||||
@ManyToOne(() => Tipo_Usuario, (tipoUsuario) => tipoUsuario.usuarios)
|
@ManyToOne(() => Tipo_Usuario, (tipoUsuario) => tipoUsuario.usuarios)
|
||||||
tipoUsuario: Tipo_Usuario;
|
tipoUsuario: Tipo_Usuario;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
Injectable,
|
||||||
|
NotFoundException,
|
||||||
|
UnauthorizedException,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { CreateUsuarioDto } from './dto/create-usuario.dto';
|
import { CreateUsuarioDto } from './dto/create-usuario.dto';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Tipo_Usuario, Usuario } from './entities/usuario.entity';
|
import { Tipo_Usuario, Usuario } from './entities/usuario.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import * as bcrypt from 'bcryptjs';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsuariosService {
|
export class UsuariosService {
|
||||||
@@ -13,6 +19,67 @@ export class UsuariosService {
|
|||||||
@InjectRepository(Tipo_Usuario)
|
@InjectRepository(Tipo_Usuario)
|
||||||
private readonly tipoUsuarioRepository: Repository<Tipo_Usuario>,
|
private readonly tipoUsuarioRepository: Repository<Tipo_Usuario>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async usuarios() {
|
||||||
|
return await this.usuarioRepository.find({ relations: ['tipoUsuario'] });
|
||||||
|
}
|
||||||
|
|
||||||
|
async actualizarUsuario(
|
||||||
|
id: number,
|
||||||
|
datos: {
|
||||||
|
nombre?: string;
|
||||||
|
contraseñaN?: string;
|
||||||
|
id_tipo_usuario?: number;
|
||||||
|
contraseñaV?: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
// Buscar al usuario
|
||||||
|
const usuario = await this.usuarioRepository.findOne({
|
||||||
|
where: { id_usuario: id },
|
||||||
|
relations: ['tipoUsuario'],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!usuario) {
|
||||||
|
throw new NotFoundException('Usuario no encontrado');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualizar nombre
|
||||||
|
if (datos.nombre) {
|
||||||
|
usuario.nombre = datos.nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualizar contraseña con hash
|
||||||
|
if (datos.contraseñaN && datos.contraseñaV) {
|
||||||
|
const contraseñaValida = await bcrypt.compare(
|
||||||
|
datos.contraseñaV,
|
||||||
|
usuario.contraseña,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!contraseñaValida) {
|
||||||
|
throw new UnauthorizedException('Contraseña inválida');
|
||||||
|
}
|
||||||
|
|
||||||
|
const hashed = await bcrypt.hash(datos.contraseñaN, 10);
|
||||||
|
usuario.contraseña = hashed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualizar tipo de usuario
|
||||||
|
if (datos.id_tipo_usuario) {
|
||||||
|
const tipo = await this.tipoUsuarioRepository.findOne({
|
||||||
|
where: { id_tipo_usuario: datos.id_tipo_usuario },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!tipo) {
|
||||||
|
throw new BadRequestException('El tipo de usuario no existe');
|
||||||
|
}
|
||||||
|
|
||||||
|
usuario.tipoUsuario = tipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guardar cambios
|
||||||
|
return await this.usuarioRepository.save(usuario);
|
||||||
|
}
|
||||||
|
|
||||||
async create(createUsuarioDto: CreateUsuarioDto) {
|
async create(createUsuarioDto: CreateUsuarioDto) {
|
||||||
let user = await this.usuarioRepository.create({
|
let user = await this.usuarioRepository.create({
|
||||||
nombre: createUsuarioDto.nombre,
|
nombre: createUsuarioDto.nombre,
|
||||||
|
|||||||
Reference in New Issue
Block a user