Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!