fixed create user
This commit is contained in:
@@ -47,10 +47,6 @@ export class CreateUserDto {
|
||||
@MaxLength(50)
|
||||
descripcion?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
fecha_registro?: string;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_perfil: number;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateUserDto } from './create-user.dto';
|
||||
|
||||
export class UpdateUserDto extends PartialType(CreateUserDto) {}
|
||||
@@ -1,4 +1,3 @@
|
||||
// jwt-auth.guard.ts
|
||||
import { ExecutionContext, Injectable, ForbiddenException } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user