Given is a nestJS application (0.8) with typeORM (0.2), which contains queries like this:
async findAllForClient(client: ClientEntity): Promise<VaultEntity[]> {
return this.repository.find({
where: { client: client },
order: { createdAt: 'ASC' },
});
}
client is a OneToMany-relation between an Entity ("Value") to another ("Client")
After upgrade to typeORM 0.3 this does not compile anymore:
TS2322: Type 'ClientEntity' is not assignable to type 'boolean | FindOperator | FindOptionsWhere | FindOptionsWhere[] | EqualOperator<...>'. Type 'ClientEntity' is not assignable to type 'FindOptionsWhere'. Types of property 'users' are incompatible.
Type 'UserEntity[]' is not assignable to type 'boolean | FindOperator | FindOptionsWhere | FindOptionsWhere[] | EqualOperator<...>'.
Type 'UserEntity[]' is not assignable to type 'FindOptionsWhere[]'.
Type 'UserEntity' is not assignable to type 'FindOptionsWhere'.
Types of property 'hasRole' are incompatible. Type '(role: string) => boolean' is not assignable to type 'never'.
For sake of completeness I will post the entities:
VaultEntity:
@Entity({ name: 'vaults' })
@Unique('idx_unique_uuid', ['uuid'])
export class VaultEntity extends ImmutableBaseEntity {
@ManyToOne(() => ClientEntity, (entity) => entity.vaults)
@JoinColumn({ name: 'client_id' })
@Index()
client: ClientEntity;
@Column({ name: 'uuid', type: 'varchar', length: 64 })
@IsUUID()
uuid: string;
// .... more properties that makes no sense to mention them here
}
ClientEntity:
@Entity({ name: 'clients' })
@Unique('idx_unique_uuid', ['uuid'])
export class ClientEntity extends ImmutableBaseEntity {
@ApiProperty({ description: 'UUID' })
@Column({ name: 'uuid', type: 'varchar', length: 64 })
@IsUUID()
uuid: string;
@ApiProperty({ description: 'Associated vaults' })
@OneToMany(() => VaultEntity, (vault) => vault.client, { cascade: true })
@JoinColumn({ name: 'client_id' })
vaults: VaultEntity[];
@ApiProperty({ type: (type) => UserEntity, isArray: true })
@OneToMany(() => UserEntity, (user) => user.client, { cascade: true })
users: UserEntity[];
// ....
}
Can someone pls tell me how to make such queries, where relations and entities are involved, work with typeORM 0.3?