Skip to content

Commit

Permalink
fix(sequelize): resolves SQL error when order filter is an empty string
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 Dec 29, 2023
1 parent 74aa049 commit 56201c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ describe('Sequelize CRUD Repository (integration)', () => {
expect(getResponse.body).to.be.deepEqual(reversedArray);
});

it('ignores an empty `order` filter', async () => {
const users = [
getDummyUser({name: 'ABoy'}),
getDummyUser({name: 'BBoy'}),
getDummyUser({name: 'CBoy'}),
];
const createAllResponse = await client.post('/users-bulk').send(users);
const filter = {
order: '',
};
const getResponse = await client.get(`/users`).query({
filter,
});

expect(getResponse.body).to.be.deepEqual(createAllResponse.body);
});

it('supports `limit` filter', async () => {
const users = [getDummyUser(), getDummyUser(), getDummyUser()];
await client.post('/users-bulk').send(users);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export class SequelizeCrudRepository<
* @returns Sequelize compatible order filter value
*/
protected buildSequelizeOrder(order?: string[] | string): Order | undefined {
if (order === undefined) {
if (order === undefined || order === '') {
return undefined;
}

Expand Down

0 comments on commit 56201c5

Please sign in to comment.