Skip to content

Commit

Permalink
fix(sequelize): exclude undefined values from where filter
Browse files Browse the repository at this point in the history
Signed-off-by: KalleV <kvirtaneva@gmail.com>
  • Loading branch information
KalleV authored and samarpanB committed Nov 15, 2023
1 parent bdee472 commit 8292615
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -179,6 +179,27 @@ describe('Sequelize CRUD Repository (integration)', () => {
expect(afterResponse).to.not.have.property('password');
});

it('[find] excludes undefined props from where filter', async () => {
const user = getDummyUser();
await userRepo.create({
name: user.name,
address: user.address as AnyObject,
email: user.email,
password: user.password,
dob: user.dob,
active: user.active,
});

const userData = await userRepo.find({
where: {name: user.name, email: user.email, password: undefined},
});

expect(userData.length).to.be.eql(1);
expect(userData[0]).to.have.property('name', user.name);
expect(userData[0]).to.have.property('email', user.email);
expect(userData[0]).to.have.property('password', user.password);
});

it('[findById] allows accessing hidden props before serializing', async () => {
const user = getDummyUser();
const createdUser = await userRepo.create({
Expand Down
Expand Up @@ -621,6 +621,11 @@ export class SequelizeCrudRepository<
where[columnName as keyof typeof where]
);

// Ignoring undefined values for backwards compatibility with Loopback Juggler ORM API
if (typeof conditionValue === 'undefined') {
continue;
}

if (isTruelyObject(conditionValue)) {
sequelizeWhere[columnName] = {};

Expand Down

0 comments on commit 8292615

Please sign in to comment.