@goweekdays/layer-common 1.0.0 → 1.0.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.
@@ -1,26 +1,37 @@
1
1
  export default function useOrg() {
2
- function getOrgs({ page = 1, search = "", user = "", limit = 20 } = {}) {
2
+ function getAll({ page = 1, search = "", limit = 20 } = {}) {
3
3
  return useNuxtApp().$api<Record<string, any>>("/api/organizations", {
4
4
  method: "GET",
5
5
  query: {
6
6
  page,
7
7
  search,
8
- user,
9
8
  limit,
10
9
  },
11
10
  });
12
11
  }
13
12
 
14
- const org = useState("org", (): TOrg => {
15
- return {
16
- _id: "",
17
- name: "",
18
- email: "",
19
- contact: "",
20
- busInst: "",
21
- type: "",
22
- status: "",
23
- };
13
+ function getByUserId({ page = 1, search = "", user = "", limit = 20 } = {}) {
14
+ return useNuxtApp().$api<Record<string, any>>(
15
+ `/api/organizations/user/${user}`,
16
+ {
17
+ method: "GET",
18
+ query: {
19
+ page,
20
+ search,
21
+ limit,
22
+ },
23
+ }
24
+ );
25
+ }
26
+
27
+ const org = ref({
28
+ _id: "",
29
+ name: "",
30
+ email: "",
31
+ contact: "",
32
+ busInst: "",
33
+ type: "",
34
+ status: "",
24
35
  });
25
36
 
26
37
  function reset() {
@@ -71,7 +82,8 @@ export default function useOrg() {
71
82
 
72
83
  return {
73
84
  org,
74
- getOrgs,
85
+ getAll,
86
+ getByUserId,
75
87
  reset,
76
88
  set,
77
89
  perSeatPrice,
@@ -0,0 +1,27 @@
1
+ export function useOrgPermission() {
2
+ const { memberPermissions, rolePermissions, invitationPermission } =
3
+ useCommonPermissions();
4
+ const permissions: TPermissions = {
5
+ organizations: {
6
+ "create-organization": {
7
+ check: true,
8
+ description: "Create Organization",
9
+ },
10
+ "view-organization": {
11
+ check: true,
12
+ description: "View Organization",
13
+ },
14
+ "view-organization-details": {
15
+ check: true,
16
+ description: "View Organization Details",
17
+ },
18
+ },
19
+ members: memberPermissions,
20
+ invitations: invitationPermission,
21
+ roles: rolePermissions,
22
+ };
23
+
24
+ return {
25
+ permissions,
26
+ };
27
+ }
@@ -1,14 +1,15 @@
1
1
  export default function useRole() {
2
2
  function createRole(
3
- { name, permissions, type } = {} as {
3
+ { name, permissions, type, org } = {} as {
4
4
  name: string;
5
5
  permissions: Array<string>;
6
6
  type: string;
7
+ org: string;
7
8
  }
8
9
  ) {
9
10
  return useNuxtApp().$api("/api/roles", {
10
11
  method: "POST",
11
- body: { name, permissions, type },
12
+ body: { name, permissions, type, org },
12
13
  });
13
14
  }
14
15
 
@@ -57,7 +58,7 @@ export default function useRole() {
57
58
  }
58
59
 
59
60
  function deleteRole(_id: string) {
60
- return useNuxtApp().$api(`/api/roles/${_id}`, {
61
+ return useNuxtApp().$api<Record<string, any>>(`/api/roles/${_id}`, {
61
62
  method: "DELETE",
62
63
  });
63
64
  }
@@ -66,6 +67,7 @@ export default function useRole() {
66
67
  return {
67
68
  _id: "",
68
69
  name: "",
70
+ org: "",
69
71
  permissions: [],
70
72
  createdAt: "",
71
73
  updatedAt: "",
@@ -0,0 +1,13 @@
1
+ export function useSchoolPermission() {
2
+ const { memberPermissions, rolePermissions, invitationPermission } =
3
+ useCommonPermissions();
4
+ const permissions: TPermissions = {
5
+ members: memberPermissions,
6
+ invitations: invitationPermission,
7
+ roles: rolePermissions,
8
+ };
9
+
10
+ return {
11
+ permissions,
12
+ };
13
+ }
@@ -69,7 +69,9 @@ export default function useSubscription() {
69
69
  }
70
70
 
71
71
  function getByOrgId(id: string) {
72
- return useNuxtApp().$api<TSubscription>(`/api/subscriptions/org/${id}`);
72
+ return useNuxtApp().$api<Record<string, any>>(
73
+ `/api/subscriptions/org/${id}`
74
+ );
73
75
  }
74
76
 
75
77
  function getSubscriptions() {
@@ -186,6 +188,7 @@ export default function useSubscription() {
186
188
  }
187
189
 
188
190
  function updateSeatsById({
191
+ transactionId = "",
189
192
  subscriptionId = "",
190
193
  seats = 0,
191
194
  amount = 0,
@@ -197,6 +200,7 @@ export default function useSubscription() {
197
200
  body: {
198
201
  seats,
199
202
  amount,
203
+ transactionId,
200
204
  },
201
205
  }
202
206
  );
@@ -213,7 +217,7 @@ export default function useSubscription() {
213
217
 
214
218
  function addOrgSubscription(value: {
215
219
  user: string;
216
- transactionId: string;
220
+ transactionId?: string;
217
221
  promoCode?: string;
218
222
  seats: number;
219
223
  perSeatPrice: number;
@@ -1,48 +1,48 @@
1
1
  export default function useUser() {
2
2
  function inviteUser({ email = "", app = "", role = "", name = "" } = {}) {
3
- return useNuxtApp().$api<TKeyValuePair>("/api/auth/invite", {
3
+ return useNuxtApp().$api<Record<string, any>>("/api/auth/invite", {
4
4
  method: "POST",
5
5
  body: { email, app, role, name },
6
6
  });
7
7
  }
8
8
 
9
9
  function updateName({ firstName = "", lastName = "" } = {}) {
10
- return useNuxtApp().$api<TKeyValuePair>("/api/users/name", {
10
+ return useNuxtApp().$api<Record<string, any>>("/api/users/name", {
11
11
  method: "PUT",
12
12
  body: { firstName, lastName },
13
13
  });
14
14
  }
15
15
 
16
16
  function updateBirthday({ month = "", day = 0, year = 0 } = {}) {
17
- return useNuxtApp().$api<TKeyValuePair>("/api/users/birthday", {
17
+ return useNuxtApp().$api<Record<string, any>>("/api/users/birthday", {
18
18
  method: "PUT",
19
19
  body: { month, day, year },
20
20
  });
21
21
  }
22
22
 
23
23
  function updateGender(gender = "") {
24
- return useNuxtApp().$api<TKeyValuePair>("/api/users/gender", {
24
+ return useNuxtApp().$api<Record<string, any>>("/api/users/gender", {
25
25
  method: "PUT",
26
26
  body: { gender },
27
27
  });
28
28
  }
29
29
 
30
30
  function updateEmail(email = "") {
31
- return useNuxtApp().$api<TKeyValuePair>("/api/users/email", {
31
+ return useNuxtApp().$api<Record<string, any>>("/api/users/email", {
32
32
  method: "PUT",
33
33
  body: { email },
34
34
  });
35
35
  }
36
36
 
37
37
  function updateContact(contact = "") {
38
- return useNuxtApp().$api<TKeyValuePair>("/api/users/contact", {
38
+ return useNuxtApp().$api<Record<string, any>>("/api/users/contact", {
39
39
  method: "PUT",
40
40
  body: { contact },
41
41
  });
42
42
  }
43
43
 
44
44
  function updateUserFieldById(id = "", field = "", value = "") {
45
- return useNuxtApp().$api<TKeyValuePair>(`/api/users/field/${id}`, {
45
+ return useNuxtApp().$api<Record<string, any>>(`/api/users/field/${id}`, {
46
46
  method: "PATCH",
47
47
  body: { field, value },
48
48
  });
@@ -54,14 +54,14 @@ export default function useUser() {
54
54
  search = "",
55
55
  page = 1,
56
56
  } = {}) {
57
- return useNuxtApp().$api<TKeyValuePair>("/api/users", {
57
+ return useNuxtApp().$api<Record<string, any>>("/api/users", {
58
58
  method: "GET",
59
59
  query: { status, search, page, type },
60
60
  });
61
61
  }
62
62
 
63
63
  function getById(id = "") {
64
- return useNuxtApp().$api<TKeyValuePair>(`/api/users/id/${id}`, {
64
+ return useNuxtApp().$api<Record<string, any>>(`/api/users/id/${id}`, {
65
65
  method: "GET",
66
66
  });
67
67
  }
@@ -74,7 +74,7 @@ export default function useUser() {
74
74
  referralCode = "",
75
75
  type = "",
76
76
  } = {}) {
77
- return useNuxtApp().$api<TKeyValuePair>(`/api/users/invite/${id}`, {
77
+ return useNuxtApp().$api<Record<string, any>>(`/api/users/invite/${id}`, {
78
78
  method: "POST",
79
79
  body: { firstName, lastName, password, referralCode, type },
80
80
  });
@@ -199,23 +199,32 @@ export default function useUtils() {
199
199
  // console.log(formatNumber(1234.56, { useSymbol: true, currency: "EUR", locale: "de-DE" })); // "1.234,56 €"
200
200
  // console.log(formatNumber(1234.56, { useSymbol: true, currency: "EUR", locale: "de-DE", decimalPlaces: 0 })); // "1.234 €"
201
201
 
202
- function computeTieredCost(seats: number, tiers: TPromoTier[]) {
202
+ function computeTieredCost(
203
+ seats: number,
204
+ tiers: { min: number; max: number; price: number }[],
205
+ remainingDays?: number,
206
+ totalDaysInMonth?: number
207
+ ) {
203
208
  let totalCost = 0;
204
209
 
205
- for (let i = 0; i < tiers.length; i++) {
206
- let { min, max, price } = tiers[i];
210
+ for (let i = 1; i <= seats; i++) {
211
+ for (const { min, max, price } of tiers) {
212
+ const effectiveMax = max === 0 ? Infinity : max;
207
213
 
208
- if (max === 0) max = Infinity; // Handle unlimited tier
214
+ if (i >= min && i <= effectiveMax) {
215
+ // Prorate the cost for this seat based on its tier price
216
+ if (remainingDays && totalDaysInMonth) {
217
+ totalCost += price * (remainingDays / totalDaysInMonth);
218
+ break;
219
+ }
209
220
 
210
- if (seats >= min) {
211
- let seatsInTier = Math.min(seats, max) - min + 1;
212
- totalCost += seatsInTier * price;
221
+ totalCost += price;
222
+ break; // Stop checking once we apply the correct tier pricing
223
+ }
213
224
  }
214
-
215
- if (seats <= max) break; // Stop when all seats are counted
216
225
  }
217
226
 
218
- return totalCost;
227
+ return totalCost; // This now returns the total prorated cost
219
228
  }
220
229
 
221
230
  function convertPermissionsToArray(permissions: TPermissions) {
package/nuxt.config.ts CHANGED
@@ -28,6 +28,7 @@ export default defineNuxtConfig({
28
28
  APP_ACCOUNTING: (process.env.APP_ACCOUNTING as string) ?? "",
29
29
  APP_BOOK_KEEPING: (process.env.APP_BOOK_KEEPING as string) ?? "",
30
30
  APP_ZONAL: (process.env.APP_ZONAL as string) ?? "",
31
+ APP_SCHOOL: (process.env.APP_SCHOOL as string) ?? "",
31
32
  },
32
33
  },
33
34
 
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.0.0",
5
+ "version": "1.0.1",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
package/types/org.d.ts CHANGED
@@ -5,6 +5,7 @@ declare type TOrg = {
5
5
  contact: string;
6
6
  busInst: string;
7
7
  type: string;
8
+ apps?: Array<string>;
8
9
  createdAt?: string;
9
10
  updatedAt?: string;
10
11
  status?: string;
package/types/role.d.ts CHANGED
@@ -3,6 +3,7 @@ declare type TRole = {
3
3
  name?: string;
4
4
  permissions?: Array<string>;
5
5
  type?: string;
6
+ org: string;
6
7
  status?: string;
7
8
  default?: boolean;
8
9
  createdBy?: string;
package/types/user.d.ts CHANGED
@@ -7,8 +7,10 @@ declare type TUser = {
7
7
  lastName: string;
8
8
  suffix?: string;
9
9
  birthMonth?: string;
10
- birthDate?: string;
10
+ birthDay?: string;
11
11
  birthYear?: string;
12
+ gender?: string;
13
+ contact?: string;
12
14
  profile?: string;
13
15
  defaultOrg?: string;
14
16
  createdAt: string;