@managesome/eposmatic-toolkit 0.2.319 → 0.2.320

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.
@@ -68,6 +68,7 @@ export * from './void-warehouse-invoice-items-helpers';
68
68
  export * from './void-warehouse-invoice-items-report-helpers';
69
69
  export * from './voidations-summary-report-helpers';
70
70
  export * from './wallet-helpers';
71
+ export * from './wallet-redemption-helpers';
71
72
  export * from './warehouse-catalog-conversion';
72
73
  export * from './warehouse-inventory';
73
74
  export * from './warehouse-invoice-order-engine';
@@ -84,6 +84,7 @@ __exportStar(require("./void-warehouse-invoice-items-helpers"), exports);
84
84
  __exportStar(require("./void-warehouse-invoice-items-report-helpers"), exports);
85
85
  __exportStar(require("./voidations-summary-report-helpers"), exports);
86
86
  __exportStar(require("./wallet-helpers"), exports);
87
+ __exportStar(require("./wallet-redemption-helpers"), exports);
87
88
  __exportStar(require("./warehouse-catalog-conversion"), exports);
88
89
  __exportStar(require("./warehouse-inventory"), exports);
89
90
  __exportStar(require("./warehouse-invoice-order-engine"), exports);
@@ -0,0 +1,18 @@
1
+ import { GIFT_CARD_REWARD_TYPE_ENUM } from '../../constants';
2
+ export interface IWalletGiftCardRedemptionCompat {
3
+ gift_card_id?: string | null;
4
+ mystery_gift_type?: GIFT_CARD_REWARD_TYPE_ENUM | null;
5
+ redeemed_times?: number | null;
6
+ value_redeemed?: number | null;
7
+ }
8
+ export type TWalletGiftCardRedemptionsCompatInput = IWalletGiftCardRedemptionCompat | IWalletGiftCardRedemptionCompat[] | null | undefined;
9
+ export interface IWalletGiftCardClaim {
10
+ gift_card_id: string;
11
+ redeemed_times: number;
12
+ mystery_gift_type?: GIFT_CARD_REWARD_TYPE_ENUM | null;
13
+ }
14
+ export declare function getWalletGiftCardRedemptionClaims(walletGiftCardRedemptions: TWalletGiftCardRedemptionsCompatInput): IWalletGiftCardClaim[];
15
+ export declare function buildWalletGiftCardRedemptionCompatPayload({ currentWalletGiftCardRedemptions, nextWalletGiftCardClaims, }: {
16
+ currentWalletGiftCardRedemptions: TWalletGiftCardRedemptionsCompatInput;
17
+ nextWalletGiftCardClaims: IWalletGiftCardClaim[];
18
+ }): IWalletGiftCardRedemptionCompat | IWalletGiftCardClaim[] | null;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWalletGiftCardRedemptionClaims = getWalletGiftCardRedemptionClaims;
4
+ exports.buildWalletGiftCardRedemptionCompatPayload = buildWalletGiftCardRedemptionCompatPayload;
5
+ function getWalletGiftCardRedemptionClaims(walletGiftCardRedemptions) {
6
+ const normalizedWalletGiftCardRedemptions = Array.isArray(walletGiftCardRedemptions)
7
+ ? walletGiftCardRedemptions
8
+ : walletGiftCardRedemptions != null
9
+ ? [walletGiftCardRedemptions]
10
+ : [];
11
+ const claimsByGiftCardId = {};
12
+ for (let i = 0; i < normalizedWalletGiftCardRedemptions.length; i++) {
13
+ const walletGiftCardRedemption = normalizedWalletGiftCardRedemptions[i];
14
+ const giftCardId = walletGiftCardRedemption.gift_card_id?.trim();
15
+ const redeemedTimes = Number(walletGiftCardRedemption.redeemed_times ?? walletGiftCardRedemption.value_redeemed ?? 0);
16
+ if (giftCardId == null || giftCardId.length === 0 || !Number.isFinite(redeemedTimes) || redeemedTimes <= 0) {
17
+ continue;
18
+ }
19
+ const existingClaim = claimsByGiftCardId[giftCardId];
20
+ claimsByGiftCardId[giftCardId] = {
21
+ gift_card_id: giftCardId,
22
+ redeemed_times: (existingClaim?.redeemed_times ?? 0) + Math.floor(redeemedTimes),
23
+ ...(walletGiftCardRedemption.mystery_gift_type != null
24
+ ? {
25
+ mystery_gift_type: walletGiftCardRedemption.mystery_gift_type,
26
+ }
27
+ : existingClaim?.mystery_gift_type != null
28
+ ? {
29
+ mystery_gift_type: existingClaim.mystery_gift_type,
30
+ }
31
+ : {}),
32
+ };
33
+ }
34
+ return Object.values(claimsByGiftCardId);
35
+ }
36
+ function buildWalletGiftCardRedemptionCompatPayload({ currentWalletGiftCardRedemptions, nextWalletGiftCardClaims, }) {
37
+ if (Array.isArray(currentWalletGiftCardRedemptions)) {
38
+ return nextWalletGiftCardClaims;
39
+ }
40
+ const nextWalletGiftCardClaim = nextWalletGiftCardClaims[0];
41
+ if (nextWalletGiftCardClaim == null) {
42
+ return null;
43
+ }
44
+ return {
45
+ gift_card_id: nextWalletGiftCardClaim.gift_card_id,
46
+ mystery_gift_type: nextWalletGiftCardClaim.mystery_gift_type,
47
+ value_redeemed: nextWalletGiftCardClaim.redeemed_times,
48
+ redeemed_times: nextWalletGiftCardClaim.redeemed_times,
49
+ };
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.319",
3
+ "version": "0.2.320",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",