Skip to content

Commit 28e1de4

Browse files
committed
chore: refactor roles and permissions api
1 parent 6708d32 commit 28e1de4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1942
-1380
lines changed

app/@layouts/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { OffsetOptions } from '@floating-ui/dom'
22
import type { RouteLocationRaw } from 'vue-router'
33
import type { AppContentLayoutNav, ContentWidth, FooterType, HorizontalNavType, NavbarType } from '@base/@layouts/enums'
44
import type { Component } from 'vue'
5-
import type { Actions } from '~/stores/casl'
5+
import type { Actions } from '@base/stores/casl'
66

77
export interface LayoutConfig {
88
app: {

app/components/organizations/OrganizationDrawer.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { cloneDeep } from 'lodash-es'
33
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
44
55
import type { VForm } from 'vuetify/components/VForm'
6-
import type { Organization } from '~/stores/admin/organization'
7-
import type { DialogConfig, DrawerConfig } from '~/utils/types'
6+
import type { Organization } from '@base/stores/admin/organization'
7+
import type { DialogConfig, DrawerConfig } from '@base/utils/types'
88
99
interface Emit {
1010
(e: 'update:isDrawerOpen', value: boolean): void

app/components/permissions/AddEditPermissionDialog.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<script setup lang="ts">
2-
import type { VForm } from 'vuetify/components/VForm'
3-
42
import type { sysPermissionTable } from '@base/server/db/schemas/sys_permissions.schema'
53
import type { InferSelectModel } from 'drizzle-orm'
6-
import { cloneDeep } from 'lodash-es'
7-
import { PermissionAction, PermissionScope } from '@base/server/db/schemas'
84
import { requiredValidator } from '#imports'
5+
import { PermissionAction, PermissionScope } from '@base/server/db/schemas'
6+
import { cloneDeep } from 'lodash-es'
97
108
type Permission = InferSelectModel<typeof sysPermissionTable>
119

app/components/roles/AddEditRoleDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { debounce, values } from 'lodash-es'
33
import { VForm } from 'vuetify/components/VForm'
44
import { usePermissionStore } from '@base/stores/admin/permission'
55
import type { Permission } from '@base/stores/admin/permission'
6-
import type { PivotRolePermission, RoleWithPermissions } from '~/stores/admin/role'
6+
import type { PivotRolePermission, RoleWithPermissions } from '@base/stores/admin/role'
77
import { requiredValidator } from '#imports'
88
99
const props = defineProps<{

app/components/users/UserDrawer.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { cloneDeep } from 'lodash-es'
33
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
44
55
import type { VForm } from 'vuetify/components/VForm'
6-
import { type Organization, useOrganizationStore } from '~/stores/admin/organization'
7-
import { useRoleStore } from '~/stores/admin/role'
8-
import type { User } from '~/stores/admin/user'
9-
import type { DialogConfig, DrawerConfig } from '~/utils/types'
6+
import { type Organization, useOrganizationStore } from '@base/stores/admin/organization'
7+
import { useRoleStore } from '@base/stores/admin/role'
8+
import type { User } from '@base/stores/admin/user'
9+
import type { DialogConfig, DrawerConfig } from '@base/utils/types'
1010
1111
interface Emit {
1212
(e: 'update:isDrawerOpen', value: boolean): void

app/pages/admin/organizations.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import AddNewUserDrawer from '~/components/users/UserDrawer.vue'
2+
import AddNewUserDrawer from '@base/components/users/UserDrawer.vue'
33
44
definePageMeta({
55
action: 'manage',

app/pages/admin/permissions.vue

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ function resetQuery() {
3232
const { data: permissionData, status: permissionStatus, refresh: reFetchPermissions } = useLazyAsyncData(
3333
'permissions',
3434
() => permissionStore.fetchPermissions(formQuery.value),
35-
{
36-
watch: [formQuery],
37-
},
3835
)
3936
37+
watch(formQuery, () => {
38+
reFetchPermissions()
39+
}, { deep: true })
40+
4041
const permissionSelected = ref<Permission | null>(null)
4142
4243
const headers = [
@@ -52,17 +53,31 @@ function handleUpdateOptions(options: any) {
5253
5354
const dialogVisible = ref(false)
5455
55-
function handleEditPermission(permission: Permission) {
56+
async function handleAddPermission() {
57+
permissionSelected.value = null
58+
59+
await nextTick()
60+
61+
dialogVisible.value = true
62+
}
63+
64+
async function handleEditPermission(permission: Permission) {
5665
permissionSelected.value = permission
66+
67+
await nextTick()
68+
5769
dialogVisible.value = true
5870
}
5971
6072
async function handleSubmitEdit(permission: Permission) {
6173
await permissionStore.updatePermission(permission.id, permission)
6274
63-
permissionSelected.value = null
6475
dialogVisible.value = false
6576
77+
await nextTick()
78+
79+
permissionSelected.value = null
80+
6681
notifySuccess({
6782
content: t('Permission updated successfully'),
6883
})
@@ -84,9 +99,12 @@ async function handleSubmitCreate(permission: Permission) {
8499
await reFetchPermissions()
85100
}
86101
87-
function handleCancelEdit() {
88-
permissionSelected.value = null
102+
async function handleCancelEdit() {
89103
dialogVisible.value = false
104+
105+
await nextTick()
106+
107+
permissionSelected.value = null
90108
}
91109
92110
async function handleDeletePermission(permission: Permission) {
@@ -124,7 +142,7 @@ async function handleDeletePermission(permission: Permission) {
124142

125143
<VBtn
126144
density="default"
127-
@click="dialogVisible = true"
145+
@click="handleAddPermission"
128146
>
129147
Add Permission
130148
</VBtn>

app/pages/admin/roles.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import RoleCards from '@base/components/roles/RoleCards.vue'
33
import type { RoleWithPermissions } from '@base/stores/admin/role'
44
import { useRoleStore } from '@base/stores/admin/role'
5-
import { usePermissionStore } from '~/stores/admin/permission'
5+
import { usePermissionStore } from '@base/stores/admin/permission'
66
// import UserList from '@base/components/roles/UserList.vue'
77
88
definePageMeta({

app/pages/admin/users.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import AddNewUserDrawer from '~/components/users/UserDrawer.vue'
2+
import AddNewUserDrawer from '@base/components/users/UserDrawer.vue'
33
44
definePageMeta({
55
action: 'manage',

app/pages/test-organization.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { type Organization, useOrganizationStore } from '@base/stores/admin/organization'
3-
import { DRAWER_ACTION_TYPES } from '~/constant/organization'
4-
import type { DrawerConfig } from '~/utils/types'
5-
import type { DrawerActionTypes } from '~/utils/types/landing-page'
3+
import { DRAWER_ACTION_TYPES } from '@base/constant/organization'
4+
import type { DrawerConfig } from '@base/utils/types'
5+
import type { DrawerActionTypes } from '@base/utils/types/landing-page'
66
77
definePageMeta({
88
sidebar: {

app/pages/test-permission.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { type Permission, usePermissionStore } from '@base/stores/admin/permission'
3-
import { DRAWER_ACTION_TYPES } from '~/constant/organization'
4-
import type { DrawerActionTypes } from '~/utils/types'
3+
import { DRAWER_ACTION_TYPES } from '@base/constant/organization'
4+
import type { DrawerActionTypes } from '@base/utils/types'
55
66
definePageMeta({
77
sidebar: {

app/pages/test-role.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
2-
import { DRAWER_ACTION_TYPES } from '~/constant/organization'
3-
import { type Role, useRoleStore } from '~/stores/admin/role'
4-
import type { DrawerActionTypes } from '~/utils/types'
2+
import { DRAWER_ACTION_TYPES } from '@base/constant/organization'
3+
import { type Role, useRoleStore } from '@base/stores/admin/role'
4+
import type { DrawerActionTypes } from '@base/utils/types'
55
66
definePageMeta({
77
sidebar: {

app/pages/test-user.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { type User, useUserStore } from '@base/stores/admin/user'
33
import { type Role, useRoleStore } from '@base/stores/admin/role'
4-
import { DRAWER_ACTION_TYPES } from '~/constant/organization'
5-
import type { DrawerConfig } from '~/utils/types'
4+
import { DRAWER_ACTION_TYPES } from '@base/constant/organization'
5+
import type { DrawerConfig } from '@base/utils/types'
66
77
definePageMeta({
88
sidebar: {

app/stores/admin/permission.ts

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,35 @@ export interface PermissionWithRelations extends Permission {
1010

1111
export const usePermissionStore = defineStore('permission', () => {
1212
async function fetchPermissions(options?: { page: number, limit: number, keyword: string }) {
13-
try {
14-
return $api<{ total: number, data: Permission[] }>('/permissions', {
15-
query: options,
16-
})
17-
}
18-
catch (error) {
19-
console.error('Error fetching permissions:', error)
20-
}
13+
return $api<{ total: number, data: Permission[] }>('/permissions', {
14+
query: options,
15+
})
2116
}
2217

2318
async function fetchPermissionDetail(permissionId: string) {
24-
try {
25-
return $api(`/permissions/${permissionId}`, {
26-
method: 'GET',
27-
})
28-
}
29-
catch (error) {
30-
console.error('Error fetching permission detail:', error)
31-
}
19+
return $api(`/permissions/${permissionId}`, {
20+
method: 'GET',
21+
})
3222
}
3323

3424
async function createPermission(body: Permission) {
35-
try {
36-
return $api('/permissions', {
37-
method: 'POST',
38-
body: omit(body, ['id']),
39-
})
40-
}
41-
catch (error) {
42-
console.error('Error creating permission:', error)
43-
}
25+
return $api('/permissions', {
26+
method: 'POST',
27+
body: omit(body, ['id']),
28+
})
4429
}
4530

4631
async function updatePermission(permissionId: string, body: Partial<Permission>) {
47-
try {
48-
return $api(`/permissions/${permissionId}`, {
49-
method: 'PATCH',
50-
body,
51-
})
52-
}
53-
catch (error) {
54-
console.error('Error updating permission:', error)
55-
}
32+
return $api(`/permissions/${permissionId}`, {
33+
method: 'PATCH',
34+
body,
35+
})
5636
}
5737

5838
async function deletePermission(permissionId: string) {
59-
try {
60-
return $api(`/permissions/${permissionId}`, {
61-
method: 'DELETE',
62-
})
63-
}
64-
catch (error) {
65-
console.error('Error deleting permission:', error)
66-
}
39+
return $api(`/permissions/${permissionId}`, {
40+
method: 'DELETE',
41+
})
6742
}
6843

6944
return {

app/stores/admin/role.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { InferSelectModel } from 'drizzle-orm'
22
import type { sysRoleTable } from '@base/server/db/schemas/sys_roles.schema'
33
import type { ParsedFilterQuery } from '@base/server/utils/filter'
4+
import type { sysRolePermissionTable } from '@base/server/db/schemas'
45
import type { Permission } from './permission'
5-
import type { sysRolePermissionTable } from '~~/server/db/schemas'
66

77
export type Role = InferSelectModel<typeof sysRoleTable>
88

env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { Page } from 'puppeteer'
44
import type { NavGroupType, NavItem } from '@base/@layouts/types'
55
import type { z } from 'zod'
66
import type { HookResult } from '@nuxt/schema'
7+
import type { Actions } from '@base/stores/casl'
78
import type { sysUserTable } from './server/db/schemas'
8-
import type { Actions } from '~/stores/casl'
99

1010
declare module 'vue-router' {
1111
interface RouteMeta {

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@iconify/utils": "2.1.23",
7575
"@iconify/vue": "4.1.1",
7676
"@ngneat/falso": "^7.2.0",
77-
"@nuxt/eslint": "^0.5.7",
77+
"@nuxt/eslint": "^0.7.1",
7878
"@nuxt/fonts": "^0.9.2",
7979
"@nuxt/kit": "^3.13.2",
8080
"@nuxt/schema": "^3.13.2",
@@ -107,8 +107,6 @@
107107
"@types/pdfmake": "^0.2.9",
108108
"@types/uuid": "^8.3.3",
109109
"@types/webfontloader": "1.6.38",
110-
"@typescript-eslint/eslint-plugin": "7.7.1",
111-
"@typescript-eslint/parser": "7.7.1",
112110
"@videojs-player/vue": "1.0.0",
113111
"@vueuse/core": "10.9.0",
114112
"@vueuse/math": "10.9.0",
@@ -123,7 +121,7 @@
123121
"drizzle-kit": "^0.23.0",
124122
"drizzle-orm": "^0.32.0",
125123
"drizzle-zod": "^0.5.1",
126-
"eslint": "8.57.0",
124+
"eslint": "^9.15.0",
127125
"execa": "^9.3.0",
128126
"firebase": "^10.12.4",
129127
"firebase-admin": "^12.2.0",

packages/config/eslint/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thecodeorigin/eslint-config",
33
"type": "module",
4-
"version": "1.0.2",
4+
"version": "1.1.0",
55
"publishConfig": {
66
"registry": "https://npm.pkg.github.com/",
77
"access": "restricted"
@@ -17,7 +17,7 @@
1717
"main": "./index.mjs",
1818
"types": "./index.d.ts",
1919
"dependencies": {
20-
"@antfu/eslint-config": "^2.22.0",
20+
"@antfu/eslint-config": "^3.9.2",
2121
"@antfu/eslint-config-vue": "0.43.1"
2222
}
2323
}

0 commit comments

Comments
 (0)