Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

298
Vistas
Not able to update in Nestjs using typeorm

I have an application I am current working on and all other things are working fine except for one endpoint which is update IsTokenExpired. This holds a boolean which could either be true or false. I have been trying to update this isTokenExpired for some time and it seems to have given up on me. Below is the code list:

password-reset.service.ts

...
async updateExpiryStatus(
    accessToken: string,
    isExpired: boolean
  ): Promise<any> {
    const expiryStatus = await this.passwordRepository.findOne({
      where: { accessToken },
    });
    const result = await this.passwordRepository
      .createQueryBuilder('password_entity')
      .update(PasswordEntity)
      .set({
        isExpired,
      })
      .where('accessToken = :accessToken', { accessToken })
      .execute();
    console.log('====================================');
    console.log({ expiryStatus, accessToken, isExpired });
    console.log('====================================');
    return result;
  }
...

password-reset.controller.ts

 @Put('updateToken/:accessToken')
  updateExpiryStatus(
    @Param('accessToken') accessToken: string,
    @Body() isExpired: boolean
  ): Promise<string> {
    return this.passwordService.updateExpiryStatus(accessToken, isExpired);
  }
}
...

password-reset.entity.ts

import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity('password_reset')
export class PasswordEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  email: string;

  @Column({ unique: true })
  accessToken: string;

  @Column({ default: true })
  isExpired: boolean;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you already query the PasswordEntity with this

const expiryStatus = await this.passwordRepository.findOne({
      where: { accessToken },
    });

Then you can do this to update the isExpired

expiryStatus.isExpired = isExpired;
await this.passwordRepository.save(expiryStatus);

This will update the status for the row that you fetch with the accessToken.

this.passwordRepository.save(expiryStatus) will return the newly updated row.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda