Merge branch 'master' into budi-8238-rewrite-postgresspects-to-use-knex
This commit is contained in:
commit
75e79156f7
|
@ -596,6 +596,9 @@ class InternalBuilder {
|
|||
const offset = page * paginate.limit
|
||||
foundLimit = paginate.limit
|
||||
foundOffset = offset
|
||||
} else if (paginate && paginate.offset && paginate.limit) {
|
||||
foundLimit = paginate.limit
|
||||
foundOffset = paginate.offset
|
||||
} else if (paginate && paginate.limit) {
|
||||
foundLimit = paginate.limit
|
||||
}
|
||||
|
|
|
@ -512,14 +512,10 @@ describe.each([
|
|||
])
|
||||
})
|
||||
|
||||
// TODO(samwho): fix for SQS
|
||||
!isSqs &&
|
||||
it("should match the session user id in a multi user field", async () => {
|
||||
const allUsers = [...globalUsers, config.getUser()].map(
|
||||
(user: any) => {
|
||||
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
|
||||
return { _id: user._id }
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
await expectQuery({
|
||||
contains: { multi_user: ["{{ [user]._id }}"] },
|
||||
|
@ -531,14 +527,10 @@ describe.each([
|
|||
])
|
||||
})
|
||||
|
||||
// TODO(samwho): fix for SQS
|
||||
!isSqs &&
|
||||
it("should match the session user id in a deprecated multi user field", async () => {
|
||||
const allUsers = [...globalUsers, config.getUser()].map(
|
||||
(user: any) => {
|
||||
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
|
||||
return { _id: user._id }
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
await expectQuery({
|
||||
contains: { deprecated_multi_user: ["{{ [user]._id }}"] },
|
||||
|
@ -550,8 +542,6 @@ describe.each([
|
|||
])
|
||||
})
|
||||
|
||||
// TODO(samwho): fix for SQS
|
||||
!isSqs &&
|
||||
it("should not match the session user id in a multi user field", async () => {
|
||||
await expectQuery({
|
||||
notContains: { multi_user: ["{{ [user]._id }}"] },
|
||||
|
@ -566,8 +556,6 @@ describe.each([
|
|||
])
|
||||
})
|
||||
|
||||
// TODO(samwho): fix for SQS
|
||||
!isSqs &&
|
||||
it("should not match the session user id in a deprecated multi user field", async () => {
|
||||
await expectQuery({
|
||||
notContains: { deprecated_multi_user: ["{{ [user]._id }}"] },
|
||||
|
@ -1552,8 +1540,6 @@ describe.each([
|
|||
})
|
||||
})
|
||||
|
||||
// TODO(samwho): fix for SQS
|
||||
!isSqs &&
|
||||
describe("pagination", () => {
|
||||
it("should paginate through all rows", async () => {
|
||||
// @ts-ignore
|
||||
|
@ -1578,10 +1564,8 @@ describe.each([
|
|||
bookmark = response.bookmark
|
||||
}
|
||||
|
||||
expect(rows).toHaveLength(10)
|
||||
expect(rows.map(row => row.auto)).toEqual(
|
||||
expect.arrayContaining([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
||||
)
|
||||
const autoValues = rows.map(row => row.auto).sort((a, b) => a - b)
|
||||
expect(autoValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -167,13 +167,9 @@ export async function search(
|
|||
const sortField = table.schema[params.sort]
|
||||
const sortType =
|
||||
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
|
||||
const sortDirection =
|
||||
params.sortOrder === SortOrder.ASCENDING
|
||||
? SortOrder.ASCENDING
|
||||
: SortOrder.DESCENDING
|
||||
request.sort = {
|
||||
[sortField.name]: {
|
||||
direction: sortDirection,
|
||||
direction: params.sortOrder || SortOrder.DESCENDING,
|
||||
type: sortType as SortType,
|
||||
},
|
||||
}
|
||||
|
@ -182,14 +178,15 @@ export async function search(
|
|||
if (params.bookmark && typeof params.bookmark !== "number") {
|
||||
throw new Error("Unable to paginate with string based bookmarks")
|
||||
}
|
||||
const bookmark: number = (params.bookmark as number) || 1
|
||||
const limit = params.limit
|
||||
|
||||
const bookmark: number = (params.bookmark as number) || 0
|
||||
if (paginate && params.limit) {
|
||||
request.paginate = {
|
||||
limit: params.limit + 1,
|
||||
page: bookmark,
|
||||
offset: bookmark * params.limit,
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const rows = await runSqlQuery(request, allTables)
|
||||
|
||||
|
@ -221,18 +218,12 @@ export async function search(
|
|||
}
|
||||
|
||||
// check for pagination
|
||||
if (paginate && limit) {
|
||||
if (paginate) {
|
||||
const response: SearchResponse<Row> = {
|
||||
rows: finalRows,
|
||||
}
|
||||
const prevLimit = request.paginate!.limit
|
||||
request.paginate = {
|
||||
limit: 1,
|
||||
page: bookmark * prevLimit + 1,
|
||||
}
|
||||
const hasNextPage = !!nextRow
|
||||
response.hasNextPage = hasNextPage
|
||||
if (hasNextPage) {
|
||||
if (nextRow) {
|
||||
response.hasNextPage = true
|
||||
response.bookmark = bookmark + 1
|
||||
}
|
||||
return response
|
||||
|
|
|
@ -85,6 +85,7 @@ export interface SortJson {
|
|||
export interface PaginationJson {
|
||||
limit: number
|
||||
page?: string | number
|
||||
offset?: number
|
||||
}
|
||||
|
||||
export interface RenameColumn {
|
||||
|
|
Loading…
Reference in New Issue