Skip to content

Commit

Permalink
Update multi patch sort
Browse files Browse the repository at this point in the history
  • Loading branch information
DaddyWarbucks committed Mar 14, 2024
1 parent f75b4f2 commit f933f4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 16 additions & 14 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 0 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,6 @@ describe('Feathers Sequelize Service', () => {
// @ts-ignore
delete result.updatedAt

console.log(result, { ...current, ...data })

assert.deepStrictEqual(result, { ...current, ...data });
});

Expand Down

0 comments on commit f933f4c

Please sign in to comment.