Skip to content

Commit 4b14a5c

Browse files
committed
fix(repository): default where object to an empty object
1 parent 6560f25 commit 4b14a5c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/repository/src/repositories/legacy-juggler-bridge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export class DefaultCrudRepository<T extends Entity, ID>
219219
where?: Where,
220220
options?: Options,
221221
): Promise<number> {
222+
where = where || {};
222223
return ensurePromise(this.modelClass.updateAll(where, data, options)).then(
223224
result => result.count,
224225
);

packages/repository/test/unit/repositories/legacy-juggler-bridge.unit.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ describe('DefaultCrudRepository', () => {
177177
expect(notes[0].content).to.eql('c5');
178178
});
179179

180+
it('implements Repository.updateAll() without a where object', async () => {
181+
const repo = new DefaultCrudRepository(Note, ds);
182+
await repo.create({title: 't3', content: 'c3'});
183+
await repo.create({title: 't4', content: 'c4'});
184+
const result = await repo.updateAll({content: 'c5'});
185+
expect(result).to.eql(2);
186+
const notes = await repo.find();
187+
const titles = notes.map(n => `${n.title}:${n.content}`);
188+
expect(titles).to.deepEqual(['t3:c5', 't4:c5']);
189+
});
190+
180191
it('implements Repository.count()', async () => {
181192
const repo = new DefaultCrudRepository(Note, ds);
182193
await repo.create({title: 't3', content: 'c3'});

0 commit comments

Comments
 (0)