Fix userFetch query
This commit is contained in:
parent
8d74833873
commit
c52dd56872
|
@ -2,11 +2,30 @@ import { get } from "svelte/store"
|
||||||
import DataFetch from "./DataFetch"
|
import DataFetch from "./DataFetch"
|
||||||
import { TableNames } from "../constants"
|
import { TableNames } from "../constants"
|
||||||
import { utils } from "@budibase/shared-core"
|
import { utils } from "@budibase/shared-core"
|
||||||
import { BasicOperator, Table } from "@budibase/types"
|
import {
|
||||||
|
BasicOperator,
|
||||||
|
SearchFilters,
|
||||||
|
SearchUsersRequest,
|
||||||
|
Table,
|
||||||
|
} from "@budibase/types"
|
||||||
import { APIClient } from "../api/types.js"
|
import { APIClient } from "../api/types.js"
|
||||||
|
|
||||||
export default class UserFetch extends DataFetch<{ tableId: string }, {}> {
|
interface UserFetchQuery {
|
||||||
constructor(opts: { API: APIClient; datasource: Table; options?: {} }) {
|
appId: string
|
||||||
|
paginated: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class UserFetch extends DataFetch<
|
||||||
|
{ tableId: string },
|
||||||
|
{},
|
||||||
|
UserFetchQuery
|
||||||
|
> {
|
||||||
|
constructor(opts: {
|
||||||
|
API: APIClient
|
||||||
|
datasource: Table
|
||||||
|
options?: {}
|
||||||
|
query: UserFetchQuery
|
||||||
|
}) {
|
||||||
super({
|
super({
|
||||||
...opts,
|
...opts,
|
||||||
datasource: {
|
datasource: {
|
||||||
|
@ -38,13 +57,14 @@ export default class UserFetch extends DataFetch<{ tableId: string }, {}> {
|
||||||
const { cursor, query } = get(this.store)
|
const { cursor, query } = get(this.store)
|
||||||
|
|
||||||
// Convert old format to new one - we now allow use of the lucene format
|
// Convert old format to new one - we now allow use of the lucene format
|
||||||
const { appId, paginated, ...rest } = query || ({} as any) // TODO
|
const { appId, paginated, ...rest } = query || {}
|
||||||
const finalQuery = utils.isSupportedUserSearch(rest)
|
|
||||||
? query
|
const finalQuery: SearchFilters = utils.isSupportedUserSearch(rest)
|
||||||
: { [BasicOperator.EMPTY]: { email: true } } // TODO: check
|
? rest
|
||||||
|
: { [BasicOperator.EMPTY]: { email: true } }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const opts = {
|
const opts: SearchUsersRequest = {
|
||||||
bookmark: cursor ?? undefined,
|
bookmark: cursor ?? undefined,
|
||||||
query: finalQuery ?? undefined,
|
query: finalQuery ?? undefined,
|
||||||
appId: appId,
|
appId: appId,
|
||||||
|
|
|
@ -109,7 +109,9 @@ export function trimOtherProps(object: any, allowedProps: string[]) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isSupportedUserSearch(query: SearchFilters) {
|
export function isSupportedUserSearch(
|
||||||
|
query: SearchFilters
|
||||||
|
): query is SearchFilters {
|
||||||
const allowed = [
|
const allowed = [
|
||||||
{ op: BasicOperator.STRING, key: "email" },
|
{ op: BasicOperator.STRING, key: "email" },
|
||||||
{ op: BasicOperator.EQUAL, key: "_id" },
|
{ op: BasicOperator.EQUAL, key: "_id" },
|
||||||
|
|
Loading…
Reference in New Issue