2022-08-05 16:57:21 +02:00
|
|
|
import { get } from "svelte/store"
|
2025-01-14 10:48:50 +01:00
|
|
|
import BaseDataFetch, { DataFetchParams } from "./DataFetch"
|
2024-09-09 17:36:31 +02:00
|
|
|
import { utils } from "@budibase/shared-core"
|
2025-01-16 10:28:06 +01:00
|
|
|
import {
|
|
|
|
InternalTable,
|
|
|
|
SearchFilters,
|
|
|
|
SearchUsersRequest,
|
|
|
|
UserDatasource,
|
|
|
|
} from "@budibase/types"
|
2022-08-05 16:57:21 +02:00
|
|
|
|
2025-01-07 11:17:42 +01:00
|
|
|
interface UserFetchQuery {
|
|
|
|
appId: string
|
|
|
|
paginated: boolean
|
|
|
|
}
|
|
|
|
|
2025-01-14 12:51:27 +01:00
|
|
|
interface UserDefinition {
|
|
|
|
schema?: Record<string, any> | null
|
|
|
|
primaryDisplay?: string
|
|
|
|
}
|
2025-01-09 15:23:20 +01:00
|
|
|
|
2025-01-14 10:48:50 +01:00
|
|
|
export default class UserFetch extends BaseDataFetch<
|
2025-01-08 14:17:10 +01:00
|
|
|
UserDatasource,
|
2025-01-09 15:23:20 +01:00
|
|
|
UserDefinition,
|
2025-01-07 11:17:42 +01:00
|
|
|
UserFetchQuery
|
|
|
|
> {
|
2025-01-08 14:17:10 +01:00
|
|
|
constructor(opts: DataFetchParams<UserDatasource, UserFetchQuery>) {
|
2022-08-05 16:57:21 +02:00
|
|
|
super({
|
|
|
|
...opts,
|
|
|
|
datasource: {
|
2025-01-09 15:23:20 +01:00
|
|
|
type: "user",
|
2025-01-16 10:28:06 +01:00
|
|
|
tableId: InternalTable.USER_METADATA,
|
2022-08-05 16:57:21 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-01-08 12:49:17 +01:00
|
|
|
async determineFeatureFlags() {
|
2022-08-05 16:57:21 +02:00
|
|
|
return {
|
|
|
|
supportsSearch: true,
|
|
|
|
supportsSort: false,
|
|
|
|
supportsPagination: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 17:40:32 +02:00
|
|
|
async getDefinition() {
|
2025-01-08 13:05:27 +01:00
|
|
|
return { schema: {} }
|
2022-08-08 17:40:32 +02:00
|
|
|
}
|
|
|
|
|
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-08 13:05:27 +01:00
|
|
|
const { appId, paginated, ...rest } = query
|
2025-01-07 11:17:42 +01:00
|
|
|
|
|
|
|
const finalQuery: SearchFilters = utils.isSupportedUserSearch(rest)
|
|
|
|
? rest
|
2025-01-10 16:39:55 +01:00
|
|
|
: {}
|
2024-09-09 17:36:31 +02:00
|
|
|
|
2022-08-05 16:57:21 +02:00
|
|
|
try {
|
2025-01-07 11:17:42 +01:00
|
|
|
const opts: SearchUsersRequest = {
|
2025-01-02 15:55:50 +01:00
|
|
|
bookmark: cursor ?? undefined,
|
|
|
|
query: finalQuery ?? undefined,
|
2023-10-12 17:31:32 +02:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|