@eeplatform/nuxt-layer-common 1.2.0 → 1.2.2

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.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 49f4a58: Revise authentication implementation
8
+
9
+ ## 1.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - e217ab9: Admin school management adjustment
14
+
3
15
  ## 1.2.0
4
16
 
5
17
  ### Minor Changes
@@ -50,7 +50,7 @@ const prop = defineProps({
50
50
  route: {
51
51
  type: Object,
52
52
  default() {
53
- return { name: "", params: {} };
53
+ return { name: "", params: {}, query: {} };
54
54
  },
55
55
  },
56
56
  children: {
@@ -114,7 +114,7 @@ const props = defineProps({
114
114
  type: Object,
115
115
  default: () => ({}),
116
116
  },
117
- org: {
117
+ id: {
118
118
  type: String,
119
119
  default: "",
120
120
  },
@@ -150,7 +150,7 @@ async function submit() {
150
150
  name: name.value,
151
151
  permissions: selectedPermissions.value,
152
152
  type: type.value,
153
- org: props.org,
153
+ id: props.id,
154
154
  });
155
155
 
156
156
  if (createMore.value) {
@@ -82,7 +82,7 @@
82
82
  <RolePermissionFormCreate
83
83
  @cancel="createDialog = false"
84
84
  :permissions="props.permissions"
85
- :org="props.orgId"
85
+ :id="props.id"
86
86
  @success="success()"
87
87
  v-model:type="type"
88
88
  :types="props.types"
@@ -144,7 +144,7 @@
144
144
 
145
145
  <script setup lang="ts">
146
146
  const props = defineProps({
147
- orgId: {
147
+ id: {
148
148
  type: String,
149
149
  default: "",
150
150
  },
@@ -224,7 +224,7 @@ const {
224
224
  page: page.value,
225
225
  search: headerSearch.value,
226
226
  type: type.value,
227
- org: props.orgId,
227
+ id: props.id,
228
228
  }),
229
229
  {
230
230
  watch: [page, headerSearch],
@@ -0,0 +1,64 @@
1
+ export default function useDivision() {
2
+ function getAll({ page = 1, search = "", limit = 20, region = "" } = {}) {
3
+ return useNuxtApp().$api<Record<string, any>>("/api/divisions", {
4
+ method: "GET",
5
+ query: {
6
+ page,
7
+ search,
8
+ limit,
9
+ region,
10
+ },
11
+ });
12
+ }
13
+
14
+ function getById(id = "") {
15
+ return useNuxtApp().$api<Record<string, any>>(`/api/divisions/id/${id}`, {
16
+ method: "GET",
17
+ });
18
+ }
19
+
20
+ function getByName(name = "") {
21
+ return useNuxtApp().$api(`/api/divisions/name/${name}`, {
22
+ method: "GET",
23
+ });
24
+ }
25
+
26
+ function createDivision(data: Record<string, any>) {
27
+ return useNuxtApp().$api("/api/divisions", {
28
+ method: "POST",
29
+ body: data,
30
+ });
31
+ }
32
+
33
+ function updateDivisionField(id: string, field: string, value: string) {
34
+ return useNuxtApp().$api(`/api/divisions/${id}`, {
35
+ method: "PATCH",
36
+ body: { field, value },
37
+ });
38
+ }
39
+
40
+ function deleteDivision(id: string) {
41
+ return useNuxtApp().$api(`/api/divisions/${id}`, {
42
+ method: "DELETE",
43
+ });
44
+ }
45
+
46
+ const division = ref({
47
+ _id: "",
48
+ name: "",
49
+ region: "",
50
+ regionName: "",
51
+ superintendent: "",
52
+ superintendentName: "",
53
+ });
54
+
55
+ return {
56
+ division,
57
+ getAll,
58
+ getById,
59
+ getByName,
60
+ createDivision,
61
+ updateDivisionField,
62
+ deleteDivision,
63
+ };
64
+ }
@@ -30,19 +30,19 @@ export default function useLocal() {
30
30
  title: "School",
31
31
  icon: "ph:building-bold",
32
32
  link: APP_SCHOOL as string,
33
- landingPage: "home",
33
+ landingPage: "",
34
34
  },
35
35
  {
36
36
  title: "Division",
37
37
  icon: "ph:building-apartment-bold",
38
38
  link: APP_DIVISION as string,
39
- landingPage: "home",
39
+ landingPage: "",
40
40
  },
41
41
  {
42
42
  title: "Region",
43
43
  icon: "ph:buildings-bold",
44
44
  link: APP_REGION as string,
45
- landingPage: "home",
45
+ landingPage: "",
46
46
  },
47
47
  ];
48
48
  });
@@ -38,7 +38,7 @@ export default function useLocalAuth() {
38
38
  }
39
39
 
40
40
  async function login({ email = "", password = "", role = "" }) {
41
- return useNuxtApp().$api<TKeyValuePair>("/api/auth/login", {
41
+ return useNuxtApp().$api<Record<string, any>>("/api/auth/login", {
42
42
  method: "POST",
43
43
  body: JSON.stringify({ email, password, role }),
44
44
  });
@@ -78,19 +78,17 @@ export default function useLocalAuth() {
78
78
  }
79
79
  }
80
80
 
81
- async function getCurrentUser() {
81
+ function getCurrentUser() {
82
82
  const user = useCookie("user", cookieConfig).value;
83
- if (!user) return null;
84
- try {
85
- const _user = await useNuxtApp().$api<TUser>(`/api/users/id/${user}`, {
86
- method: "GET",
87
- });
83
+ const { data: userData } = useLazyAsyncData("get-current-user", () =>
84
+ useNuxtApp().$api<TUser>(`/api/users/id/${user}`)
85
+ );
88
86
 
89
- currentUser.value = _user;
90
- return _user;
91
- } catch (error) {
92
- console.log("Error fetching current user:", error);
93
- }
87
+ watchEffect(() => {
88
+ if (userData.value) {
89
+ currentUser.value = userData.value;
90
+ }
91
+ });
94
92
  }
95
93
 
96
94
  async function forgotPassword(email: string) {
@@ -129,13 +127,13 @@ export default function useLocalAuth() {
129
127
  }
130
128
 
131
129
  function verify(id: string) {
132
- return useNuxtApp().$api<TKeyValuePair>(`/api/auth/verify/${id}`, {
130
+ return useNuxtApp().$api<Record<string, any>>(`/api/auth/verify/${id}`, {
133
131
  method: "GET",
134
132
  });
135
133
  }
136
134
 
137
135
  function signUp(email: string, referral: string) {
138
- return useNuxtApp().$api<TKeyValuePair>("/api/auth/sign-up", {
136
+ return useNuxtApp().$api<Record<string, any>>("/api/auth/sign-up", {
139
137
  method: "POST",
140
138
  body: { email, referral },
141
139
  });
@@ -1,14 +1,12 @@
1
1
  export function useLocalSetup(type: string, org?: string) {
2
- const { currentUser } = useLocalAuth();
3
-
4
- const userId = computed(() => currentUser.value?._id ?? "");
2
+ const userId = computed(() => useCookie("user").value ?? "");
5
3
 
6
4
  const { getByUserType } = useMember();
7
5
 
8
6
  const { data: userMemberData, error: userMemberError } = useLazyAsyncData(
9
7
  "get-member-by-id",
10
8
  () => getByUserType(userId.value, type, org),
11
- { watch: [userId], immediate: false }
9
+ { watch: [userId] }
12
10
  );
13
11
 
14
12
  watchEffect(() => {
@@ -40,7 +38,10 @@ export function useLocalSetup(type: string, org?: string) {
40
38
  }
41
39
  });
42
40
 
41
+ const id = computed(() => userMemberData.value?.org ?? "id");
42
+
43
43
  return {
44
44
  userAppRole,
45
+ id,
45
46
  };
46
47
  }
@@ -0,0 +1,62 @@
1
+ export default function useRegion() {
2
+ function getAll({ page = 1, search = "", limit = 20 } = {}) {
3
+ return useNuxtApp().$api<Record<string, any>>("/api/regions", {
4
+ method: "GET",
5
+ query: {
6
+ page,
7
+ search,
8
+ limit,
9
+ },
10
+ });
11
+ }
12
+
13
+ function getById(id = "") {
14
+ return useNuxtApp().$api<Record<string, any>>(`/api/regions/id/${id}`, {
15
+ method: "GET",
16
+ });
17
+ }
18
+
19
+ function getByName(name = "") {
20
+ return useNuxtApp().$api(`/api/regions/name/${name}`, {
21
+ method: "GET",
22
+ });
23
+ }
24
+
25
+ function createRegion(data: Record<string, any>) {
26
+ return useNuxtApp().$api("/api/regions", {
27
+ method: "POST",
28
+ body: data,
29
+ });
30
+ }
31
+
32
+ function updateRegionField(id: string, field: string, value: string) {
33
+ return useNuxtApp().$api(`/api/regions/${id}`, {
34
+ method: "PATCH",
35
+ body: { field, value },
36
+ });
37
+ }
38
+
39
+ function deleteRegion(id: string) {
40
+ return useNuxtApp().$api(`/api/regions/${id}`, {
41
+ method: "DELETE",
42
+ });
43
+ }
44
+
45
+ const region = ref({
46
+ _id: "",
47
+ name: "",
48
+ director: "",
49
+ directorName: "",
50
+ });
51
+
52
+ return {
53
+ region,
54
+ getAll,
55
+ getById,
56
+ getByName,
57
+ createRegion,
58
+ updateRegionField,
59
+ deleteRegion,
60
+ };
61
+ }
62
+
@@ -1,15 +1,15 @@
1
1
  export default function useRole() {
2
2
  function createRole(
3
- { name, permissions, type, org } = {} as {
3
+ { name, permissions, type, id } = {} as {
4
4
  name: string;
5
5
  permissions: Array<string>;
6
6
  type: string;
7
- org: string;
7
+ id: string;
8
8
  }
9
9
  ) {
10
10
  return useNuxtApp().$api("/api/roles", {
11
11
  method: "POST",
12
- body: { name, permissions, type, org },
12
+ body: { name, permissions, type, id },
13
13
  });
14
14
  }
15
15
 
@@ -18,11 +18,11 @@ export default function useRole() {
18
18
  page = 1,
19
19
  limit = 20,
20
20
  type = "",
21
- org = "",
21
+ id = "",
22
22
  } = {}) {
23
23
  return useNuxtApp().$api<Record<string, any>>("/api/roles", {
24
24
  method: "GET",
25
- query: { search, page, limit, type, org },
25
+ query: { search, page, limit, type, id },
26
26
  });
27
27
  }
28
28
 
@@ -67,7 +67,7 @@ export default function useRole() {
67
67
  return {
68
68
  _id: "",
69
69
  name: "",
70
- org: "",
70
+ id: "",
71
71
  permissions: [],
72
72
  createdAt: "",
73
73
  updatedAt: "",
@@ -0,0 +1,46 @@
1
+ export default function useSchool() {
2
+ function registerSchool(school: TSchool) {
3
+ return useNuxtApp().$api("/api/schools/register", {
4
+ method: "POST",
5
+ body: school,
6
+ });
7
+ }
8
+
9
+ function getPendingByCreatedBy(createdBy: string) {
10
+ return useNuxtApp().$api<Record<string, any>>(
11
+ `/api/schools/createdBy/${createdBy}`,
12
+ {
13
+ method: "GET",
14
+ }
15
+ );
16
+ }
17
+
18
+ function approvedById(id: string) {
19
+ return useNuxtApp().$api<Record<string, any>>(
20
+ `/api/schools/approve/${id}`,
21
+ {
22
+ method: "PATCH",
23
+ }
24
+ );
25
+ }
26
+
27
+ function getAll({
28
+ page = 1,
29
+ status = "active",
30
+ search = "",
31
+ region = "",
32
+ division = "",
33
+ } = {}) {
34
+ return useNuxtApp().$api<Record<string, any>>("/api/schools", {
35
+ method: "GET",
36
+ query: { page, status, search, region, division },
37
+ });
38
+ }
39
+
40
+ return {
41
+ registerSchool,
42
+ getPendingByCreatedBy,
43
+ getAll,
44
+ approvedById,
45
+ };
46
+ }
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.2.0",
5
+ "version": "1.2.2",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
package/types/local.d.ts CHANGED
@@ -6,7 +6,8 @@ declare type TToken = {
6
6
 
7
7
  declare type TNavigationRoute = {
8
8
  name: string;
9
- params?: TKeyValuePair;
9
+ params?: Record<string, any>;
10
+ query?: Record<string, any>;
10
11
  };
11
12
 
12
13
  declare type TNavigationItem = {
@@ -16,10 +17,3 @@ declare type TNavigationItem = {
16
17
  children?: TNavigationItem[];
17
18
  disabled?: boolean;
18
19
  };
19
-
20
- declare type TKeyValuePair<
21
- K extends string | number | symbol = string,
22
- V = string | number | object | Array | TKeyValuePair
23
- > = {
24
- [key in K]: V;
25
- };
package/types/role.d.ts CHANGED
@@ -3,7 +3,7 @@ declare type TRole = {
3
3
  name?: string;
4
4
  permissions?: Array<string>;
5
5
  type?: string;
6
- org?: string;
6
+ id?: string;
7
7
  status?: string;
8
8
  default?: boolean;
9
9
  createdBy?: string;
@@ -0,0 +1,23 @@
1
+ declare type TSchool = {
2
+ _id?: string;
3
+ id: string;
4
+ name: string;
5
+ country: string;
6
+ address: string;
7
+ continuedAddress: string;
8
+ city: string;
9
+ province: string;
10
+ postalCode: string;
11
+ courses: Array<string>;
12
+ principalName: string;
13
+ principalEmail: string;
14
+ principalNumber: string;
15
+ region: string;
16
+ regionName?: string;
17
+ division: string;
18
+ divisionName?: string;
19
+ status?: string;
20
+ createdAt?: string;
21
+ updatedAt?: string;
22
+ createdBy?: string;
23
+ };