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"
|
2025-01-02 13:38:38 +01:00
|
|
|
import { Table, UIFetchAPI } from "@budibase/types"
|
2022-08-05 16:57:21 +02:00
|
|
|
|
2025-01-02 13:38:38 +01:00
|
|
|
export default class UserFetch extends DataFetch<{ tableId: string }, {}> {
|
|
|
|
constructor(opts: { API: UIFetchAPI; datasource: Table; options?: {} }) {
|
2022-08-05 16:57:21 +02:00
|
|
|
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: {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-02 13:38:38 +01:00
|
|
|
getSchema(_datasource: any, definition: Table | null) {
|
|
|
|
return definition?.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)
|
2024-09-09 17:36:31 +02:00
|
|
|
|
2024-10-30 10:29:24 +01:00
|
|
|
// Convert old format to new one - we now allow use of the lucene format
|
2025-01-02 13:38:38 +01:00
|
|
|
const { appId, paginated, ...rest } = query || ({} as any) // TODO
|
2024-10-30 10:29:24 +01:00
|
|
|
const finalQuery = utils.isSupportedUserSearch(rest)
|
2024-09-09 17:36:31 +02:00
|
|
|
? 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|