@eeplatform/nuxt-layer-common 1.7.48 → 1.7.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/composables/useMember.ts +63 -33
- package/middleware/02.member.ts +8 -4
- package/middleware/03.role.ts +4 -2
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +2 -2
- package/types/member.d.ts +9 -0
package/CHANGELOG.md
CHANGED
package/composables/useMember.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
export default function useMember() {
|
|
2
|
-
const
|
|
3
|
-
const page = useState("page", () => 1);
|
|
4
|
-
const pages = useState("pages", () => 0);
|
|
5
|
-
const pageRange = useState("pageRange", () => "-- - -- of --");
|
|
6
|
-
|
|
7
|
-
const member = useState<TMember>("member", () => ({
|
|
8
|
-
_id: "",
|
|
2
|
+
const member = ref<TMember>({
|
|
9
3
|
org: "",
|
|
10
4
|
orgName: "",
|
|
11
|
-
roleName: "",
|
|
12
5
|
name: "",
|
|
13
6
|
user: "",
|
|
14
7
|
role: "",
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const invitation = ref<TMemberInvitation>({
|
|
11
|
+
_id: "",
|
|
12
|
+
email: "",
|
|
13
|
+
app: "",
|
|
14
|
+
org: "",
|
|
15
|
+
role: "",
|
|
16
|
+
});
|
|
23
17
|
|
|
24
18
|
function getByUserId(user: string) {
|
|
25
19
|
return useNuxtApp().$api<TMember>(`/api/members/user/${user}`);
|
|
@@ -32,18 +26,41 @@ export default function useMember() {
|
|
|
32
26
|
});
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
function getByApp({ app = "", user = "", org = "" } = {}) {
|
|
30
|
+
return useNuxtApp().$api<TMember>(`/api/members/app/${app}/user/${user}`, {
|
|
31
|
+
method: "GET",
|
|
32
|
+
query: { org },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getAllByAppUser({
|
|
37
|
+
app = "",
|
|
38
|
+
user = "",
|
|
39
|
+
limit = 10,
|
|
40
|
+
page = 1,
|
|
41
|
+
search = "",
|
|
42
|
+
} = {}) {
|
|
43
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
44
|
+
`/api/members/orgs/app/${app}/user/${user}`,
|
|
45
|
+
{
|
|
46
|
+
method: "GET",
|
|
47
|
+
query: { page, limit, search },
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
35
52
|
async function getAll({
|
|
36
53
|
page = 1,
|
|
37
54
|
search = "",
|
|
38
55
|
limit = 10,
|
|
39
56
|
user = "",
|
|
40
57
|
org = "",
|
|
41
|
-
|
|
58
|
+
app = "",
|
|
42
59
|
status = "active",
|
|
43
60
|
} = {}) {
|
|
44
|
-
return useNuxtApp().$api<Record<string, any>>(
|
|
61
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/members/app/${app}`, {
|
|
45
62
|
method: "GET",
|
|
46
|
-
query: { page, limit, search, user, org,
|
|
63
|
+
query: { page, limit, search, user, org, status },
|
|
47
64
|
});
|
|
48
65
|
}
|
|
49
66
|
function createUserByVerification(
|
|
@@ -76,32 +93,45 @@ export default function useMember() {
|
|
|
76
93
|
);
|
|
77
94
|
}
|
|
78
95
|
|
|
79
|
-
function
|
|
80
|
-
id: string,
|
|
81
|
-
role: string,
|
|
82
|
-
type: string,
|
|
83
|
-
org: string
|
|
84
|
-
) {
|
|
96
|
+
function updateRoleById(id: string, role: string) {
|
|
85
97
|
return useNuxtApp().$api<Record<string, any>>(
|
|
86
|
-
`/api/members/id/${id}
|
|
98
|
+
`/api/members/role/id/${id}`,
|
|
87
99
|
{
|
|
88
|
-
method: "
|
|
100
|
+
method: "PATCH",
|
|
101
|
+
body: { role },
|
|
89
102
|
}
|
|
90
103
|
);
|
|
91
104
|
}
|
|
105
|
+
|
|
106
|
+
function updateStatusById(id: string, status: string) {
|
|
107
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
108
|
+
`/api/members/status/id/${id}`,
|
|
109
|
+
{
|
|
110
|
+
method: "PATCH",
|
|
111
|
+
body: { status },
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function deleteById(id: string) {
|
|
117
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/members/id/${id}`, {
|
|
118
|
+
method: "DELETE",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
92
122
|
return {
|
|
93
|
-
members,
|
|
94
123
|
member,
|
|
95
|
-
|
|
96
|
-
pages,
|
|
97
|
-
pageRange,
|
|
98
|
-
|
|
124
|
+
invitation,
|
|
99
125
|
getAll,
|
|
100
126
|
getByUserId,
|
|
101
127
|
createUserByVerification,
|
|
102
128
|
createMemberInvite,
|
|
103
129
|
getByUserType,
|
|
130
|
+
getByApp,
|
|
104
131
|
updateMemberStatus,
|
|
105
|
-
|
|
132
|
+
updateRoleById,
|
|
133
|
+
updateStatusById,
|
|
134
|
+
deleteById,
|
|
135
|
+
getAllByAppUser,
|
|
106
136
|
};
|
|
107
137
|
}
|
package/middleware/02.member.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
export default defineNuxtRouteMiddleware(async () => {
|
|
1
|
+
export default defineNuxtRouteMiddleware(async (to) => {
|
|
2
2
|
// Ensure middleware runs only on the client side
|
|
3
3
|
if (import.meta.server) return;
|
|
4
4
|
|
|
5
5
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
6
|
+
const APP = useRuntimeConfig().public.APP;
|
|
7
|
+
const org = (to.params.org as string) ?? "";
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
console.log(APP);
|
|
8
10
|
|
|
9
|
-
const {
|
|
11
|
+
const { loggedInUser } = useLocalAuth();
|
|
12
|
+
|
|
13
|
+
const { getByApp } = useMember();
|
|
10
14
|
try {
|
|
11
|
-
const memberData = await
|
|
15
|
+
const memberData = await getByApp({ app: APP, user: loggedInUser(), org });
|
|
12
16
|
if (memberData.role) {
|
|
13
17
|
useCookie("role", cookieConfig).value = memberData.role;
|
|
14
18
|
}
|
package/middleware/03.role.ts
CHANGED
|
@@ -4,7 +4,7 @@ export default defineNuxtRouteMiddleware(async () => {
|
|
|
4
4
|
|
|
5
5
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { getById } = useRole();
|
|
8
8
|
const role = useCookie("role", cookieConfig).value ?? "";
|
|
9
9
|
if (!role) {
|
|
10
10
|
navigateTo({ name: "require-role" });
|
|
@@ -12,9 +12,11 @@ export default defineNuxtRouteMiddleware(async () => {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const { userAppRole } = useLocalSetup();
|
|
15
|
+
const { permissions } = useLocalAuth();
|
|
15
16
|
|
|
16
17
|
try {
|
|
17
|
-
const roleData = await
|
|
18
|
+
const roleData = await getById(role);
|
|
19
|
+
permissions.value.push(...roleData.permissions);
|
|
18
20
|
userAppRole.value = roleData;
|
|
19
21
|
} catch (error) {
|
|
20
22
|
navigateTo({ name: "require-role" });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default defineNuxtPlugin(() => {
|
|
2
2
|
const router = useRouter();
|
|
3
3
|
const { getByUserType } = useMember();
|
|
4
|
-
const {
|
|
4
|
+
const { getById } = useRole();
|
|
5
5
|
|
|
6
6
|
const { userAppRole, id } = useLocalSetup();
|
|
7
7
|
|
|
@@ -38,7 +38,7 @@ export default defineNuxtPlugin(() => {
|
|
|
38
38
|
|
|
39
39
|
const { data: getRoleByIdReq } = useLazyAsyncData(
|
|
40
40
|
"get-role-by-id",
|
|
41
|
-
() =>
|
|
41
|
+
() => getById(roleId.value),
|
|
42
42
|
{ watch: [roleId], immediate: false }
|
|
43
43
|
);
|
|
44
44
|
|
package/types/member.d.ts
CHANGED
|
@@ -5,8 +5,17 @@ declare type TMember = {
|
|
|
5
5
|
name: string;
|
|
6
6
|
user: string;
|
|
7
7
|
role: string;
|
|
8
|
+
roleName?: string;
|
|
8
9
|
status?: string;
|
|
9
10
|
createdAt?: string;
|
|
10
11
|
updatedAt?: string;
|
|
11
12
|
deletedAt?: string;
|
|
12
13
|
};
|
|
14
|
+
|
|
15
|
+
declare type TMemberInvitation = {
|
|
16
|
+
_id?: string;
|
|
17
|
+
email: string;
|
|
18
|
+
app: string;
|
|
19
|
+
org: string;
|
|
20
|
+
role: string;
|
|
21
|
+
};
|