diff --git a/src/adapter.ts b/src/adapter.ts index 0ee3949..849c0c7 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -395,21 +395,23 @@ export class SequelizeAdapter< const selected = isPresent(sequelize.attributes); if (instances) { - const sortedInstances: Model[] = []; - const unsortedInstances: Model[] = []; - - current.forEach((item: any) => { - const id = item[this.id]; - // @ts-ignore - const instance = instances.find(instance => instance[this.id] === id); - if (instance) { - sortedInstances.push(instance); - } else { - unsortedInstances.push(item); - } - }); + if (isPresent(params?.query?.$sort)) { + const sortedInstances: Model[] = []; + const unsortedInstances: Model[] = []; + + current.forEach((item: any) => { + const id = item[this.id]; + // @ts-ignore + const instance = instances.find(instance => instance[this.id] === id); + if (instance) { + sortedInstances.push(instance); + } else { + unsortedInstances.push(item); + } + }); - instances = [...sortedInstances, ...unsortedInstances]; + instances = [...sortedInstances, ...unsortedInstances]; + } if (sequelize.raw) { const result = instances.map((instance) => { diff --git a/test/index.test.ts b/test/index.test.ts index 98b815e..e0cc11a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -487,8 +487,6 @@ describe('Feathers Sequelize Service', () => { // @ts-ignore delete result.updatedAt - console.log(result, { ...current, ...data }) - assert.deepStrictEqual(result, { ...current, ...data }); });