@eeplatform/nuxt-layer-common 1.7.17 → 1.7.19

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.7.19
4
+
5
+ ### Patch Changes
6
+
7
+ - c9a024e: add API.ts plugin
8
+
9
+ ## 1.7.18
10
+
11
+ ### Patch Changes
12
+
13
+ - df3cd25: Fix program model
14
+
3
15
  ## 1.7.17
4
16
 
5
17
  ### Patch Changes
@@ -124,7 +136,7 @@
124
136
 
125
137
  ### Minor Changes
126
138
 
127
- - cc493b1: Migrate from custom fetch to $fetch
139
+ - cc493b1: Migrate from custom fetch to useNuxtApp().$api
128
140
 
129
141
  ## 1.4.10
130
142
 
@@ -13,7 +13,7 @@ export default function useAddress() {
13
13
  postalCode = "",
14
14
  taxId = "",
15
15
  } = {}) {
16
- return $fetch("/api/addresses", {
16
+ return useNuxtApp().$api("/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 $fetch(`/api/addresses/details/${id}`, {
60
+ return useNuxtApp().$api(`/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 $fetch<TAddress>(`/api/addresses/user/${user}`);
67
+ return useNuxtApp().$api<TAddress>(`/api/addresses/user/${user}`);
68
68
  }
69
69
 
70
70
  function getByOrgId(id = "") {
71
- return $fetch<TAddress>(`/api/addresses/org/${id}`);
71
+ return useNuxtApp().$api<TAddress>(`/api/addresses/org/${id}`);
72
72
  }
73
73
 
74
74
  const _address = useState("address", (): TAddress => {
@@ -129,11 +129,15 @@ export default function useBasicEdu() {
129
129
  }
130
130
 
131
131
  async function getPhilippineMunicipalities() {
132
- return $fetch<Record<string, any>>("https://psgc.cloud/api/municipalities");
132
+ return useNuxtApp().$api<Record<string, any>>(
133
+ "https://psgc.cloud/api/municipalities"
134
+ );
133
135
  }
134
136
 
135
137
  async function getPhilippineCities() {
136
- return $fetch<Record<string, any>>("https://psgc.cloud/api/cities");
138
+ return useNuxtApp().$api<Record<string, any>>(
139
+ "https://psgc.cloud/api/cities"
140
+ );
137
141
  }
138
142
 
139
143
  const motherTongueOptions = [
@@ -7,7 +7,7 @@ export default function useChartOfAccount() {
7
7
  children?: number;
8
8
  }
9
9
  ) {
10
- return $fetch<Record<string, any>>("/api/chart-of-accounts", {
10
+ return useNuxtApp().$api<Record<string, any>>("/api/chart-of-accounts", {
11
11
  method: "GET",
12
12
  query: { page, status, orgId, children },
13
13
  });
@@ -23,30 +23,35 @@ export default function useChartOfAccount() {
23
23
  };
24
24
 
25
25
  function add(value: TAddPayload) {
26
- return $fetch<TAddPayload>("/api/chart-of-accounts", {
26
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>(`/api/chart-of-accounts/id/${id}`);
33
+ return useNuxtApp().$api<Record<string, any>>(
34
+ `/api/chart-of-accounts/id/${id}`
35
+ );
34
36
  }
35
37
 
36
38
  function updateById(
37
39
  id: string,
38
40
  value: Pick<TAddPayload, "name" | "code" | "normalBalance" | "parent">
39
41
  ) {
40
- return $fetch<TAddPayload>(`/api/chart-of-accounts/id/${id}`, {
42
+ return useNuxtApp().$api<TAddPayload>(`/api/chart-of-accounts/id/${id}`, {
41
43
  method: "PUT",
42
44
  body: value,
43
45
  });
44
46
  }
45
47
 
46
48
  function deleteById(id: string) {
47
- return $fetch<Record<string, any>>(`/api/chart-of-accounts/id/${id}`, {
48
- method: "DELETE",
49
- });
49
+ return useNuxtApp().$api<Record<string, any>>(
50
+ `/api/chart-of-accounts/id/${id}`,
51
+ {
52
+ method: "DELETE",
53
+ }
54
+ );
50
55
  }
51
56
 
52
57
  return {
@@ -6,9 +6,12 @@ export default function useRegion() {
6
6
  limit = 20,
7
7
  region = "",
8
8
  } = {}) {
9
- return $fetch<Record<string, any>>("/api/basic-education/divisions", {
10
- query: { page, search, status, limit, region },
11
- });
9
+ return useNuxtApp().$api<Record<string, any>>(
10
+ "/api/basic-education/divisions",
11
+ {
12
+ query: { page, search, status, limit, region },
13
+ }
14
+ );
12
15
  }
13
16
 
14
17
  return {
@@ -95,7 +95,7 @@ export default function useEnrollment() {
95
95
  });
96
96
 
97
97
  function add(value: TTLearner) {
98
- return $fetch("/api/basic-education/enrollments", {
98
+ return useNuxtApp().$api("/api/basic-education/enrollments", {
99
99
  method: "POST",
100
100
  body: value,
101
101
  });
@@ -110,13 +110,16 @@ export default function useEnrollment() {
110
110
  createdBy = "",
111
111
  gradeLevel = "",
112
112
  } = {}) {
113
- return $fetch<Record<string, any>>("/api/basic-education/enrollments", {
114
- query: { status, page, limit, search, createdBy, school, gradeLevel },
115
- });
113
+ return useNuxtApp().$api<Record<string, any>>(
114
+ "/api/basic-education/enrollments",
115
+ {
116
+ query: { status, page, limit, search, createdBy, school, gradeLevel },
117
+ }
118
+ );
116
119
  }
117
120
 
118
121
  function updateStatusById(_id: string, status: string) {
119
- return $fetch<string>(
122
+ return useNuxtApp().$api<string>(
120
123
  `/api/basic-education/enrollments/status/${status}/id/${_id}`,
121
124
  {
122
125
  method: "PATCH",
@@ -125,10 +128,13 @@ export default function useEnrollment() {
125
128
  }
126
129
 
127
130
  function updateStatusWithId(_id: string, status: string) {
128
- return $fetch<string>(`/api/basic-education/enrollments/status/id/${_id}`, {
129
- method: "PATCH",
130
- body: { status },
131
- });
131
+ return useNuxtApp().$api<string>(
132
+ `/api/basic-education/enrollments/status/id/${_id}`,
133
+ {
134
+ method: "PATCH",
135
+ body: { status },
136
+ }
137
+ );
132
138
  }
133
139
 
134
140
  function generateEnrollmentData(value: {
@@ -137,7 +143,7 @@ export default function useEnrollment() {
137
143
  numberOfApplications: number;
138
144
  schoolYear: string;
139
145
  }) {
140
- return $fetch("/api/basic-education/enrollments/generate", {
146
+ return useNuxtApp().$api("/api/basic-education/enrollments/generate", {
141
147
  method: "POST",
142
148
  body: value,
143
149
  });
@@ -7,16 +7,19 @@ export default function useFile() {
7
7
  const formData = new FormData();
8
8
  formData.append("file", file);
9
9
 
10
- return $fetch<Record<string, any>>("/api/files", {
10
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>(`/api/files/${attachmentId}`, {
18
- method: "DELETE",
19
- });
17
+ return useNuxtApp().$api<Record<string, any>>(
18
+ `/api/files/${attachmentId}`,
19
+ {
20
+ method: "DELETE",
21
+ }
22
+ );
20
23
  }
21
24
 
22
25
  return {
@@ -2,7 +2,7 @@ export default function useGradeLevel() {
2
2
  const resource = "basic-education/grade-levels";
3
3
 
4
4
  function add(value: TGradeLevel) {
5
- return $fetch<Record<string, any>>(`/api/${resource}`, {
5
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}`, {
6
6
  method: "POST",
7
7
  body: value,
8
8
  });
@@ -15,20 +15,23 @@ export default function useGradeLevel() {
15
15
  status = "active",
16
16
  school = "",
17
17
  } = {}) {
18
- return $fetch<Record<string, any>>(`/api/${resource}/school/${school}`, {
19
- method: "GET",
20
- query: { page, limit, search, status },
21
- });
18
+ return useNuxtApp().$api<Record<string, any>>(
19
+ `/api/${resource}/school/${school}`,
20
+ {
21
+ method: "GET",
22
+ query: { page, limit, search, status },
23
+ }
24
+ );
22
25
  }
23
26
 
24
27
  function updateById(id: string) {
25
- return $fetch<Record<string, any>>(`/api/${resource}/${id}`, {
28
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}/${id}`, {
26
29
  method: "PUT",
27
30
  });
28
31
  }
29
32
 
30
33
  function deleteById(id: string) {
31
- return $fetch<Record<string, any>>(`/api/${resource}/${id}`, {
34
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}/${id}`, {
32
35
  method: "DELETE",
33
36
  });
34
37
  }
@@ -4,23 +4,29 @@ export default function useInvoice() {
4
4
  throw new Error("Subscription ID is required");
5
5
  }
6
6
 
7
- return $fetch<Record<string, any>>(`/api/invoices/subscription/${id}`, {
8
- method: "GET",
9
- params: {
10
- search,
11
- page,
12
- },
13
- });
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
+ );
14
17
  }
15
18
 
16
19
  function getByNumber(number: string) {
17
- return $fetch<Record<string, any>>(`/api/invoices/number/${number}`, {
18
- method: "GET",
19
- });
20
+ return useNuxtApp().$api<Record<string, any>>(
21
+ `/api/invoices/number/${number}`,
22
+ {
23
+ method: "GET",
24
+ }
25
+ );
20
26
  }
21
27
 
22
28
  function getByDueDateStatus(date: string, status: string) {
23
- return $fetch<Record<string, any>>(
29
+ return useNuxtApp().$api<Record<string, any>>(
24
30
  `/api/invoices/due-date/${date}/status/${status}`,
25
31
  {
26
32
  method: "GET",
@@ -7,13 +7,16 @@ export default function useLearner() {
7
7
  school = "",
8
8
  level = "",
9
9
  } = {}) {
10
- return $fetch<Record<string, any>>("/api/basic-education/learners", {
11
- query: { page, search, status, limit, school, level },
12
- });
10
+ return useNuxtApp().$api<Record<string, any>>(
11
+ "/api/basic-education/learners",
12
+ {
13
+ query: { page, search, status, limit, school, level },
14
+ }
15
+ );
13
16
  }
14
17
 
15
18
  function add(value: TTLearner) {
16
- return $fetch("/api/basic-education/learners", {
19
+ return useNuxtApp().$api("/api/basic-education/learners", {
17
20
  method: "POST",
18
21
  body: value,
19
22
  });
@@ -12,7 +12,7 @@ export default function useLocalAuth() {
12
12
 
13
13
  const { data: getCurrentUserReq, error: getCurrentUserErr } =
14
14
  useLazyAsyncData("get-current-user", () =>
15
- $fetch<TUser>(`/api/users/id/${user}`)
15
+ useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/auth/login", {
33
+ return useNuxtApp().$api<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 $fetch("/api/auth/logout", {
64
+ return useNuxtApp().$api("/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
- $fetch<TUser>(`/api/users/id/${user}`)
72
+ useNuxtApp().$api<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 $fetch("/api/auth/forget-password", {
88
+ const response = await useNuxtApp().$api("/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 $fetch("/api/auth/reset-password", {
106
+ return await useNuxtApp().$api("/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 $fetch<Record<string, any>>(`/api/auth/verify/${id}`, {
118
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/auth/sign-up", {
124
+ return useNuxtApp().$api<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 $fetch<TMember>(`/api/members/user/${user}`);
25
+ return useNuxtApp().$api<TMember>(`/api/members/user/${user}`);
26
26
  }
27
27
 
28
28
  function getByUserType(user: string, type: string, org?: string) {
29
- return $fetch<TMember>(`/api/members/user/${user}/app/${type}`, {
29
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/members", {
44
+ return useNuxtApp().$api<Record<string, any>>("/api/members", {
45
45
  method: "GET",
46
46
  query: { page, limit, search, user, org, type, status },
47
47
  });
@@ -50,19 +50,25 @@ export default function useMember() {
50
50
  verificationId: string,
51
51
  payload: Record<string, any>
52
52
  ) {
53
- return $fetch<Record<string, any>>(`/api/users/invite/${verificationId}`, {
54
- method: "POST",
55
- body: payload,
56
- });
53
+ return useNuxtApp().$api<Record<string, any>>(
54
+ `/api/users/invite/${verificationId}`,
55
+ {
56
+ method: "POST",
57
+ body: payload,
58
+ }
59
+ );
57
60
  }
58
61
 
59
62
  function createMemberInvite(verificatonId: string) {
60
- return $fetch<TMember>(`/api/members/verification/${verificatonId}`, {
61
- method: "POST",
62
- });
63
+ return useNuxtApp().$api<TMember>(
64
+ `/api/members/verification/${verificatonId}`,
65
+ {
66
+ method: "POST",
67
+ }
68
+ );
63
69
  }
64
70
  function updateMemberStatus(id: string, status: string) {
65
- return $fetch<Record<string, any>>(
71
+ return useNuxtApp().$api<Record<string, any>>(
66
72
  `/api/members/status/${status}/id/${id}`,
67
73
  {
68
74
  method: "PUT",
@@ -76,7 +82,7 @@ export default function useMember() {
76
82
  type: string,
77
83
  org: string
78
84
  ) {
79
- return $fetch<Record<string, any>>(
85
+ return useNuxtApp().$api<Record<string, any>>(
80
86
  `/api/members/id/${id}/role/${role}/type/${type}/org/${org}`,
81
87
  {
82
88
  method: "PUT",
@@ -1,6 +1,6 @@
1
1
  export default function useOffice() {
2
2
  function add(value: TOffice) {
3
- return $fetch<Record<string, any>>("/api/offices", {
3
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/offices", {
16
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>(`/api/offices/${id}`, {
23
+ return useNuxtApp().$api<Record<string, any>>(`/api/offices/${id}`, {
24
24
  method: "PUT",
25
25
  });
26
26
  }
27
27
 
28
28
  function deleteById(id: string) {
29
- return $fetch<Record<string, any>>(`/api/offices/${id}`, {
29
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/orders", {
8
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/organizations", {
3
+ return useNuxtApp().$api<Record<string, any>>("/api/organizations", {
4
4
  method: "GET",
5
5
  query: {
6
6
  page,
@@ -12,20 +12,26 @@ export default function useOrg() {
12
12
  }
13
13
 
14
14
  function getById(id = "") {
15
- return $fetch<Record<string, any>>(`/api/organizations/id/${id}`, {
16
- method: "GET",
17
- });
15
+ return useNuxtApp().$api<Record<string, any>>(
16
+ `/api/organizations/id/${id}`,
17
+ {
18
+ method: "GET",
19
+ }
20
+ );
18
21
  }
19
22
 
20
23
  function getByUserId({ page = 1, search = "", user = "", limit = 20 } = {}) {
21
- return $fetch<Record<string, any>>(`/api/organizations/user/${user}`, {
22
- method: "GET",
23
- query: {
24
- page,
25
- search,
26
- limit,
27
- },
28
- });
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
+ );
29
35
  }
30
36
 
31
37
  const org = ref({
@@ -71,7 +77,7 @@ export default function useOrg() {
71
77
  const total = computed(() => seats.value * perSeatPrice);
72
78
 
73
79
  function getByName(name = "") {
74
- return $fetch<TOrg>(`/api/organizations/name/${name}`, {
80
+ return useNuxtApp().$api<TOrg>(`/api/organizations/name/${name}`, {
75
81
  method: "GET",
76
82
  });
77
83
  }
@@ -6,7 +6,7 @@ export default function usePSGC() {
6
6
  type = "",
7
7
  prefix = "",
8
8
  } = {}) {
9
- return $fetch<Record<string, any>>("/api/psgc", {
9
+ return useNuxtApp().$api<Record<string, any>>("/api/psgc", {
10
10
  query: { page, limit, search, type, prefix },
11
11
  });
12
12
  }
@@ -5,7 +5,7 @@ export default function usePayment() {
5
5
  page = 1,
6
6
  status = "completed",
7
7
  } = {}) {
8
- return $fetch<Record<string, any>>("/api/payments", {
8
+ return useNuxtApp().$api<Record<string, any>>("/api/payments", {
9
9
  method: "GET",
10
10
  query: {
11
11
  search,
@@ -9,17 +9,20 @@ export default function usePaymentMethod() {
9
9
  cancel_return_url = "",
10
10
  category = "individual",
11
11
  } = {}) {
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
- });
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
+ );
23
26
  }
24
27
 
25
28
  function linkCard({
@@ -34,7 +37,7 @@ export default function usePaymentMethod() {
34
37
  failure_return_url = "",
35
38
  subscriptionData = {},
36
39
  } = {}) {
37
- return $fetch<Record<string, any>>("/api/payment-methods/card", {
40
+ return useNuxtApp().$api<Record<string, any>>("/api/payment-methods/card", {
38
41
  method: "POST",
39
42
  body: {
40
43
  cardType,
@@ -52,7 +55,7 @@ export default function usePaymentMethod() {
52
55
  }
53
56
 
54
57
  function getByUser(user = "") {
55
- return $fetch<Array<Record<string, any>>>(
58
+ return useNuxtApp().$api<Array<Record<string, any>>>(
56
59
  `/api/payment-methods/user/${user}`,
57
60
  {
58
61
  method: "GET",
@@ -61,7 +64,7 @@ export default function usePaymentMethod() {
61
64
  }
62
65
 
63
66
  function getByOrg(org = "") {
64
- return $fetch<Array<Record<string, any>>>(
67
+ return useNuxtApp().$api<Array<Record<string, any>>>(
65
68
  `/api/payment-methods/org/${org}`,
66
69
  {
67
70
  method: "GET",
@@ -70,11 +73,15 @@ export default function usePaymentMethod() {
70
73
  }
71
74
 
72
75
  function getById(id = "") {
73
- return $fetch<Record<string, any>>(`/api/payment-methods/id/${id}`);
76
+ return useNuxtApp().$api<Record<string, any>>(
77
+ `/api/payment-methods/id/${id}`
78
+ );
74
79
  }
75
80
 
76
81
  function getByCustomerId(id = "") {
77
- return $fetch<Record<string, any>>(`/api/payment-methods/customer/${id}`);
82
+ return useNuxtApp().$api<Record<string, any>>(
83
+ `/api/payment-methods/customer/${id}`
84
+ );
78
85
  }
79
86
 
80
87
  const eWalletNumber = useState("eWalletNumber", () => "");
@@ -87,10 +94,13 @@ export default function usePaymentMethod() {
87
94
  const selectedPaymentMethod = useState("selectedPaymentMethod", () => "");
88
95
 
89
96
  function linkOnly(value: Record<string, any>) {
90
- return $fetch<Record<string, any>>("/api/payment-methods/link-only", {
91
- method: "POST",
92
- body: value,
93
- });
97
+ return useNuxtApp().$api<Record<string, any>>(
98
+ "/api/payment-methods/link-only",
99
+ {
100
+ method: "POST",
101
+ body: value,
102
+ }
103
+ );
94
104
  }
95
105
 
96
106
  const supportedEwallets = [
@@ -298,10 +308,13 @@ export default function usePaymentMethod() {
298
308
  }
299
309
 
300
310
  function updateStatusById(id: string, status: string) {
301
- return $fetch<Record<string, any>>(`/api/payment-methods/status/${id}`, {
302
- method: "PATCH",
303
- body: { status },
304
- });
311
+ return useNuxtApp().$api<Record<string, any>>(
312
+ `/api/payment-methods/status/${id}`,
313
+ {
314
+ method: "PATCH",
315
+ body: { status },
316
+ }
317
+ );
305
318
  }
306
319
 
307
320
  return {
@@ -1,6 +1,6 @@
1
1
  export default function usePlantilla() {
2
2
  function addPlantilla(plantilla: TPlantilla) {
3
- return $fetch<{ message: string }>("/api/plantillas", {
3
+ return useNuxtApp().$api<{ 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 $fetch<Record<string, any>>("/api/plantillas", {
16
+ return useNuxtApp().$api<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 $fetch<{
32
+ return useNuxtApp().$api<{
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 $fetch<Record<string, any>>("/api/prices/price", {
3
+ return useNuxtApp().$api<Record<string, any>>("/api/prices/price", {
4
4
  method: "GET",
5
5
  params: {
6
6
  name,
@@ -8,10 +8,11 @@ export function useProgram() {
8
8
  gwa: 0,
9
9
  subjects: [],
10
10
  description: "",
11
+ gradeLevels: [],
11
12
  });
12
13
 
13
14
  function add(value: TProgram) {
14
- return $fetch<Record<string, any>>(`/api/${resource}`, {
15
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}`, {
15
16
  method: "POST",
16
17
  body: value,
17
18
  });
@@ -25,21 +26,21 @@ export function useProgram() {
25
26
  school = "",
26
27
  gradeLevel = "",
27
28
  } = {}) {
28
- return $fetch<Record<string, any>>(`/api/${resource}`, {
29
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}`, {
29
30
  method: "GET",
30
31
  query: { page, limit, search, status, school, gradeLevel },
31
32
  });
32
33
  }
33
34
 
34
35
  function updateById(id: string, value: TProgram) {
35
- return $fetch<Record<string, any>>(`/api/${resource}/id/${id}`, {
36
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}/id/${id}`, {
36
37
  method: "POST",
37
38
  body: value,
38
39
  });
39
40
  }
40
41
 
41
42
  function deleteById(id: string) {
42
- return $fetch<Record<string, any>>(`/api/${resource}/id/${id}`, {
43
+ return useNuxtApp().$api<Record<string, any>>(`/api/${resource}/id/${id}`, {
43
44
  method: "DELETE",
44
45
  });
45
46
  }
@@ -1,13 +1,13 @@
1
1
  export default function usePromoCode() {
2
2
  function add(value: TPromoCode) {
3
- return $fetch<Record<string, any>>("/api/promo-codes", {
3
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/promo-codes", {
10
+ return useNuxtApp().$api<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 $fetch<TPromoCode>("/api/promo-codes/code", {
21
+ return useNuxtApp().$api<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 $fetch<TPromoCode>(`/api/promo-codes/id/${id}`, {
32
+ return useNuxtApp().$api<TPromoCode>(`/api/promo-codes/id/${id}`, {
33
33
  method: "GET",
34
34
  });
35
35
  }
@@ -5,9 +5,12 @@ export default function useRegion() {
5
5
  status = "active",
6
6
  limit = 20,
7
7
  } = {}) {
8
- return $fetch<Record<string, any>>("/api/basic-education/regions", {
9
- query: { page, search, status, limit },
10
- });
8
+ return useNuxtApp().$api<Record<string, any>>(
9
+ "/api/basic-education/regions",
10
+ {
11
+ query: { page, search, status, limit },
12
+ }
13
+ );
11
14
  }
12
15
 
13
16
  return {
@@ -6,7 +6,7 @@ export default function useRole() {
6
6
  type: string;
7
7
  }
8
8
  ) {
9
- return $fetch("/api/roles", {
9
+ return useNuxtApp().$api("/api/roles", {
10
10
  method: "POST",
11
11
  body: { name, permissions, type },
12
12
  });
@@ -19,14 +19,14 @@ export default function useRole() {
19
19
  type = "",
20
20
  id = "",
21
21
  } = {}) {
22
- return $fetch<Record<string, any>>("/api/roles", {
22
+ return useNuxtApp().$api<Record<string, any>>("/api/roles", {
23
23
  method: "GET",
24
24
  query: { search, page, limit, type, id },
25
25
  });
26
26
  }
27
27
 
28
28
  function getRoleById(id: string) {
29
- return $fetch<TRole>(`/api/roles/id/${id}`, {
29
+ return useNuxtApp().$api<TRole>(`/api/roles/id/${id}`, {
30
30
  method: "GET",
31
31
  });
32
32
  }
@@ -36,28 +36,28 @@ export default function useRole() {
36
36
  name?: string,
37
37
  permissions?: Array<string>
38
38
  ) {
39
- return $fetch(`/api/roles/id/${_id}`, {
39
+ return useNuxtApp().$api(`/api/roles/id/${_id}`, {
40
40
  method: "PATCH",
41
41
  body: { name, permissions },
42
42
  });
43
43
  }
44
44
 
45
45
  function updatePermissionById(_id: string, permissions?: Array<string>) {
46
- return $fetch(`/api/roles/permissions/id/${_id}`, {
46
+ return useNuxtApp().$api(`/api/roles/permissions/id/${_id}`, {
47
47
  method: "PATCH",
48
48
  body: { permissions },
49
49
  });
50
50
  }
51
51
 
52
52
  function updateRoleFieldById(_id: string, field: string, value: string) {
53
- return $fetch(`/api/roles/${_id}`, {
53
+ return useNuxtApp().$api(`/api/roles/${_id}`, {
54
54
  method: "PATCH",
55
55
  body: { field, value },
56
56
  });
57
57
  }
58
58
 
59
59
  function deleteRole(_id: string) {
60
- return $fetch<Record<string, any>>(`/api/roles/${_id}`, {
60
+ return useNuxtApp().$api<Record<string, any>>(`/api/roles/${_id}`, {
61
61
  method: "DELETE",
62
62
  });
63
63
  }
@@ -6,9 +6,12 @@ export default function useSchool() {
6
6
  limit = 20,
7
7
  psgc = "",
8
8
  } = {}) {
9
- return $fetch<Record<string, any>>("/api/basic-education/schools", {
10
- query: { page, search, status, limit, psgc },
11
- });
9
+ return useNuxtApp().$api<Record<string, any>>(
10
+ "/api/basic-education/schools",
11
+ {
12
+ query: { page, search, status, limit, psgc },
13
+ }
14
+ );
12
15
  }
13
16
 
14
17
  return {
@@ -4,7 +4,7 @@ export default function useSubscription() {
4
4
  trialDays: number,
5
5
  productId: string
6
6
  ) {
7
- return $fetch("/api/subscriptions/plan", {
7
+ return useNuxtApp().$api("/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 $fetch("/api/subscriptions", {
18
+ return useNuxtApp().$api("/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 $fetch(`/api/subscriptions/billing-contact/${id}`, {
28
+ return useNuxtApp().$api(`/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 $fetch(
41
+ return useNuxtApp().$api(
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 $fetch(
53
+ return useNuxtApp().$api(
54
54
  `/api/subscriptions/billing-contact/${id}/added-at/${addedAt}`,
55
55
  {
56
56
  method: "DELETE",
@@ -59,27 +59,33 @@ export default function useSubscription() {
59
59
  }
60
60
 
61
61
  function getById(id: string) {
62
- return $fetch<TSubscription>(`/api/subscriptions/id/${id}`);
62
+ return useNuxtApp().$api<TSubscription>(`/api/subscriptions/id/${id}`);
63
63
  }
64
64
 
65
65
  function getByAffiliateId(id: string) {
66
- return $fetch<TSubscription>(`/api/subscriptions/affiliate/${id}`);
66
+ return useNuxtApp().$api<TSubscription>(
67
+ `/api/subscriptions/affiliate/${id}`
68
+ );
67
69
  }
68
70
 
69
71
  function getByOrgId(id: string) {
70
- return $fetch<Record<string, any>>(`/api/subscriptions/org/${id}`);
72
+ return useNuxtApp().$api<Record<string, any>>(
73
+ `/api/subscriptions/org/${id}`
74
+ );
71
75
  }
72
76
 
73
77
  function getSubscriptions() {
74
- return $fetch("/api/subscriptions");
78
+ return useNuxtApp().$api("/api/subscriptions");
75
79
  }
76
80
 
77
81
  function getSubscriptionStatusById(id: string) {
78
- return $fetch<Record<string, string>>(`/api/subscriptions/status/${id}`);
82
+ return useNuxtApp().$api<Record<string, string>>(
83
+ `/api/subscriptions/status/${id}`
84
+ );
79
85
  }
80
86
 
81
87
  function cancelSubscription(id: string) {
82
- return $fetch(`/api/subscriptions/cancel/${id}`, {
88
+ return useNuxtApp().$api(`/api/subscriptions/cancel/${id}`, {
83
89
  method: "DELETE",
84
90
  });
85
91
  }
@@ -90,7 +96,7 @@ export default function useSubscription() {
90
96
  );
91
97
 
92
98
  function updatePromoCodeById(id: string, promoCode: string) {
93
- return $fetch(`/api/subscriptions/promo-code/${id}`, {
99
+ return useNuxtApp().$api(`/api/subscriptions/promo-code/${id}`, {
94
100
  method: "PUT",
95
101
  body: {
96
102
  promoCode,
@@ -99,7 +105,7 @@ export default function useSubscription() {
99
105
  }
100
106
 
101
107
  function updateStatusById(id: string, status: string) {
102
- return $fetch(`/api/subscriptions/status/${id}`, {
108
+ return useNuxtApp().$api(`/api/subscriptions/status/${id}`, {
103
109
  method: "PUT",
104
110
  body: {
105
111
  status,
@@ -108,7 +114,7 @@ export default function useSubscription() {
108
114
  }
109
115
 
110
116
  function updatePaymentMethodById(id: string, paymentMethodId: string) {
111
- return $fetch(`/api/subscriptions/payment-method/${id}`, {
117
+ return useNuxtApp().$api(`/api/subscriptions/payment-method/${id}`, {
112
118
  method: "PUT",
113
119
  body: {
114
120
  paymentMethodId,
@@ -162,17 +168,23 @@ export default function useSubscription() {
162
168
  };
163
169
 
164
170
  function initOrgSubscription(value: TSub) {
165
- return $fetch<Record<string, any>>("/api/subscriptions/organization", {
166
- method: "POST",
167
- body: value,
168
- });
171
+ return useNuxtApp().$api<Record<string, any>>(
172
+ "/api/subscriptions/organization",
173
+ {
174
+ method: "POST",
175
+ body: value,
176
+ }
177
+ );
169
178
  }
170
179
 
171
180
  function initAffiliateSubscription(value: TSub) {
172
- return $fetch<Record<string, any>>("/api/subscriptions/affiliate", {
173
- method: "POST",
174
- body: value,
175
- });
181
+ return useNuxtApp().$api<Record<string, any>>(
182
+ "/api/subscriptions/affiliate",
183
+ {
184
+ method: "POST",
185
+ body: value,
186
+ }
187
+ );
176
188
  }
177
189
 
178
190
  function updateSeatsById({
@@ -181,7 +193,7 @@ export default function useSubscription() {
181
193
  seats = 0,
182
194
  amount = 0,
183
195
  } = {}) {
184
- return $fetch<Record<string, any>>(
196
+ return useNuxtApp().$api<Record<string, any>>(
185
197
  `/api/subscriptions/seats/${subscriptionId}`,
186
198
  {
187
199
  method: "PUT",
@@ -195,7 +207,7 @@ export default function useSubscription() {
195
207
  }
196
208
 
197
209
  function processSubscriptionPayment(id: string, invoice: string) {
198
- return $fetch(`/api/subscriptions/payment/id/${id}`, {
210
+ return useNuxtApp().$api(`/api/subscriptions/payment/id/${id}`, {
199
211
  method: "PUT",
200
212
  body: {
201
213
  invoice,
@@ -218,7 +230,7 @@ export default function useSubscription() {
218
230
  type: string;
219
231
  };
220
232
  }) {
221
- return $fetch("/api/subscriptions/subscribe", {
233
+ return useNuxtApp().$api("/api/subscriptions/subscribe", {
222
234
  method: "POST",
223
235
  body: value,
224
236
  });
@@ -7,49 +7,49 @@ export default function useUser() {
7
7
  org = "",
8
8
  orgName = "",
9
9
  } = {}) {
10
- return $fetch<Record<string, any>>("/api/auth/invite", {
10
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/users/name", {
17
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/users/birthday", {
24
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/users/gender", {
31
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/users/email", {
38
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/users/contact", {
45
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>(`/api/users/field/${id}`, {
52
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>("/api/users", {
64
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>(`/api/users/id/${id}`, {
71
+ return useNuxtApp().$api<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 $fetch<Record<string, any>>(`/api/users/invite/${id}`, {
84
+ return useNuxtApp().$api<Record<string, any>>(`/api/users/invite/${id}`, {
85
85
  method: "POST",
86
86
  body: { firstName, lastName, password, referralCode, type },
87
87
  });
@@ -136,7 +136,7 @@ export default function useUtils() {
136
136
 
137
137
  async function getCountries() {
138
138
  try {
139
- const countries = await $fetch<Array<Record<string, any>>>(
139
+ const countries = await useNuxtApp().$api<Array<Record<string, any>>>(
140
140
  "https://restcountries.com/v3.1/all?fields=name,currencies,idd",
141
141
  { method: "GET" }
142
142
  );
@@ -7,7 +7,7 @@ export default function useUser() {
7
7
  email = "",
8
8
  app = "",
9
9
  } = {}) {
10
- return $fetch<Record<string, any>>("/api/verifications", {
10
+ return useNuxtApp().$api<Record<string, any>>("/api/verifications", {
11
11
  method: "GET",
12
12
  query: { status, search, page, type, email, app },
13
13
  });
package/nuxt.config.ts CHANGED
@@ -15,6 +15,7 @@ export default defineNuxtConfig({
15
15
  secure: true,
16
16
  maxAge: 30 * 24 * 60 * 60,
17
17
  },
18
+ API_CORE: (process.env.API_CORE as string) ?? "http://localhost:5001",
18
19
  APP: (process.env.APP as string) ?? "App",
19
20
  APP_NAME: (process.env.APP_NAME as string) ?? "App",
20
21
  APP_NAME_ROUTE: (process.env.APP_NAME_ROUTE as string) ?? "index",
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.7.17",
5
+ "version": "1.7.19",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
package/plugins/API.ts ADDED
@@ -0,0 +1,18 @@
1
+ export default defineNuxtPlugin(() => {
2
+ const { cookieConfig } = useRuntimeConfig().public;
3
+
4
+ const api = $fetch.create({
5
+ baseURL: useRuntimeConfig().public.API_CORE,
6
+ credentials: "include",
7
+ headers: {
8
+ cookie: `domain=${cookieConfig.domain}; Max-Age=${cookieConfig.maxAge}; Secure=${cookieConfig.secure}`,
9
+ },
10
+ });
11
+
12
+ // Expose to useNuxtApp().$api
13
+ return {
14
+ provide: {
15
+ api,
16
+ },
17
+ };
18
+ });