@goweekdays/layer-common 0.0.7 → 0.0.8

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,11 @@
1
1
  # @goweekdays/layer-common
2
2
 
3
+ ## 0.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - b47a001: revise promo code query
8
+
3
9
  ## 0.0.7
4
10
 
5
11
  ### Patch Changes
@@ -17,13 +17,15 @@ export default function usePromoCode() {
17
17
  });
18
18
  }
19
19
 
20
- function getByCode(code: string) {
21
- return useNuxtApp().$api<Record<string, any>>(
22
- `/api/promo-codes/code/${code}`,
23
- {
24
- method: "GET",
25
- }
26
- );
20
+ function getByCode(code: string, type?: string, assigned?: boolean) {
21
+ return useNuxtApp().$api<Record<string, any>>("/api/promo-codes/code", {
22
+ method: "GET",
23
+ params: {
24
+ code,
25
+ type,
26
+ assigned,
27
+ },
28
+ });
27
29
  }
28
30
 
29
31
  return {
@@ -89,6 +89,7 @@ export default function useSubscription() {
89
89
  seats?: number;
90
90
  organization?: TOrg;
91
91
  billingAddress: TAddress;
92
+ promoCode?: string;
92
93
  };
93
94
 
94
95
  function initOrgSubscription(value: TSub) {
@@ -189,6 +189,25 @@ export default function useUtils() {
189
189
  // console.log(formatNumber(1234.56, { useSymbol: true, currency: "EUR", locale: "de-DE" })); // "1.234,56 €"
190
190
  // console.log(formatNumber(1234.56, { useSymbol: true, currency: "EUR", locale: "de-DE", decimalPlaces: 0 })); // "1.234 €"
191
191
 
192
+ function computeTieredCost(seats: number, tiers: TPromoTier[]) {
193
+ let totalCost = 0;
194
+
195
+ for (let i = 0; i < tiers.length; i++) {
196
+ let { min, max, price } = tiers[i];
197
+
198
+ if (max === 0) max = Infinity; // Handle unlimited tier
199
+
200
+ if (seats >= min) {
201
+ let seatsInTier = Math.min(seats, max) - min + 1;
202
+ totalCost += seatsInTier * price;
203
+ }
204
+
205
+ if (seats <= max) break; // Stop when all seats are counted
206
+ }
207
+
208
+ return totalCost;
209
+ }
210
+
192
211
  return {
193
212
  requiredRule,
194
213
  emailRule,
@@ -207,5 +226,6 @@ export default function useUtils() {
207
226
  formatNumber,
208
227
  validateDate,
209
228
  minOneMonthAdvance,
229
+ computeTieredCost,
210
230
  };
211
231
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@goweekdays/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.0.7",
5
+ "version": "0.0.8",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"