Type role endpoints

This commit is contained in:
Andrew Kingston 2024-12-03 10:20:05 +00:00
parent e938fddeed
commit 2a7c0ca276
No known key found for this signature in database
4 changed files with 27 additions and 14 deletions

View File

@ -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

View File

@ -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 => {

View File

@ -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<DestroyRoleResponse>
saveRole: (role: SaveRoleRequest) => Promise<SaveRoleResponse>
getRoles: () => Promise<FetchRolesResponse>
getRolesForApp: (appId: string) => Promise<any>
getAccessibleRoles: () => Promise<AccessibleRolesResponse>
}
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}`,
})
},

View File

@ -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 }