@goweekdays/layer-common 1.2.5 → 1.3.0
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 +12 -0
- package/components/RolePermissionMain.vue +1 -0
- package/composables/useLocalSetup.ts +5 -5
- package/composables/useOrg.ts +11 -59
- package/package.json +1 -1
- package/plugins/member.client.ts +7 -43
- package/plugins/secure.client.ts +5 -17
- package/types/org.d.ts +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @goweekdays/layer-common
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 598fcf3: Refactor org and member logic, update TOrg type
|
|
8
|
+
|
|
9
|
+
## 1.2.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bcdc6ba: Fix setRole() to clear message
|
|
14
|
+
|
|
3
15
|
## 1.2.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -19,7 +19,7 @@ export function useLocalSetup(type: string, org?: string) {
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
const {
|
|
22
|
+
const { getById } = useRole();
|
|
23
23
|
|
|
24
24
|
const roleId = computed(() => userMemberData.value?.role ?? "");
|
|
25
25
|
|
|
@@ -28,15 +28,15 @@ export function useLocalSetup(type: string, org?: string) {
|
|
|
28
28
|
() => null
|
|
29
29
|
);
|
|
30
30
|
|
|
31
|
-
const { data:
|
|
31
|
+
const { data: getByIdReq } = useLazyAsyncData(
|
|
32
32
|
"get-role-by-id",
|
|
33
|
-
() =>
|
|
33
|
+
() => getById(roleId.value),
|
|
34
34
|
{ watch: [roleId], immediate: false }
|
|
35
35
|
);
|
|
36
36
|
|
|
37
37
|
watchEffect(() => {
|
|
38
|
-
if (
|
|
39
|
-
userAppRole.value =
|
|
38
|
+
if (getByIdReq.value) {
|
|
39
|
+
userAppRole.value = getByIdReq.value;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
package/composables/useOrg.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export default function useOrg() {
|
|
2
|
+
function add(value: Pick<TOrg, "name" | "email" | "contact" | "createdBy">) {
|
|
3
|
+
return $fetch<Record<string, any>>("/api/organizations", {
|
|
4
|
+
method: "POST",
|
|
5
|
+
body: value,
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
function getAll({ page = 1, search = "", limit = 20, status = "" } = {}) {
|
|
3
10
|
return $fetch<Record<string, any>>("/api/organizations", {
|
|
4
11
|
method: "GET",
|
|
@@ -28,73 +35,18 @@ export default function useOrg() {
|
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
37
|
|
|
31
|
-
const org = ref({
|
|
32
|
-
_id: "",
|
|
38
|
+
const org = ref<TOrg>({
|
|
33
39
|
name: "",
|
|
34
|
-
email: "",
|
|
35
40
|
contact: "",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
status: "",
|
|
41
|
+
email: "",
|
|
42
|
+
createdBy: "",
|
|
39
43
|
});
|
|
40
44
|
|
|
41
|
-
function reset() {
|
|
42
|
-
org.value._id = "";
|
|
43
|
-
org.value.name = "";
|
|
44
|
-
org.value.email = "";
|
|
45
|
-
org.value.contact = "";
|
|
46
|
-
org.value.busInst = "";
|
|
47
|
-
org.value.type = "";
|
|
48
|
-
org.value.status = "";
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function set({
|
|
52
|
-
_id = "",
|
|
53
|
-
name = "",
|
|
54
|
-
email = "",
|
|
55
|
-
contact = "",
|
|
56
|
-
busInst = "",
|
|
57
|
-
type = "",
|
|
58
|
-
status = "",
|
|
59
|
-
} = {}) {
|
|
60
|
-
org.value._id = _id;
|
|
61
|
-
org.value.name = name;
|
|
62
|
-
org.value.email = email;
|
|
63
|
-
org.value.contact = contact;
|
|
64
|
-
org.value.busInst = busInst;
|
|
65
|
-
org.value.type = type;
|
|
66
|
-
org.value.status = status;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const perSeatPrice = 300;
|
|
70
|
-
const seats = useState("seats", () => 1);
|
|
71
|
-
const total = computed(() => seats.value * perSeatPrice);
|
|
72
|
-
|
|
73
|
-
function getByName(name = "") {
|
|
74
|
-
return $fetch<TOrg>(`/api/organizations/name/${name}`, {
|
|
75
|
-
method: "GET",
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { currentUser } = useLocalAuth();
|
|
80
|
-
|
|
81
|
-
const currentOrg = computed(
|
|
82
|
-
() =>
|
|
83
|
-
(useRoute().params.organization as string) ||
|
|
84
|
-
currentUser.value?.defaultOrg
|
|
85
|
-
);
|
|
86
|
-
|
|
87
45
|
return {
|
|
88
46
|
org,
|
|
47
|
+
add,
|
|
89
48
|
getAll,
|
|
90
49
|
getByUserId,
|
|
91
|
-
reset,
|
|
92
|
-
set,
|
|
93
|
-
perSeatPrice,
|
|
94
|
-
seats,
|
|
95
|
-
total,
|
|
96
|
-
getByName,
|
|
97
|
-
currentOrg,
|
|
98
50
|
getById,
|
|
99
51
|
};
|
|
100
52
|
}
|
package/package.json
CHANGED
package/plugins/member.client.ts
CHANGED
|
@@ -13,54 +13,18 @@ export default defineNuxtPlugin(() => {
|
|
|
13
13
|
|
|
14
14
|
const userId = useCookie("user").value ?? "";
|
|
15
15
|
|
|
16
|
-
const {
|
|
17
|
-
data: userMemberData,
|
|
18
|
-
error: userMemberError,
|
|
19
|
-
refresh: refreshUserMemberData,
|
|
20
|
-
} = await useLazyAsyncData(
|
|
21
|
-
"plugin-get-member-by-id" + userId,
|
|
22
|
-
() => getByUserType(userId, APP, org),
|
|
23
|
-
{ immediate: false }
|
|
24
|
-
);
|
|
25
|
-
|
|
26
16
|
if (!membership.value) {
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
try {
|
|
18
|
+
const member = await getByUserType(userId, APP, org);
|
|
19
|
+
membership.value = member;
|
|
29
20
|
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
const role = await getRoleById(member.role);
|
|
22
|
+
permissions.value = role.permissions ?? [];
|
|
23
|
+
} catch (error) {
|
|
32
24
|
navigateTo({
|
|
33
25
|
name: "index",
|
|
34
26
|
});
|
|
35
27
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
watchEffect(() => {
|
|
39
|
-
if (userMemberData.value) {
|
|
40
|
-
membership.value = userMemberData.value;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const roleId = computed(() => membership.value?.role ?? "");
|
|
45
|
-
|
|
46
|
-
const { data: roleData, refresh: refreshRoleData } = await useLazyAsyncData(
|
|
47
|
-
"plugin-get-role-by-id" + roleId.value,
|
|
48
|
-
() => getRoleById(roleId.value),
|
|
49
|
-
{ immediate: false }
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
watchEffect(() => {
|
|
53
|
-
if (roleId.value) {
|
|
54
|
-
if (!permissions.value.length) {
|
|
55
|
-
refreshRoleData();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
watchEffect(() => {
|
|
61
|
-
if (roleData.value) {
|
|
62
|
-
permissions.value = roleData.value.permissions ?? [];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
28
|
+
}
|
|
65
29
|
});
|
|
66
30
|
});
|
package/plugins/secure.client.ts
CHANGED
|
@@ -13,22 +13,10 @@ export default defineNuxtPlugin(() => {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
await
|
|
18
|
-
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
watchEffect(() => {
|
|
22
|
-
if (getCurrentUserReq.value) {
|
|
23
|
-
currentUser.value = getCurrentUserReq.value;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
watchEffect(() => {
|
|
28
|
-
if (getCurrentUserErr.value) {
|
|
29
|
-
// Redirect to login page if user authentication fails
|
|
30
|
-
navigateTo({ name: "index" });
|
|
31
|
-
}
|
|
32
|
-
});
|
|
16
|
+
try {
|
|
17
|
+
currentUser.value = await $fetch<TUser>(`/api/users/id/${user}`);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
navigateTo({ name: "index" });
|
|
20
|
+
}
|
|
33
21
|
});
|
|
34
22
|
});
|
package/types/org.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
declare type TOrg = {
|
|
2
2
|
_id?: string;
|
|
3
3
|
name: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
description?: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
contact?: string;
|
|
7
|
+
createdBy: string;
|
|
8
|
+
status?: string;
|
|
9
9
|
createdAt?: string;
|
|
10
10
|
updatedAt?: string;
|
|
11
|
-
status?: string;
|
|
12
11
|
deletedAt?: string;
|
|
13
12
|
};
|