clean up
This commit is contained in:
parent
8447f4c90f
commit
8a7c130c18
10646
package-lock.json
generated
10646
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -50,6 +50,9 @@
|
|||||||
"typeorm": "^0.2.38",
|
"typeorm": "^0.2.38",
|
||||||
"typescript": "^4.4.3"
|
"typescript": "^4.4.3"
|
||||||
},
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"lodash": "^4.17.21"
|
||||||
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@nestjs/common": "^8.0.11",
|
"@nestjs/common": "^8.0.11",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
@ -84,8 +87,5 @@
|
|||||||
"branches": [
|
"branches": [
|
||||||
"master"
|
"master"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"lodash": "^4.17.21"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -81,29 +81,30 @@ export async function paginate<T>(
|
|||||||
return !!entityColumns.find((c) => c === column)
|
return !!entityColumns.find((c) => c === column)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sortableColumns, searchableColumns } = config
|
|
||||||
if (config.sortableColumns.length < 1) throw new ServiceUnavailableException()
|
if (config.sortableColumns.length < 1) throw new ServiceUnavailableException()
|
||||||
|
|
||||||
if (query.sortBy) {
|
if (query.sortBy) {
|
||||||
for (const order of query.sortBy) {
|
for (const order of query.sortBy) {
|
||||||
if (isEntityKey(sortableColumns, order[0]) && ['ASC', 'DESC'].includes(order[1])) {
|
if (isEntityKey(config.sortableColumns, order[0]) && ['ASC', 'DESC'].includes(order[1])) {
|
||||||
sortBy.push(order as Order<T>)
|
sortBy.push(order as Order<T>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sortBy.length) {
|
if (!sortBy.length) {
|
||||||
sortBy.push(...(config.defaultSortBy || [[sortableColumns[0], 'ASC']]))
|
sortBy.push(...(config.defaultSortBy || [[config.sortableColumns[0], 'ASC']]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.searchBy && searchableColumns) {
|
if (config.searchableColumns) {
|
||||||
|
if (query.searchBy) {
|
||||||
for (const column of query.searchBy) {
|
for (const column of query.searchBy) {
|
||||||
if (isEntityKey(searchableColumns, column)) {
|
if (isEntityKey(config.searchableColumns, column)) {
|
||||||
searchBy.push(column as Column<T>)
|
searchBy.push(column)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!query.searchBy && searchableColumns) {
|
} else {
|
||||||
searchBy.push(...searchableColumns)
|
searchBy.push(...config.searchableColumns)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page < 1) page = 1
|
if (page < 1) page = 1
|
||||||
@ -232,7 +233,7 @@ export async function paginate<T>(
|
|||||||
)
|
)
|
||||||
: ''
|
: ''
|
||||||
|
|
||||||
const options = `&limit=${limit}${sortByQuery}${searchQuery}${filterQuery}${searchByQuery}`
|
const options = `&limit=${limit}${sortByQuery}${searchQuery}${searchByQuery}${filterQuery}`
|
||||||
|
|
||||||
const buildLink = (p: number): string => path + '?page=' + p + options
|
const buildLink = (p: number): string => path + '?page=' + p + options
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user