Files
JayuCloud/YumiNail-Frontend/src/api/permission.ts
T

104 lines
4.2 KiB
TypeScript
Raw Normal View History

/**
* Front-end API wrapper for this module.
* Call guide: import the named API object, then call the matching method from a Vue page or composable.
*/
import { adminApi } from './admin'
2026-03-27 14:55:41 +08:00
import type { IdType } from '@/utils/id'
2026-02-25 10:37:16 +08:00
export interface PermissionVO {
2026-03-27 14:55:41 +08:00
id: IdType
2026-02-25 10:37:16 +08:00
permissionCode: string
permissionName: string
permissionGroup: string
description: string
createTime: string
updateTime: string
}
export interface CreatePermissionRequest {
permissionCode: string
permissionName: string
permissionGroup: string
description: string
}
export interface UpdatePermissionRequest {
permissionCode?: string
permissionName?: string
permissionGroup?: string
description?: string
}
/**
* permissionApi groups all API calls for this page domain.
* Call guide: pass the typed payload or identifier into the method below, and use the returned Promise in the page script.
*/
2026-02-25 10:37:16 +08:00
export const permissionApi = {
/**
* `getUserPermissions` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param userId?: IdType caller-supplied value for `userId?: IdType`
*/
2026-03-27 14:55:41 +08:00
getUserPermissions: (userId?: IdType) => {
2026-02-25 10:37:16 +08:00
if (userId) {
return adminApi.get<PermissionVO[]>(`/permission/user/${userId}`)
2026-02-25 10:37:16 +08:00
}
return adminApi.get<PermissionVO[]>('/permission/user/current')
2026-02-25 10:37:16 +08:00
},
/**
* `getAssignablePermissionIds` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param userId: IdType caller-supplied value for `userId: IdType`
*/
2026-03-27 14:55:41 +08:00
getAssignablePermissionIds: (userId: IdType) => {
return adminApi.get<IdType[]>(`/permission/assignable/${userId}`)
},
/**
* `listAllPermissions` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
*/
2026-02-25 10:37:16 +08:00
listAllPermissions: () => {
return adminApi.get<PermissionVO[]>('/permission/list/all')
2026-02-25 10:37:16 +08:00
},
/**
* `createPermission` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: CreatePermissionRequest caller-supplied value for `data: CreatePermissionRequest`
*/
2026-02-25 10:37:16 +08:00
createPermission: (data: CreatePermissionRequest) => {
return adminApi.post('/permission/create', data)
2026-02-25 10:37:16 +08:00
},
/**
* `updatePermission` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param id: IdType caller-supplied value for `id: IdType`
* @param data: UpdatePermissionRequest caller-supplied value for `data: UpdatePermissionRequest`
*/
2026-03-27 14:55:41 +08:00
updatePermission: (id: IdType, data: UpdatePermissionRequest) => {
return adminApi.put(`/permission/update/${id}`, data)
2026-02-25 10:37:16 +08:00
},
/**
* `deletePermission` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param id: IdType caller-supplied value for `id: IdType`
*/
2026-03-27 14:55:41 +08:00
deletePermission: (id: IdType) => {
return adminApi.delete(`/permission/delete/${id}`)
2026-02-25 10:37:16 +08:00
},
/**
* `assignUserPermissions` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param userId: IdType caller-supplied value for `userId: IdType`
* @param permissionIds: IdType[] caller-supplied value for `permissionIds: IdType[]`
*/
2026-03-27 14:55:41 +08:00
assignUserPermissions: (userId: IdType, permissionIds: IdType[]) => {
return adminApi.post(`/permission/assign/${userId}`, { permissionIds })
2026-02-25 10:37:16 +08:00
}
}