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?