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

110
Views
Sorting objects by a text field in TypeOrm

I need to sort fights in a certain order, so that the CONFIRMED ones go first, then the PENDING ones and then the CANCELED_BY_INITIATOR ones.

I execute the following query using TypeORM and I get the following error:

fights" alias was not found. Maybe you forgot to join it?

const fights = await this.fightRepository
    .createQueryBuilder(`${EDBTableNames.FIGHTS}`)
    .leftJoinAndSelect(`${EDBTableNames.FIGHTS}.target`, 'tgts')
    .leftJoinAndSelect(
        `tgts.images`,
        `imgs`,
        `imgs."imageType" = '${EUserImageType.HALF_LENGTH_AVATAR}'`,
    )
    .leftJoinAndSelect(`${EDBTableNames.FIGHTS}.slot`, 'slot')
    .orderBy(
        `
        ${EDBTableNames.FIGHTS}.status != '${EFightStatus.CONFIRMED}',
        ${EDBTableNames.FIGHTS}.status != '${EFightStatus.PENDING}',
        ${EDBTableNames.FIGHTS}.status != '${EFightStatus.CANCELED_BY_INITIATOR}'
        `
    )
    .where(
        `
        ${EDBTableNames.FIGHTS}.initiator = :id AND (
            ${EDBTableNames.FIGHTS}.status = :pending OR
            ${EDBTableNames.FIGHTS}.status = :confirmed OR
            ${EDBTableNames.FIGHTS}.status = :cbInitiator
        )
        `,
        {
        id,
        pending: EFightStatus.PENDING,
        confirmed: EFightStatus.CONFIRMED,
        cbInitiator: EFightStatus.CANCELED_BY_INITIATOR,
        }
    )
    .skip(page * limit)
    .take(limit)
    .getMany();

The ${EDBTableNames.FIGHTS} is equal to fights.

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
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!