Skip to content

Commit 8292615

Browse files
KalleVsamarpanB
authored andcommitted
fix(sequelize): exclude undefined values from where filter
Signed-off-by: KalleV <kvirtaneva@gmail.com>
1 parent bdee472 commit 8292615

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

extensions/sequelize/src/__tests__/integration/repository.integration.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ describe('Sequelize CRUD Repository (integration)', () => {
179179
expect(afterResponse).to.not.have.property('password');
180180
});
181181

182+
it('[find] excludes undefined props from where filter', async () => {
183+
const user = getDummyUser();
184+
await userRepo.create({
185+
name: user.name,
186+
address: user.address as AnyObject,
187+
email: user.email,
188+
password: user.password,
189+
dob: user.dob,
190+
active: user.active,
191+
});
192+
193+
const userData = await userRepo.find({
194+
where: {name: user.name, email: user.email, password: undefined},
195+
});
196+
197+
expect(userData.length).to.be.eql(1);
198+
expect(userData[0]).to.have.property('name', user.name);
199+
expect(userData[0]).to.have.property('email', user.email);
200+
expect(userData[0]).to.have.property('password', user.password);
201+
});
202+
182203
it('[findById] allows accessing hidden props before serializing', async () => {
183204
const user = getDummyUser();
184205
const createdUser = await userRepo.create({

extensions/sequelize/src/sequelize/sequelize.repository.base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ export class SequelizeCrudRepository<
621621
where[columnName as keyof typeof where]
622622
);
623623

624+
// Ignoring undefined values for backwards compatibility with Loopback Juggler ORM API
625+
if (typeof conditionValue === 'undefined') {
626+
continue;
627+
}
628+
624629
if (isTruelyObject(conditionValue)) {
625630
sequelizeWhere[columnName] = {};
626631

0 commit comments

Comments
 (0)