2022-08-05 16:57:21 +02:00
|
|
|
import { get } from "svelte/store"
|
|
|
|
import DataFetch from "./DataFetch.js"
|
|
|
|
import { TableNames } from "../constants"
|
2024-09-09 17:36:31 +02:00
|
|
|
import { utils } from "@budibase/shared-core"
|
2022-08-05 16:57:21 +02:00
|
|
|
|
|
|
|
export default class UserFetch extends DataFetch {
|
|
|
|
constructor(opts) {
|
|
|
|
super({
|
|
|
|
...opts,
|
|
|
|
datasource: {
|
|
|
|
tableId: TableNames.USERS,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
determineFeatureFlags() {
|
|
|
|
return {
|
|
|
|
supportsSearch: true,
|
|
|
|
supportsSort: false,
|
|
|
|
supportsPagination: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 17:40:32 +02:00
|
|
|
async getDefinition() {
|
|
|
|
return {
|
|
|
|
schema: {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 16:57:21 +02:00
|
|
|
async getData() {
|
2023-10-12 17:31:32 +02:00
|
|
|
const { limit, paginate } = this.options
|
2022-08-05 16:57:21 +02:00
|
|
|
const { cursor, query } = get(this.store)
|
2023-10-12 17:31:32 +02:00
|
|
|
let finalQuery
|
|
|
|
// convert old format to new one - we now allow use of the lucene format
|
2024-09-17 12:18:32 +02:00
|
|
|
const { appId, paginated, ...rest } = query || {}
|
2024-09-09 17:36:31 +02:00
|
|
|
|
|
|
|
finalQuery = utils.isSupportedUserSearch(rest)
|
|
|
|
? query
|
|
|
|
: { string: { email: null } }
|
|
|
|
|
2022-08-05 16:57:21 +02:00
|
|
|
try {
|
2023-10-12 17:31:32 +02:00
|
|
|
const opts = {
|
|
|
|
bookmark: cursor,
|
|
|
|
query: finalQuery,
|
|
|
|
appId: appId,
|
|
|
|
paginate: paginated || paginate,
|
|
|
|
limit,
|
|
|
|
}
|
|
|
|
const res = await this.API.searchUsers(opts)
|
2022-08-05 16:57:21 +02:00
|
|
|
return {
|
|
|
|
rows: res?.data || [],
|
|
|
|
hasNextPage: res?.hasNextPage || false,
|
|
|
|
cursor: res?.nextPage || null,
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
hasNextPage: false,
|
|
|
|
error,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|