@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 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
@@ -202,6 +202,7 @@ function setRole({
202
202
  )
203
203
  );
204
204
  modeRole.value = mode;
205
+ message.value = "";
205
206
 
206
207
  if (modeRole.value === "add") {
207
208
  dialogAdd.value = dialog;
@@ -19,7 +19,7 @@ export function useLocalSetup(type: string, org?: string) {
19
19
  }
20
20
  });
21
21
 
22
- const { getRoleById } = useRole();
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: getRoleByIdReq } = useLazyAsyncData(
31
+ const { data: getByIdReq } = useLazyAsyncData(
32
32
  "get-role-by-id",
33
- () => getRoleById(roleId.value),
33
+ () => getById(roleId.value),
34
34
  { watch: [roleId], immediate: false }
35
35
  );
36
36
 
37
37
  watchEffect(() => {
38
- if (getRoleByIdReq.value) {
39
- userAppRole.value = getRoleByIdReq.value;
38
+ if (getByIdReq.value) {
39
+ userAppRole.value = getByIdReq.value;
40
40
  }
41
41
  });
42
42
 
@@ -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
- busInst: "",
37
- type: "",
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
@@ -2,7 +2,7 @@
2
2
  "name": "@goweekdays/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.2.5",
5
+ "version": "1.3.0",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -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
- refreshUserMemberData();
28
- }
17
+ try {
18
+ const member = await getByUserType(userId, APP, org);
19
+ membership.value = member;
29
20
 
30
- watchEffect(() => {
31
- if (userMemberError.value) {
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
  });
@@ -13,22 +13,10 @@ export default defineNuxtPlugin(() => {
13
13
  return;
14
14
  }
15
15
 
16
- const { data: getCurrentUserReq, error: getCurrentUserErr } =
17
- await useLazyAsyncData("get-current-user", () =>
18
- $fetch<TUser>(`/api/users/id/${user}`)
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
- email: string;
5
- contact: string;
6
- busInst: string;
7
- type: string;
8
- apps?: Array<string>;
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
  };