@eeplatform/nuxt-layer-common 1.4.10 → 1.5.1

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
  # @eeplatform/nuxt-layer-common
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ab3086b: Fix school year generator utils
8
+
9
+ ## 1.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - cc493b1: Migrate from custom fetch to $fetch
14
+
3
15
  ## 1.4.10
4
16
 
5
17
  ### Patch Changes
@@ -1486,8 +1486,11 @@ const isSeniorHighSchool = computed(() => {
1486
1486
  return ["grade-11", "grade-12"].includes(gradeLevel);
1487
1487
  });
1488
1488
 
1489
- const effectiveSchoolYearOptions = generateSchoolYears();
1490
- const lastSchoolYearOptions = generateSchoolYears(50).reverse();
1489
+ const effectiveSchoolYearOptions = computed(() =>
1490
+ generateSchoolYears(0, "future")
1491
+ );
1492
+
1493
+ const lastSchoolYearOptions = generateSchoolYears(50);
1491
1494
 
1492
1495
  const indigenousCommunitiesPhilippines = [
1493
1496
  // Luzon (Northern Philippines) - Cordillera Groups (Igorot Subgroups)
@@ -1664,7 +1667,6 @@ watchEffect(() => {
1664
1667
  });
1665
1668
 
1666
1669
  import { useMask } from "vuetify";
1667
- import { fa } from "zod/v4/locales";
1668
1670
 
1669
1671
  watchEffect(() => {
1670
1672
  const mask = useMask({ mask: "##/##/####" });
@@ -65,7 +65,7 @@
65
65
  <script setup lang="ts">
66
66
  definePageMeta({
67
67
  middleware: ["01-auth", "org"],
68
- secured: true,
68
+ ,
69
69
  });
70
70
 
71
71
  const headers = [
@@ -13,7 +13,7 @@ export default function useAddress() {
13
13
  postalCode = "",
14
14
  taxId = "",
15
15
  } = {}) {
16
- return useNuxtApp().$api("/api/addresses", {
16
+ return $fetch("/api/addresses", {
17
17
  method: "POST",
18
18
  body: {
19
19
  type,
@@ -57,18 +57,18 @@ export default function useAddress() {
57
57
  payload.org = orgId;
58
58
  }
59
59
 
60
- return useNuxtApp().$api(`/api/addresses/details/${id}`, {
60
+ return $fetch(`/api/addresses/details/${id}`, {
61
61
  method: "PUT",
62
62
  body: payload,
63
63
  });
64
64
  }
65
65
 
66
66
  function getByUserId(user = "") {
67
- return useNuxtApp().$api<TAddress>(`/api/addresses/user/${user}`);
67
+ return $fetch<TAddress>(`/api/addresses/user/${user}`);
68
68
  }
69
69
 
70
70
  function getByOrgId(id = "") {
71
- return useNuxtApp().$api<TAddress>(`/api/addresses/org/${id}`);
71
+ return $fetch<TAddress>(`/api/addresses/org/${id}`);
72
72
  }
73
73
 
74
74
  const _address = useState("address", (): TAddress => {
@@ -114,12 +114,24 @@ export default function useBasicEdu() {
114
114
  },
115
115
  ];
116
116
 
117
- function generateSchoolYears(generation = 0) {
117
+ function generateSchoolYears(generation = 0, mode = "past") {
118
118
  const currentYear = new Date().getFullYear();
119
119
  const years = [];
120
- for (let i = currentYear - generation; i <= currentYear; i++) {
121
- years.push(`${i}-${i + 1}`);
120
+
121
+ if (mode === "past") {
122
+ // Generate from current year going back to past years
123
+ for (let i = 0; i <= generation; i++) {
124
+ const year = currentYear - i;
125
+ years.push(`${year}-${year + 1}`);
126
+ }
127
+ } else if (mode === "future") {
128
+ // Generate from current year going forward to future years
129
+ for (let i = 0; i <= generation; i++) {
130
+ const year = currentYear + i;
131
+ years.push(`${year}-${year + 1}`);
132
+ }
122
133
  }
134
+
123
135
  return years;
124
136
  }
125
137
 
@@ -7,7 +7,7 @@ export default function useChartOfAccount() {
7
7
  children?: number;
8
8
  }
9
9
  ) {
10
- return useNuxtApp().$api<Record<string, any>>("/api/chart-of-accounts", {
10
+ return $fetch<Record<string, any>>("/api/chart-of-accounts", {
11
11
  method: "GET",
12
12
  query: { page, status, orgId, children },
13
13
  });
@@ -23,33 +23,30 @@ export default function useChartOfAccount() {
23
23
  };
24
24
 
25
25
  function add(value: TAddPayload) {
26
- return useNuxtApp().$api<TAddPayload>("/api/chart-of-accounts", {
26
+ return $fetch<TAddPayload>("/api/chart-of-accounts", {
27
27
  method: "POST",
28
28
  body: value,
29
29
  });
30
30
  }
31
31
 
32
32
  function getById(id: string) {
33
- return useNuxtApp().$api<Record<string, any>>(
34
- `/api/chart-of-accounts/id/${id}`
35
- );
33
+ return $fetch<Record<string, any>>(`/api/chart-of-accounts/id/${id}`);
36
34
  }
37
35
 
38
36
  function updateById(
39
37
  id: string,
40
38
  value: Pick<TAddPayload, "name" | "code" | "normalBalance" | "parent">
41
39
  ) {
42
- return useNuxtApp().$api<TAddPayload>(`/api/chart-of-accounts/id/${id}`, {
40
+ return $fetch<TAddPayload>(`/api/chart-of-accounts/id/${id}`, {
43
41
  method: "PUT",
44
42
  body: value,
45
43
  });
46
44
  }
47
45
 
48
46
  function deleteById(id: string) {
49
- return useNuxtApp().$api<Record<string, any>>(
50
- `/api/chart-of-accounts/id/${id}`,
51
- { method: "DELETE" }
52
- );
47
+ return $fetch<Record<string, any>>(`/api/chart-of-accounts/id/${id}`, {
48
+ method: "DELETE",
49
+ });
53
50
  }
54
51
 
55
52
  return {
@@ -7,19 +7,16 @@ export default function useFile() {
7
7
  const formData = new FormData();
8
8
  formData.append("file", file);
9
9
 
10
- return useNuxtApp().$api<Record<string, any>>("/api/files", {
10
+ return $fetch<Record<string, any>>("/api/files", {
11
11
  method: "POST",
12
12
  body: formData,
13
13
  });
14
14
  }
15
15
 
16
16
  function deleteFile(attachmentId: string) {
17
- return useNuxtApp().$api<Record<string, any>>(
18
- `/api/files/${attachmentId}`,
19
- {
20
- method: "DELETE",
21
- }
22
- );
17
+ return $fetch<Record<string, any>>(`/api/files/${attachmentId}`, {
18
+ method: "DELETE",
19
+ });
23
20
  }
24
21
 
25
22
  return {
@@ -4,29 +4,23 @@ export default function useInvoice() {
4
4
  throw new Error("Subscription ID is required");
5
5
  }
6
6
 
7
- return useNuxtApp().$api<Record<string, any>>(
8
- `/api/invoices/subscription/${id}`,
9
- {
10
- method: "GET",
11
- params: {
12
- search,
13
- page,
14
- },
15
- }
16
- );
7
+ return $fetch<Record<string, any>>(`/api/invoices/subscription/${id}`, {
8
+ method: "GET",
9
+ params: {
10
+ search,
11
+ page,
12
+ },
13
+ });
17
14
  }
18
15
 
19
16
  function getByNumber(number: string) {
20
- return useNuxtApp().$api<Record<string, any>>(
21
- `/api/invoices/number/${number}`,
22
- {
23
- method: "GET",
24
- }
25
- );
17
+ return $fetch<Record<string, any>>(`/api/invoices/number/${number}`, {
18
+ method: "GET",
19
+ });
26
20
  }
27
21
 
28
22
  function getByDueDateStatus(date: string, status: string) {
29
- return useNuxtApp().$api<Record<string, any>>(
23
+ return $fetch<Record<string, any>>(
30
24
  `/api/invoices/due-date/${date}/status/${status}`,
31
25
  {
32
26
  method: "GET",
@@ -12,7 +12,7 @@ export default function useLocalAuth() {
12
12
 
13
13
  const { data: getCurrentUserReq, error: getCurrentUserErr } =
14
14
  useLazyAsyncData("get-current-user", () =>
15
- useNuxtApp().$api<TUser>(`/api/users/id/${user}`)
15
+ $fetch<TUser>(`/api/users/id/${user}`)
16
16
  );
17
17
 
18
18
  watchEffect(() => {
@@ -30,7 +30,7 @@ export default function useLocalAuth() {
30
30
  }
31
31
 
32
32
  async function login({ email = "", password = "", role = "" }) {
33
- return useNuxtApp().$api<Record<string, any>>("/api/auth/login", {
33
+ return $fetch<Record<string, any>>("/api/auth/login", {
34
34
  method: "POST",
35
35
  body: JSON.stringify({ email, password, role }),
36
36
  });
@@ -61,7 +61,7 @@ export default function useLocalAuth() {
61
61
  }
62
62
 
63
63
  async function logout() {
64
- return useNuxtApp().$api("/api/auth/logout", {
64
+ return $fetch("/api/auth/logout", {
65
65
  method: "DELETE",
66
66
  });
67
67
  }
@@ -69,7 +69,7 @@ export default function useLocalAuth() {
69
69
  async function getCurrentUser() {
70
70
  const user = useCookie("user", cookieConfig).value;
71
71
  const { data: userData } = await useLazyAsyncData("get-current-user", () =>
72
- useNuxtApp().$api<TUser>(`/api/users/id/${user}`)
72
+ $fetch<TUser>(`/api/users/id/${user}`)
73
73
  );
74
74
 
75
75
  watchEffect(() => {
@@ -85,7 +85,7 @@ export default function useLocalAuth() {
85
85
  }
86
86
 
87
87
  try {
88
- const response = await useNuxtApp().$api("/api/auth/forget-password", {
88
+ const response = await $fetch("/api/auth/forget-password", {
89
89
  method: "POST",
90
90
  body: JSON.stringify({ email }),
91
91
  headers: { "Content-Type": "application/json" },
@@ -103,7 +103,7 @@ export default function useLocalAuth() {
103
103
  passwordConfirmation: string
104
104
  ) {
105
105
  try {
106
- return await useNuxtApp().$api("/api/auth/reset-password", {
106
+ return await $fetch("/api/auth/reset-password", {
107
107
  method: "POST",
108
108
  body: JSON.stringify({ otp, newPassword, passwordConfirmation }),
109
109
  headers: { "Content-Type": "application/json" },
@@ -115,13 +115,13 @@ export default function useLocalAuth() {
115
115
  }
116
116
 
117
117
  function verify(id: string) {
118
- return useNuxtApp().$api<Record<string, any>>(`/api/auth/verify/${id}`, {
118
+ return $fetch<Record<string, any>>(`/api/auth/verify/${id}`, {
119
119
  method: "GET",
120
120
  });
121
121
  }
122
122
 
123
123
  function signUp(email: string, referral: string) {
124
- return useNuxtApp().$api<Record<string, any>>("/api/auth/sign-up", {
124
+ return $fetch<Record<string, any>>("/api/auth/sign-up", {
125
125
  method: "POST",
126
126
  body: { email, referral },
127
127
  });
@@ -22,11 +22,11 @@ export default function useMember() {
22
22
  }));
23
23
 
24
24
  function getByUserId(user: string) {
25
- return useNuxtApp().$api<TMember>(`/api/members/user/${user}`);
25
+ return $fetch<TMember>(`/api/members/user/${user}`);
26
26
  }
27
27
 
28
28
  function getByUserType(user: string, type: string, org?: string) {
29
- return useNuxtApp().$api<TMember>(`/api/members/user/${user}/app/${type}`, {
29
+ return $fetch<TMember>(`/api/members/user/${user}/app/${type}`, {
30
30
  method: "GET",
31
31
  query: { org },
32
32
  });
@@ -41,7 +41,7 @@ export default function useMember() {
41
41
  type = "",
42
42
  status = "active",
43
43
  } = {}) {
44
- return useNuxtApp().$api<Record<string, any>>("/api/members", {
44
+ return $fetch<Record<string, any>>("/api/members", {
45
45
  method: "GET",
46
46
  query: { page, limit, search, user, org, type, status },
47
47
  });
@@ -50,25 +50,19 @@ export default function useMember() {
50
50
  verificationId: string,
51
51
  payload: Record<string, any>
52
52
  ) {
53
- return useNuxtApp().$api<Record<string, any>>(
54
- `/api/users/invite/${verificationId}`,
55
- {
56
- method: "POST",
57
- body: payload,
58
- }
59
- );
53
+ return $fetch<Record<string, any>>(`/api/users/invite/${verificationId}`, {
54
+ method: "POST",
55
+ body: payload,
56
+ });
60
57
  }
61
58
 
62
59
  function createMemberInvite(verificatonId: string) {
63
- return useNuxtApp().$api<TMember>(
64
- `/api/members/verification/${verificatonId}`,
65
- {
66
- method: "POST",
67
- }
68
- );
60
+ return $fetch<TMember>(`/api/members/verification/${verificatonId}`, {
61
+ method: "POST",
62
+ });
69
63
  }
70
64
  function updateMemberStatus(id: string, status: string) {
71
- return useNuxtApp().$api<Record<string, any>>(
65
+ return $fetch<Record<string, any>>(
72
66
  `/api/members/status/${status}/id/${id}`,
73
67
  {
74
68
  method: "PUT",
@@ -82,7 +76,7 @@ export default function useMember() {
82
76
  type: string,
83
77
  org: string
84
78
  ) {
85
- return useNuxtApp().$api<Record<string, any>>(
79
+ return $fetch<Record<string, any>>(
86
80
  `/api/members/id/${id}/role/${role}/type/${type}/org/${org}`,
87
81
  {
88
82
  method: "PUT",
@@ -1,6 +1,6 @@
1
1
  export default function useOffice() {
2
2
  function add(value: TOffice) {
3
- return useNuxtApp().$api<Record<string, any>>("/api/offices", {
3
+ return $fetch<Record<string, any>>("/api/offices", {
4
4
  method: "POST",
5
5
  body: value,
6
6
  });
@@ -13,20 +13,20 @@ export default function useOffice() {
13
13
  type = "",
14
14
  status = "active",
15
15
  } = {}) {
16
- return useNuxtApp().$api<Record<string, any>>("/api/offices", {
16
+ return $fetch<Record<string, any>>("/api/offices", {
17
17
  method: "GET",
18
18
  query: { page, limit, search, type, status },
19
19
  });
20
20
  }
21
21
 
22
22
  function updateById(id: string) {
23
- return useNuxtApp().$api<Record<string, any>>(`/api/offices/${id}`, {
23
+ return $fetch<Record<string, any>>(`/api/offices/${id}`, {
24
24
  method: "PUT",
25
25
  });
26
26
  }
27
27
 
28
28
  function deleteById(id: string) {
29
- return useNuxtApp().$api<Record<string, any>>(`/api/offices/${id}`, {
29
+ return $fetch<Record<string, any>>(`/api/offices/${id}`, {
30
30
  method: "DELETE",
31
31
  });
32
32
  }
@@ -5,7 +5,7 @@ export default function useOrder() {
5
5
  page = 1,
6
6
  status = "succeeded",
7
7
  } = {}) {
8
- return useNuxtApp().$api<Record<string, any>>("/api/orders", {
8
+ return $fetch<Record<string, any>>("/api/orders", {
9
9
  method: "GET",
10
10
  query: {
11
11
  search,
@@ -1,6 +1,6 @@
1
1
  export default function useOrg() {
2
2
  function getAll({ page = 1, search = "", limit = 20, status = "" } = {}) {
3
- return useNuxtApp().$api<Record<string, any>>("/api/organizations", {
3
+ return $fetch<Record<string, any>>("/api/organizations", {
4
4
  method: "GET",
5
5
  query: {
6
6
  page,
@@ -12,26 +12,20 @@ export default function useOrg() {
12
12
  }
13
13
 
14
14
  function getById(id = "") {
15
- return useNuxtApp().$api<Record<string, any>>(
16
- `/api/organizations/id/${id}`,
17
- {
18
- method: "GET",
19
- }
20
- );
15
+ return $fetch<Record<string, any>>(`/api/organizations/id/${id}`, {
16
+ method: "GET",
17
+ });
21
18
  }
22
19
 
23
20
  function getByUserId({ page = 1, search = "", user = "", limit = 20 } = {}) {
24
- return useNuxtApp().$api<Record<string, any>>(
25
- `/api/organizations/user/${user}`,
26
- {
27
- method: "GET",
28
- query: {
29
- page,
30
- search,
31
- limit,
32
- },
33
- }
34
- );
21
+ return $fetch<Record<string, any>>(`/api/organizations/user/${user}`, {
22
+ method: "GET",
23
+ query: {
24
+ page,
25
+ search,
26
+ limit,
27
+ },
28
+ });
35
29
  }
36
30
 
37
31
  const org = ref({
@@ -77,7 +71,7 @@ export default function useOrg() {
77
71
  const total = computed(() => seats.value * perSeatPrice);
78
72
 
79
73
  function getByName(name = "") {
80
- return useNuxtApp().$api<TOrg>(`/api/organizations/name/${name}`, {
74
+ return $fetch<TOrg>(`/api/organizations/name/${name}`, {
81
75
  method: "GET",
82
76
  });
83
77
  }
@@ -5,7 +5,7 @@ export default function usePayment() {
5
5
  page = 1,
6
6
  status = "completed",
7
7
  } = {}) {
8
- return useNuxtApp().$api<Record<string, any>>("/api/payments", {
8
+ return $fetch<Record<string, any>>("/api/payments", {
9
9
  method: "GET",
10
10
  query: {
11
11
  search,
@@ -9,20 +9,17 @@ export default function usePaymentMethod() {
9
9
  cancel_return_url = "",
10
10
  category = "individual",
11
11
  } = {}) {
12
- return useNuxtApp().$api<Record<string, any>>(
13
- "/api/payment-methods/e-wallet",
14
- {
15
- method: "POST",
16
- body: {
17
- customer_id,
18
- type,
19
- success_return_url,
20
- failure_return_url,
21
- cancel_return_url,
22
- category,
23
- },
24
- }
25
- );
12
+ return $fetch<Record<string, any>>("/api/payment-methods/e-wallet", {
13
+ method: "POST",
14
+ body: {
15
+ customer_id,
16
+ type,
17
+ success_return_url,
18
+ failure_return_url,
19
+ cancel_return_url,
20
+ category,
21
+ },
22
+ });
26
23
  }
27
24
 
28
25
  function linkCard({
@@ -37,7 +34,7 @@ export default function usePaymentMethod() {
37
34
  failure_return_url = "",
38
35
  subscriptionData = {},
39
36
  } = {}) {
40
- return useNuxtApp().$api<Record<string, any>>("/api/payment-methods/card", {
37
+ return $fetch<Record<string, any>>("/api/payment-methods/card", {
41
38
  method: "POST",
42
39
  body: {
43
40
  cardType,
@@ -55,7 +52,7 @@ export default function usePaymentMethod() {
55
52
  }
56
53
 
57
54
  function getByUser(user = "") {
58
- return useNuxtApp().$api<Array<Record<string, any>>>(
55
+ return $fetch<Array<Record<string, any>>>(
59
56
  `/api/payment-methods/user/${user}`,
60
57
  {
61
58
  method: "GET",
@@ -64,7 +61,7 @@ export default function usePaymentMethod() {
64
61
  }
65
62
 
66
63
  function getByOrg(org = "") {
67
- return useNuxtApp().$api<Array<Record<string, any>>>(
64
+ return $fetch<Array<Record<string, any>>>(
68
65
  `/api/payment-methods/org/${org}`,
69
66
  {
70
67
  method: "GET",
@@ -73,15 +70,11 @@ export default function usePaymentMethod() {
73
70
  }
74
71
 
75
72
  function getById(id = "") {
76
- return useNuxtApp().$api<Record<string, any>>(
77
- `/api/payment-methods/id/${id}`
78
- );
73
+ return $fetch<Record<string, any>>(`/api/payment-methods/id/${id}`);
79
74
  }
80
75
 
81
76
  function getByCustomerId(id = "") {
82
- return useNuxtApp().$api<Record<string, any>>(
83
- `/api/payment-methods/customer/${id}`
84
- );
77
+ return $fetch<Record<string, any>>(`/api/payment-methods/customer/${id}`);
85
78
  }
86
79
 
87
80
  const eWalletNumber = useState("eWalletNumber", () => "");
@@ -94,13 +87,10 @@ export default function usePaymentMethod() {
94
87
  const selectedPaymentMethod = useState("selectedPaymentMethod", () => "");
95
88
 
96
89
  function linkOnly(value: Record<string, any>) {
97
- return useNuxtApp().$api<Record<string, any>>(
98
- "/api/payment-methods/link-only",
99
- {
100
- method: "POST",
101
- body: value,
102
- }
103
- );
90
+ return $fetch<Record<string, any>>("/api/payment-methods/link-only", {
91
+ method: "POST",
92
+ body: value,
93
+ });
104
94
  }
105
95
 
106
96
  const supportedEwallets = [
@@ -308,13 +298,10 @@ export default function usePaymentMethod() {
308
298
  }
309
299
 
310
300
  function updateStatusById(id: string, status: string) {
311
- return useNuxtApp().$api<Record<string, any>>(
312
- `/api/payment-methods/status/${id}`,
313
- {
314
- method: "PATCH",
315
- body: { status },
316
- }
317
- );
301
+ return $fetch<Record<string, any>>(`/api/payment-methods/status/${id}`, {
302
+ method: "PATCH",
303
+ body: { status },
304
+ });
318
305
  }
319
306
 
320
307
  return {
@@ -1,6 +1,6 @@
1
1
  export default function usePlantilla() {
2
2
  function addPlantilla(plantilla: TPlantilla) {
3
- return useNuxtApp().$api<{ message: string }>("/api/plantillas", {
3
+ return $fetch<{ message: string }>("/api/plantillas", {
4
4
  method: "POST",
5
5
  body: plantilla,
6
6
  });
@@ -13,7 +13,7 @@ export default function usePlantilla() {
13
13
  org = "",
14
14
  app = "admin",
15
15
  } = {}) {
16
- return useNuxtApp().$api<Record<string, any>>("/api/plantillas", {
16
+ return $fetch<Record<string, any>>("/api/plantillas", {
17
17
  method: "GET",
18
18
  query: { page, status, search, org, app },
19
19
  });
@@ -29,7 +29,7 @@ export default function usePlantilla() {
29
29
  formData.append("region", region);
30
30
  formData.append("division", division);
31
31
 
32
- return useNuxtApp().$api<{
32
+ return $fetch<{
33
33
  message: string;
34
34
  details: {
35
35
  successful: number;
@@ -1,6 +1,6 @@
1
1
  export default function usePrice() {
2
2
  function getByNameType(name: string, type: string) {
3
- return useNuxtApp().$api<Record<string, any>>("/api/prices/price", {
3
+ return $fetch<Record<string, any>>("/api/prices/price", {
4
4
  method: "GET",
5
5
  params: {
6
6
  name,
@@ -1,13 +1,13 @@
1
1
  export default function usePromoCode() {
2
2
  function add(value: TPromoCode) {
3
- return useNuxtApp().$api<Record<string, any>>("/api/promo-codes", {
3
+ return $fetch<Record<string, any>>("/api/promo-codes", {
4
4
  method: "POST",
5
5
  body: value,
6
6
  });
7
7
  }
8
8
 
9
9
  function getPromoCodes({ search = "", page = 1, status = "active" } = {}) {
10
- return useNuxtApp().$api<Record<string, any>>("/api/promo-codes", {
10
+ return $fetch<Record<string, any>>("/api/promo-codes", {
11
11
  method: "GET",
12
12
  query: {
13
13
  search,
@@ -18,7 +18,7 @@ export default function usePromoCode() {
18
18
  }
19
19
 
20
20
  function getByCode(code: string, type?: string, assigned?: boolean) {
21
- return useNuxtApp().$api<TPromoCode>("/api/promo-codes/code", {
21
+ return $fetch<TPromoCode>("/api/promo-codes/code", {
22
22
  method: "GET",
23
23
  params: {
24
24
  code,
@@ -29,7 +29,7 @@ export default function usePromoCode() {
29
29
  }
30
30
 
31
31
  function getById(id: string) {
32
- return useNuxtApp().$api<TPromoCode>(`/api/promo-codes/id/${id}`, {
32
+ return $fetch<TPromoCode>(`/api/promo-codes/id/${id}`, {
33
33
  method: "GET",
34
34
  });
35
35
  }
@@ -1,15 +1,14 @@
1
1
  export default function useRole() {
2
2
  function createRole(
3
- { name, permissions, type, id } = {} as {
3
+ { name, permissions, type } = {} as {
4
4
  name: string;
5
5
  permissions: Array<string>;
6
6
  type: string;
7
- id: string;
8
7
  }
9
8
  ) {
10
- return useNuxtApp().$api("/api/roles", {
9
+ return $fetch("/api/roles", {
11
10
  method: "POST",
12
- body: { name, permissions, type, id },
11
+ body: { name, permissions, type },
13
12
  });
14
13
  }
15
14
 
@@ -20,14 +19,14 @@ export default function useRole() {
20
19
  type = "",
21
20
  id = "",
22
21
  } = {}) {
23
- return useNuxtApp().$api<Record<string, any>>("/api/roles", {
22
+ return $fetch<Record<string, any>>("/api/roles", {
24
23
  method: "GET",
25
24
  query: { search, page, limit, type, id },
26
25
  });
27
26
  }
28
27
 
29
28
  function getRoleById(id: string) {
30
- return useNuxtApp().$api<Record<string, any>>(`/api/roles/id/${id}`, {
29
+ return $fetch<TRole>(`/api/roles/id/${id}`, {
31
30
  method: "GET",
32
31
  });
33
32
  }
@@ -37,28 +36,28 @@ export default function useRole() {
37
36
  name?: string,
38
37
  permissions?: Array<string>
39
38
  ) {
40
- return useNuxtApp().$api(`/api/roles/id/${_id}`, {
39
+ return $fetch(`/api/roles/id/${_id}`, {
41
40
  method: "PATCH",
42
41
  body: { name, permissions },
43
42
  });
44
43
  }
45
44
 
46
45
  function updatePermissionById(_id: string, permissions?: Array<string>) {
47
- return useNuxtApp().$api(`/api/roles/permissions/id/${_id}`, {
46
+ return $fetch(`/api/roles/permissions/id/${_id}`, {
48
47
  method: "PATCH",
49
48
  body: { permissions },
50
49
  });
51
50
  }
52
51
 
53
52
  function updateRoleFieldById(_id: string, field: string, value: string) {
54
- return useNuxtApp().$api(`/api/roles/${_id}`, {
53
+ return $fetch(`/api/roles/${_id}`, {
55
54
  method: "PATCH",
56
55
  body: { field, value },
57
56
  });
58
57
  }
59
58
 
60
59
  function deleteRole(_id: string) {
61
- return useNuxtApp().$api<Record<string, any>>(`/api/roles/${_id}`, {
60
+ return $fetch<Record<string, any>>(`/api/roles/${_id}`, {
62
61
  method: "DELETE",
63
62
  });
64
63
  }
@@ -4,7 +4,7 @@ export default function useSubscription() {
4
4
  trialDays: number,
5
5
  productId: string
6
6
  ) {
7
- return useNuxtApp().$api("/api/subscriptions/plan", {
7
+ return $fetch("/api/subscriptions/plan", {
8
8
  method: "POST",
9
9
  body: {
10
10
  seats,
@@ -15,7 +15,7 @@ export default function useSubscription() {
15
15
  }
16
16
 
17
17
  function add(subscriptionId: string, user: string) {
18
- return useNuxtApp().$api("/api/subscriptions", {
18
+ return $fetch("/api/subscriptions", {
19
19
  method: "POST",
20
20
  body: {
21
21
  subscriptionId,
@@ -25,7 +25,7 @@ export default function useSubscription() {
25
25
  }
26
26
 
27
27
  function addBillingContactById(id: string, email: string) {
28
- return useNuxtApp().$api(`/api/subscriptions/billing-contact/${id}`, {
28
+ return $fetch(`/api/subscriptions/billing-contact/${id}`, {
29
29
  method: "PUT",
30
30
  body: {
31
31
  email,
@@ -38,7 +38,7 @@ export default function useSubscription() {
38
38
  addedAt: string,
39
39
  email: string
40
40
  ) {
41
- return useNuxtApp().$api(
41
+ return $fetch(
42
42
  `/api/subscriptions/billing-contact/${id}/added-at/${addedAt}`,
43
43
  {
44
44
  method: "PUT",
@@ -50,7 +50,7 @@ export default function useSubscription() {
50
50
  }
51
51
 
52
52
  function deleteBillingContactByAddedAt(id: string, addedAt: string) {
53
- return useNuxtApp().$api(
53
+ return $fetch(
54
54
  `/api/subscriptions/billing-contact/${id}/added-at/${addedAt}`,
55
55
  {
56
56
  method: "DELETE",
@@ -59,33 +59,27 @@ export default function useSubscription() {
59
59
  }
60
60
 
61
61
  function getById(id: string) {
62
- return useNuxtApp().$api<TSubscription>(`/api/subscriptions/id/${id}`);
62
+ return $fetch<TSubscription>(`/api/subscriptions/id/${id}`);
63
63
  }
64
64
 
65
65
  function getByAffiliateId(id: string) {
66
- return useNuxtApp().$api<TSubscription>(
67
- `/api/subscriptions/affiliate/${id}`
68
- );
66
+ return $fetch<TSubscription>(`/api/subscriptions/affiliate/${id}`);
69
67
  }
70
68
 
71
69
  function getByOrgId(id: string) {
72
- return useNuxtApp().$api<Record<string, any>>(
73
- `/api/subscriptions/org/${id}`
74
- );
70
+ return $fetch<Record<string, any>>(`/api/subscriptions/org/${id}`);
75
71
  }
76
72
 
77
73
  function getSubscriptions() {
78
- return useNuxtApp().$api("/api/subscriptions");
74
+ return $fetch("/api/subscriptions");
79
75
  }
80
76
 
81
77
  function getSubscriptionStatusById(id: string) {
82
- return useNuxtApp().$api<Record<string, string>>(
83
- `/api/subscriptions/status/${id}`
84
- );
78
+ return $fetch<Record<string, string>>(`/api/subscriptions/status/${id}`);
85
79
  }
86
80
 
87
81
  function cancelSubscription(id: string) {
88
- return useNuxtApp().$api(`/api/subscriptions/cancel/${id}`, {
82
+ return $fetch(`/api/subscriptions/cancel/${id}`, {
89
83
  method: "DELETE",
90
84
  });
91
85
  }
@@ -96,7 +90,7 @@ export default function useSubscription() {
96
90
  );
97
91
 
98
92
  function updatePromoCodeById(id: string, promoCode: string) {
99
- return useNuxtApp().$api(`/api/subscriptions/promo-code/${id}`, {
93
+ return $fetch(`/api/subscriptions/promo-code/${id}`, {
100
94
  method: "PUT",
101
95
  body: {
102
96
  promoCode,
@@ -105,7 +99,7 @@ export default function useSubscription() {
105
99
  }
106
100
 
107
101
  function updateStatusById(id: string, status: string) {
108
- return useNuxtApp().$api(`/api/subscriptions/status/${id}`, {
102
+ return $fetch(`/api/subscriptions/status/${id}`, {
109
103
  method: "PUT",
110
104
  body: {
111
105
  status,
@@ -114,7 +108,7 @@ export default function useSubscription() {
114
108
  }
115
109
 
116
110
  function updatePaymentMethodById(id: string, paymentMethodId: string) {
117
- return useNuxtApp().$api(`/api/subscriptions/payment-method/${id}`, {
111
+ return $fetch(`/api/subscriptions/payment-method/${id}`, {
118
112
  method: "PUT",
119
113
  body: {
120
114
  paymentMethodId,
@@ -168,23 +162,17 @@ export default function useSubscription() {
168
162
  };
169
163
 
170
164
  function initOrgSubscription(value: TSub) {
171
- return useNuxtApp().$api<Record<string, any>>(
172
- "/api/subscriptions/organization",
173
- {
174
- method: "POST",
175
- body: value,
176
- }
177
- );
165
+ return $fetch<Record<string, any>>("/api/subscriptions/organization", {
166
+ method: "POST",
167
+ body: value,
168
+ });
178
169
  }
179
170
 
180
171
  function initAffiliateSubscription(value: TSub) {
181
- return useNuxtApp().$api<Record<string, any>>(
182
- "/api/subscriptions/affiliate",
183
- {
184
- method: "POST",
185
- body: value,
186
- }
187
- );
172
+ return $fetch<Record<string, any>>("/api/subscriptions/affiliate", {
173
+ method: "POST",
174
+ body: value,
175
+ });
188
176
  }
189
177
 
190
178
  function updateSeatsById({
@@ -193,7 +181,7 @@ export default function useSubscription() {
193
181
  seats = 0,
194
182
  amount = 0,
195
183
  } = {}) {
196
- return useNuxtApp().$api<Record<string, any>>(
184
+ return $fetch<Record<string, any>>(
197
185
  `/api/subscriptions/seats/${subscriptionId}`,
198
186
  {
199
187
  method: "PUT",
@@ -207,7 +195,7 @@ export default function useSubscription() {
207
195
  }
208
196
 
209
197
  function processSubscriptionPayment(id: string, invoice: string) {
210
- return useNuxtApp().$api(`/api/subscriptions/payment/id/${id}`, {
198
+ return $fetch(`/api/subscriptions/payment/id/${id}`, {
211
199
  method: "PUT",
212
200
  body: {
213
201
  invoice,
@@ -230,7 +218,7 @@ export default function useSubscription() {
230
218
  type: string;
231
219
  };
232
220
  }) {
233
- return useNuxtApp().$api("/api/subscriptions/subscribe", {
221
+ return $fetch("/api/subscriptions/subscribe", {
234
222
  method: "POST",
235
223
  body: value,
236
224
  });
@@ -7,49 +7,49 @@ export default function useUser() {
7
7
  org = "",
8
8
  orgName = "",
9
9
  } = {}) {
10
- return useNuxtApp().$api<Record<string, any>>("/api/auth/invite", {
10
+ return $fetch<Record<string, any>>("/api/auth/invite", {
11
11
  method: "POST",
12
12
  body: { email, app, role, roleName, org, orgName },
13
13
  });
14
14
  }
15
15
 
16
16
  function updateName({ firstName = "", lastName = "" } = {}) {
17
- return useNuxtApp().$api<Record<string, any>>("/api/users/name", {
17
+ return $fetch<Record<string, any>>("/api/users/name", {
18
18
  method: "PUT",
19
19
  body: { firstName, lastName },
20
20
  });
21
21
  }
22
22
 
23
23
  function updateBirthday({ month = "", day = 0, year = 0 } = {}) {
24
- return useNuxtApp().$api<Record<string, any>>("/api/users/birthday", {
24
+ return $fetch<Record<string, any>>("/api/users/birthday", {
25
25
  method: "PUT",
26
26
  body: { month, day, year },
27
27
  });
28
28
  }
29
29
 
30
30
  function updateGender(gender = "") {
31
- return useNuxtApp().$api<Record<string, any>>("/api/users/gender", {
31
+ return $fetch<Record<string, any>>("/api/users/gender", {
32
32
  method: "PUT",
33
33
  body: { gender },
34
34
  });
35
35
  }
36
36
 
37
37
  function updateEmail(email = "") {
38
- return useNuxtApp().$api<Record<string, any>>("/api/users/email", {
38
+ return $fetch<Record<string, any>>("/api/users/email", {
39
39
  method: "PUT",
40
40
  body: { email },
41
41
  });
42
42
  }
43
43
 
44
44
  function updateContact(contact = "") {
45
- return useNuxtApp().$api<Record<string, any>>("/api/users/contact", {
45
+ return $fetch<Record<string, any>>("/api/users/contact", {
46
46
  method: "PUT",
47
47
  body: { contact },
48
48
  });
49
49
  }
50
50
 
51
51
  function updateUserFieldById(id = "", field = "", value = "") {
52
- return useNuxtApp().$api<Record<string, any>>(`/api/users/field/${id}`, {
52
+ return $fetch<Record<string, any>>(`/api/users/field/${id}`, {
53
53
  method: "PATCH",
54
54
  body: { field, value },
55
55
  });
@@ -61,14 +61,14 @@ export default function useUser() {
61
61
  search = "",
62
62
  page = 1,
63
63
  } = {}) {
64
- return useNuxtApp().$api<Record<string, any>>("/api/users", {
64
+ return $fetch<Record<string, any>>("/api/users", {
65
65
  method: "GET",
66
66
  query: { status, search, page, type },
67
67
  });
68
68
  }
69
69
 
70
70
  function getById(id = "") {
71
- return useNuxtApp().$api<Record<string, any>>(`/api/users/id/${id}`, {
71
+ return $fetch<Record<string, any>>(`/api/users/id/${id}`, {
72
72
  method: "GET",
73
73
  });
74
74
  }
@@ -81,7 +81,7 @@ export default function useUser() {
81
81
  referralCode = "",
82
82
  type = "",
83
83
  } = {}) {
84
- return useNuxtApp().$api<Record<string, any>>(`/api/users/invite/${id}`, {
84
+ return $fetch<Record<string, any>>(`/api/users/invite/${id}`, {
85
85
  method: "POST",
86
86
  body: { firstName, lastName, password, referralCode, type },
87
87
  });
@@ -132,7 +132,7 @@ export default function useUtils() {
132
132
 
133
133
  async function getCountries() {
134
134
  try {
135
- const countries = await useNuxtApp().$api<Array<Record<string, any>>>(
135
+ const countries = await $fetch<Array<Record<string, any>>>(
136
136
  "https://restcountries.com/v3.1/all?fields=name,currencies,idd",
137
137
  { method: "GET" }
138
138
  );
@@ -7,7 +7,7 @@ export default function useUser() {
7
7
  email = "",
8
8
  app = "",
9
9
  } = {}) {
10
- return useNuxtApp().$api<Record<string, any>>("/api/verifications", {
10
+ return $fetch<Record<string, any>>("/api/verifications", {
11
11
  method: "GET",
12
12
  query: { status, search, page, type, email, app },
13
13
  });
@@ -1,4 +1,4 @@
1
- export default defineNuxtRouteMiddleware(async () => {
1
+ export default defineNuxtRouteMiddleware(() => {
2
2
  // Ensure middleware runs only on the client side
3
3
  if (import.meta.server) return;
4
4
 
@@ -0,0 +1,18 @@
1
+ export default defineNuxtRouteMiddleware(async () => {
2
+ // Ensure middleware runs only on the client side
3
+ if (import.meta.server) return;
4
+
5
+ const { cookieConfig } = useRuntimeConfig().public;
6
+
7
+ const user = useCookie("user", cookieConfig).value ?? "";
8
+
9
+ const { getByUserId } = useMember();
10
+ try {
11
+ const memberData = await getByUserId(user);
12
+ if (memberData.role) {
13
+ useCookie("role", cookieConfig).value = memberData.role;
14
+ }
15
+ } catch (error) {
16
+ navigateTo({ name: "require-membership" });
17
+ }
18
+ });
@@ -0,0 +1,22 @@
1
+ export default defineNuxtRouteMiddleware(async () => {
2
+ // Ensure middleware runs only on the client side
3
+ if (import.meta.server) return;
4
+
5
+ const { cookieConfig } = useRuntimeConfig().public;
6
+
7
+ const { getRoleById } = useRole();
8
+ const role = useCookie("role", cookieConfig).value ?? "";
9
+ if (!role) {
10
+ navigateTo({ name: "require-role" });
11
+ return;
12
+ }
13
+
14
+ const { userAppRole } = useLocalSetup();
15
+
16
+ try {
17
+ const roleData = await getRoleById(role);
18
+ userAppRole.value = roleData;
19
+ } catch (error) {
20
+ navigateTo({ name: "require-role" });
21
+ }
22
+ });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@eeplatform/nuxt-layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.4.10",
5
+ "version": "1.5.1",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <v-row no-gutters class="fill-height" align="center" justify="center">
3
+ <v-col cols="12" lg="6" md="6" sm="6" class="text-center text-subtitle-1">
4
+ Role is required to access this app. Please contact administrator.
5
+ <v-row no-gutters justify="center" align="center" class="mt-2">
6
+ <v-btn
7
+ @click="goToAccount"
8
+ rounded="xl"
9
+ variant="tonal"
10
+ class="text-none text-subtitle-2"
11
+ >
12
+ Go to Account Page
13
+ </v-btn>
14
+ </v-row>
15
+ </v-col>
16
+ </v-row>
17
+ </template>
18
+
19
+ <script setup lang="ts">
20
+ definePageMeta({
21
+ layout: "plain",
22
+ });
23
+
24
+ const { APP_ACCOUNT } = useRuntimeConfig().public;
25
+
26
+ function goToAccount() {
27
+ window.location.href = `${APP_ACCOUNT}/home`;
28
+ }
29
+ </script>
package/plugins/API.ts DELETED
@@ -1,33 +0,0 @@
1
- export default defineNuxtPlugin(() => {
2
- const { cookieConfig } = useRuntimeConfig().public;
3
- const { redirect } = useLocal();
4
-
5
- const api = $fetch.create({
6
- baseURL: "/",
7
- retry: 1,
8
- retryStatusCodes: [401],
9
- retryDelay: 500,
10
- onRequest({ options }) {
11
- const sid = useCookie("sid", cookieConfig).value ?? "";
12
- options.headers.set("authorization", sid);
13
- },
14
- onResponse({ response }) {
15
- if (response.status === 401) {
16
- // Clear cookie
17
- let sid = useCookie("sid", cookieConfig).value;
18
- if (sid) {
19
- sid = null;
20
- const { APP_MAIN } = useRuntimeConfig().public;
21
- redirect(APP_MAIN, "logout");
22
- }
23
- }
24
- },
25
- });
26
-
27
- // Expose to useNuxtApp().$api
28
- return {
29
- provide: {
30
- api,
31
- },
32
- };
33
- });