diff --git a/packages/builder/src/stores/builder/queries.js b/packages/builder/src/stores/builder/queries.js index a3c599785d..27607deff5 100644 --- a/packages/builder/src/stores/builder/queries.js +++ b/packages/builder/src/stores/builder/queries.js @@ -84,10 +84,7 @@ export function createQueriesStore() { } const deleteQuery = async query => { - await API.deleteQuery({ - queryId: query?._id, - queryRev: query?._rev, - }) + await API.deleteQuery(query._id, query._rev) store.update(state => { state.list = state.list.filter(existing => existing._id !== query._id) return state diff --git a/packages/builder/src/stores/builder/roles.js b/packages/builder/src/stores/builder/roles.js index fd3581f1d4..4d5e37434a 100644 --- a/packages/builder/src/stores/builder/roles.js +++ b/packages/builder/src/stores/builder/roles.js @@ -43,10 +43,7 @@ export function createRolesStore() { setRoles(roles) }, delete: async role => { - await API.deleteRole({ - roleId: role?._id, - roleRev: role?._rev, - }) + await API.deleteRole(role._id, role._rev) await actions.fetch() }, save: async role => { diff --git a/packages/frontend-core/src/api/roles.js b/packages/frontend-core/src/api/roles.ts similarity index 50% rename from packages/frontend-core/src/api/roles.js rename to packages/frontend-core/src/api/roles.ts index 80b8028c12..6a68706271 100644 --- a/packages/frontend-core/src/api/roles.js +++ b/packages/frontend-core/src/api/roles.ts @@ -1,12 +1,29 @@ -export const buildRoleEndpoints = API => ({ +import { + AccessibleRolesResponse, + DestroyRoleResponse, + FetchRolesResponse, + SaveRoleRequest, + SaveRoleResponse, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface RoleEndpoints { + deleteRole: (id: string, rev: string) => Promise + saveRole: (role: SaveRoleRequest) => Promise + getRoles: () => Promise + getRolesForApp: (appId: string) => Promise + getAccessibleRoles: () => Promise +} + +export const buildRoleEndpoints = (API: BaseAPIClient): RoleEndpoints => ({ /** * Deletes a role. - * @param roleId the ID of the role to delete - * @param roleRev the rev of the role to delete + * @param id the ID of the role to delete + * @param rev the rev of the role to delete */ - deleteRole: async ({ roleId, roleRev }) => { + deleteRole: async (id, rev) => { return await API.delete({ - url: `/api/roles/${roleId}/${roleRev}`, + url: `/api/roles/${id}/${rev}`, }) }, diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 6d2088cfba..176e7f6a32 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -21,6 +21,7 @@ import { PermissionEndpoints } from "./permissions" import { PluginEndpoins } from "./plugins" import { QueryEndpoints } from "./queries" import { RelationshipEndpoints } from "./relationships" +import { RoleEndpoints } from "./roles" export enum HTTPMethod { POST = "POST", @@ -113,4 +114,5 @@ export type APIClient = BaseAPIClient & PermissionEndpoints & PluginEndpoins & QueryEndpoints & - RelationshipEndpoints & { [key: string]: any } + RelationshipEndpoints & + RoleEndpoints & { [key: string]: any }