After some testing, I came across an interesting quirk with typeorm. It turns out that if a property in the WHERE clause of a FIND query (such as find, findOne, findBy, etc) is undefined, it behaves as if it's true and returns records - returning the first record for findOne and all records for find.
I understand that this can be avoided by using validators or an IF statement to check against undefined properties. However, I'm curious if there's a direct way within typeorm itself to handle this without additional checks.
Here's a snippet of what I observed:
const client = await this.clientRepository.findOne({
where: {
id: payload.clientId //undefined
}
});
Surprisingly, I was able to retrieve the first record from the client table even though clientId was undefined.