validate token

This commit is contained in:
TuNombreDeUsuario
2024-06-12 11:40:20 -06:00
parent 3c1f35962b
commit f91ce40371
6 changed files with 68 additions and 30 deletions
@@ -1,11 +1,10 @@
import { IsEmail, IsNotEmpty, IsString, MinLength } from "class-validator";
export class CreateUserDto{
export class UserDto{
@IsString()
readonly name: string;
name: string;
@IsNotEmpty()
@MinLength(10)
readonly password: string;
password: string;
}
+16 -3
View File
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from './entities/user.entity';
import { UserDto } from './dto/userDto.dto';
@Injectable()
export class UsersService {
@@ -19,11 +20,23 @@ export class UsersService {
return this.users.save(newUser);
}
async updateTokenAndDates(id: number, jwt: string, lastlog: Date, expirationjwt: Date): Promise<void> {
await this.users.update(id, { jwt, lastlog, expirationjwt });
async update(userId: number, updateUserDto: UserDto): Promise<User> {
await this.users.update(userId, updateUserDto);
return this.users.findOne({where:{userId}});
}
async remove(userId: number): Promise<void> {
await this.users.delete(userId);
}
async updateTokenAndDates(id: number, token: string, lastLogin: Date, jwtExpiry: Date): Promise<void> {
await this.users.update(id, {
jwt:token,
lastlog:lastLogin,
expirationjwt:jwtExpiry,
});
}
}