Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/query/match/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const sortList = (data: any[], params: SortOptions) => {
// `null` values are treated as `"null"` strings and ordered alphabetically
// Turn `null` values into `undefined` so they place at the end of the list
.map(value => value === null ? undefined : value)
if (params[key] === 0) {
if (params[key] === -1) {
values.reverse()
}
return comperable.compare(values[0], values[1])
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface SortParams {
}

export interface SortFields {
[field: string]: 0 | 1
[field: string]: -1 | 1
}

export type SortOptions = SortParams | SortFields
Expand Down
2 changes: 1 addition & 1 deletion test/features/query/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Database Provider', () => {
const nameAsc = await createQuery(pipelineFetcher).sort({ name: 1 }).find()
assert(nameAsc[0].name === database[0].name)

const nameDesc = await createQuery(pipelineFetcher).sort({ name: 0 }).find()
const nameDesc = await createQuery(pipelineFetcher).sort({ name: -1 }).find()
assert(nameDesc[0].name === database[database.length - 1].name)
})

Expand Down
10 changes: 5 additions & 5 deletions test/features/query/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('query utils', () => {
{ a: 2, b: 1 }
])

expect(sortList(data, { a: 0 })).toEqual([
expect(sortList(data, { a: -1 })).toEqual([
{ a: 2, b: 1 },
{ a: 1, b: 2 },
{ a: 1, b: 1 }
Expand All @@ -86,7 +86,7 @@ describe('query utils', () => {
{ a: 1, b: 2 }
])

expect(sortList(data, { b: 0 })).toEqual([
expect(sortList(data, { b: -1 })).toEqual([
{ a: 1, b: 2 },
{ a: 2, b: 1 },
{ a: 1, b: 1 }
Expand All @@ -97,8 +97,8 @@ describe('query utils', () => {
const data = [{ data: { a: 1, b: 2 } }, { data: { a: 2, b: 1 } }, { data: { a: 1, b: 1 } }]

// sort by a descending
const aDesc = sortList(data, { 'data.a': 0 })
expect(sortList(aDesc, { 'data.b': 0 })).toEqual([
const aDesc = sortList(data, { 'data.a': -1 })
expect(sortList(aDesc, { 'data.b': -1 })).toEqual([
{ data: { a: 1, b: 2 } },
{ data: { a: 2, b: 1 } },
{ data: { a: 1, b: 1 } }
Expand All @@ -112,6 +112,6 @@ describe('query utils', () => {
])

// Sort again by a desc.
expect(sortList(aDesc, { 'data.a': 0 })).toEqual(aDesc)
expect(sortList(aDesc, { 'data.a': -1 })).toEqual(aDesc)
})
})