fixed create user

This commit is contained in:
2026-01-13 14:51:59 -06:00
parent aa84960ae3
commit 20f6e89e82
6 changed files with 20 additions and 11 deletions
-4
View File
@@ -47,10 +47,6 @@ export class CreateUserDto {
@MaxLength(50)
descripcion?: string;
@IsString()
@IsOptional()
fecha_registro?: string;
@IsInt()
@IsNotEmpty()
id_perfil: number;
-4
View File
@@ -1,4 +0,0 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateUserDto } from './create-user.dto';
export class UpdateUserDto extends PartialType(CreateUserDto) {}
-1
View File
@@ -1,4 +1,3 @@
// jwt-auth.guard.ts
import { ExecutionContext, Injectable, ForbiddenException } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
+1 -1
View File
@@ -1,4 +1,3 @@
// jwt.strategy.ts
import { Injectable, ForbiddenException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
@@ -24,6 +23,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
if (!payload || !payload.id || !payload.usuario) {
throw new ForbiddenException('Token inválido o corrupto');
}
console.log(payload)
return { id: payload.id, usuario: payload.usuario,role:payload.role};
}
}
+10
View File
@@ -17,6 +17,16 @@ import { JwtAuthGuard } from './jwt.guard';
export class UserController {
constructor(private readonly userService: UserService) {}
@Get()
async getAll() {
return this.userService.getAll();
}
@Get('/perfil')
async getAllPerfil() {
return this.userService.getAllPerfil();
}
@Post()
async Login(@Body() data: Login, @Res() res: Response) {
return this.userService.Login(data, res);
+9 -1
View File
@@ -88,7 +88,9 @@ export class UserService {
throw new NotFoundException('Perfil not found');
}
const datauser = { ...rest, perfil };
const fecha_registro = new Date()
const datauser = { ...rest, perfil ,fecha_registro};
const usercreate = this.userRepository.create(datauser);
return this.userRepository.save(usercreate);
@@ -103,5 +105,11 @@ export class UserService {
user.password = data.newPassword;
return this.userRepository.save(user);
}
async getAll(){
return this.userRepository.find();
}
async getAllPerfil(){
return this.perfilRepository.find();
}
}
//IO