Skip to content

Commit

Permalink
fix: mongodb typing error
Browse files Browse the repository at this point in the history
  • Loading branch information
SimYunSup authored and 심윤섭 committed May 22, 2024
1 parent f8e9a71 commit 7aa5431
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/db-mongodb/src/queries/buildSortParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Args = {
config: SanitizedConfig
fields: Field[]
locale: string
sort: string
sort: string | undefined
timestamps: boolean
}

Expand All @@ -30,7 +30,13 @@ export const buildSortParam = ({
let sortDirection: SortDirection = 'desc'
const isSortMultipleField = sort.includes(',')

if (isSortMultipleField) {
if (!sort) {
if (timestamps) {
sortProperty = 'createdAt'
} else {
sortProperty = '_id'
}
} else if (isSortMultipleField) {
const sortFields = sort.split(',')
return sortFields.reduce((acc, sortField) => {
const isDesc = sortField.indexOf('-') === 0
Expand All @@ -48,14 +54,6 @@ export const buildSortParam = ({
}
return [...acc, `${isDesc ? '-' : ''}${currentSortProperty}`]
}, [])
}

if (!sort) {
if (timestamps) {
sortProperty = 'createdAt'
} else {
sortProperty = '_id'
}
} else if (sort.indexOf('-') === 0) {
sortProperty = sort.substring(1)
} else {
Expand Down

0 comments on commit 7aa5431

Please sign in to comment.