Skip to content

Commit

Permalink
fix: Fix queryDraft error
Browse files Browse the repository at this point in the history
  • Loading branch information
SimYunSup committed May 22, 2024
1 parent 7aa5431 commit 07ab50e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
47 changes: 25 additions & 22 deletions packages/db-postgres/src/queries/buildQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,32 @@ const buildQuery = async function buildQuery({
let orderBy: Result['orderBy'] = []

if (sort) {
orderBy = sort.split(',').map((sortString) => {
const sortPath = sortString.replace(/^-/, '')
try {
const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({
adapter,
collectionPath: sortPath,
fields,
joinAliases,
joins,
locale,
pathSegments: sortPath.replace(/__/g, '.').split('.'),
selectFields,
tableName,
value: sortPath,
})
return {
column: sortTable?.[sortTableColumnName] ?? null,
order: sortString[0] === '-' ? desc : asc,
orderBy = sort
.split(',')
.map((sortString) => {
const sortPath = sortString.replace(/^-/, '')
try {
const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({
adapter,
collectionPath: sortPath,
fields,
joinAliases,
joins,
locale,
pathSegments: sortPath.replace(/__/g, '.').split('.'),
selectFields,
tableName,
value: sortPath,
})
return {
column: sortTable?.[sortTableColumnName] ?? null,
order: sortString[0] === '-' ? desc : asc,
}
} catch (err) {
// continue
}
} catch (err) {
// continue
}
})
})
.filter((sortInfo) => !!sortInfo)
}

if (!orderBy.length) {
Expand Down
21 changes: 12 additions & 9 deletions packages/payload/src/versions/drafts/getQueryDraftsSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
export const getQueryDraftsSort = (sort: string): string => {
if (!sort) return sort

let direction = ''
let orderBy = sort

if (sort[0] === '-') {
direction = '-'
orderBy = sort.substring(1)
}

return `${direction}version.${orderBy}`
return sort
.split(' ')
.map((sortString) => {
let direction = ''
let orderBy = sortString
if (sortString[0] === '-') {
direction = '-'
orderBy = sortString.substring(1)
}
return `${direction}version.${orderBy}`
})
.join(' ')
}

0 comments on commit 07ab50e

Please sign in to comment.