Skip to content

Commit

Permalink
fix(query): do not create empty where
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Aug 4, 2022
1 parent 2602c07 commit c71c79b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/runtime/server/api/navigation.ts
Expand Up @@ -10,7 +10,7 @@ export default defineEventHandler(async (event) => {

// Read from cache if not preview and there is no query
if (!isPreview(event) && Object.keys(query).length === 0) {
const cache = cacheStorage.getItem('content-navigation.json')
const cache = await cacheStorage.getItem('content-navigation.json')
if (cache) {
return cache
}
Expand Down
10 changes: 8 additions & 2 deletions src/runtime/utils/query.ts
Expand Up @@ -40,15 +40,21 @@ export const getContentQuery = (event: CompatibilityEvent): QueryBuilderParams =
query.without = query.without.split(',').map(s => s.trim())
}

query.where = query.where || {}
const where = query.where || {}
// ?partial=true|false&draft=true|false&empty=true|false
for (const key of ['draft', 'partial', 'empty']) {
// ?partial=true|false
if (query[key] && ['true', 'false'].includes(query[key])) {
query.where[key] = query[key] === 'true'
where[key] = query[key] === 'true'
delete query[key]
}
}
if (Object.keys(where).length > 0) {
query.where = [where]
} else {
delete query.where
}

// ?sortyBy=size:1
if (query.sort) {
query.sort = query.sort.split(',').map((s) => {
Expand Down

0 comments on commit c71c79b

Please sign in to comment.