refactor(role): rename PagePermission to RoleAccesses and fix base model id

Update type name from PagePermission to RoleAccesses across multiple files for consistency
Change mock id value from -1 to 0 in base model to match backend constraints
Enable RBAC middleware and fix patient edit page permissions
This commit is contained in:
Khafid Prayoga
2025-12-08 18:57:35 +07:00
parent 1083bb5384
commit e967ee1cf0
7 changed files with 26 additions and 29 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import type { RoleAccess } from '~/models/role'
import type { RoleAccesses } from '~/models/role'
export const PAGE_PERMISSIONS = {
'/client/patient': {
@@ -63,4 +63,4 @@ export const PAGE_PERMISSIONS = {
'emp|pay': ['R'],
'emp|mng': ['R'],
},
} as const satisfies Record<string, RoleAccess>
} as const satisfies Record<string, RoleAccesses>
+1 -3
View File
@@ -19,9 +19,7 @@ export interface TreeItem {
export function genBase(): Base {
return {
// -1 buat mock data
// backend harusnya non-negative/ > 0 (untuk auto increment constraint) jadi harusnya aman ya
id: -1,
id: 0,
createdAt: '',
updatedAt: '',
}
+3 -3
View File
@@ -43,9 +43,9 @@ export interface Person extends Base {
export function genPerson(): Person {
return {
...genBase(),
frontTitle: '[MOCK] dr. ',
name: 'Agus Iwan Setiawan',
endTitle: 'Sp.Bo',
frontTitle: '',
name: '',
endTitle: '',
}
}
@@ -1,12 +1,12 @@
<script setup lang="ts">
// import type { PagePermission } from '~/models/role'
import type { RoleAccesses } from '~/models/role'
import Error from '~/components/pub/my-ui/error/error.vue'
// import { PAGE_PERMISSIONS } from '~/lib/page-permission'
import { PAGE_PERMISSIONS } from '~/lib/page-permission'
definePageMeta({
// middleware: ['rbac'],
middleware: ['rbac'],
roles: ['doctor', 'nurse', 'admisi', 'pharmacy', 'billing', 'management'],
title: 'Daftar Divisi',
title: 'Edit Pasien',
contentFrame: 'cf-full-width',
})
@@ -16,19 +16,18 @@ useHead({
title: () => route.meta.title as string,
})
// const roleAccess: PagePermission = PAGE_PERMISSIONS['/patient']
const roleAccess: RoleAccesses = PAGE_PERMISSIONS['/client/patient']
// const { checkRole, hasReadAccess } = useRBAC()
const { checkRole, hasReadAccess } = useRBAC()
// // Check if user has access to this page
// const hasAccess = checkRole(roleAccess)
// if (!hasAccess) {
// navigateTo('/403')
// }
// Check if user has access to this page
const hasAccess = checkRole(roleAccess)
if (!hasAccess) {
navigateTo('/403')
}
// Define permission-based computed properties
// const canRead = hasReadAccess(roleAccess)
const canRead = true
const canRead = hasReadAccess(roleAccess)
</script>
<template>
@@ -36,7 +35,7 @@ const canRead = true
<div v-if="canRead">
<ContentPatientForm
:mode="'edit'"
:patient-id="route.params.id"
:patient-id="route.params.id as string"
/>
</div>
<Error
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { PagePermission } from '~/models/role'
import type { RoleAccesses } from '~/models/role'
import Error from '~/components/pub/my-ui/error/error.vue'
import { PAGE_PERMISSIONS } from '~/lib/page-permission'
@@ -16,7 +16,7 @@ useHead({
title: () => route.meta.title as string,
})
const roleAccess: PagePermission = PAGE_PERMISSIONS['/patient']
const roleAccess: RoleAccesses = PAGE_PERMISSIONS['/client/patient']
const { checkRole, hasReadAccess } = useRBAC()
+2 -2
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { PagePermission } from '~/models/role'
import type { RoleAccesses } from '~/models/role'
import Error from '~/components/pub/my-ui/error/error.vue'
import { PAGE_PERMISSIONS } from '~/lib/page-permission'
@@ -16,7 +16,7 @@ useHead({
title: () => route.meta.title as string,
})
const roleAccess: PagePermission = PAGE_PERMISSIONS['/patient']
const roleAccess: RoleAccesses = PAGE_PERMISSIONS['/client/patient']
const { checkRole, hasReadAccess } = useRBAC()
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { PagePermission } from '~/models/role'
import type { RoleAccesses } from '~/models/role'
import Error from '~/components/pub/my-ui/error/error.vue'
import { PAGE_PERMISSIONS } from '~/lib/page-permission'
@@ -16,8 +16,8 @@ useHead({
title: () => route.meta.title as string,
})
const roleAccess: PagePermission = PAGE_PERMISSIONS['/patient']
const roleAccess: RoleAccesses = PAGE_PERMISSIONS['/client/patient']
console.log(roleAccess)
const { checkRole, hasReadAccess } = useRBAC()
// Check if user has access to this page