@managesome/eposmatic-toolkit 0.2.260 → 0.2.262

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.
@@ -1993,9 +1993,7 @@ offers) {
1993
1993
  };
1994
1994
  let hasChanges = false;
1995
1995
  const categories = data.categories ?? [];
1996
- const orderLevelDiscountBaseAmount = categories.reduce((subtotal, category) => {
1997
- return subtotal + category.items.reduce((itemSubtotal, item) => itemSubtotal + (item.subtotal ?? 0), 0);
1998
- }, 0);
1996
+ const orderLevelDiscountBaseAmount = (0, utils_1.getOrderSubtotalFromCategories)(categories);
1999
1997
  let order_discount_details = data.order_discount_details;
2000
1998
  const clearOrderLevelDiscount = (discountType) => {
2001
1999
  if (order_discount_details == null) {
@@ -27,6 +27,7 @@ export * from './kds-helpers';
27
27
  export * from './location-helpers';
28
28
  export * from './menu-helpers';
29
29
  export * from './minified-catalog';
30
+ export * from './offer-apply-helpers';
30
31
  export * from './offers-helpers';
31
32
  export * from './operational-roles-helpers';
32
33
  export * from './order-engine';
@@ -43,6 +43,7 @@ __exportStar(require("./kds-helpers"), exports);
43
43
  __exportStar(require("./location-helpers"), exports);
44
44
  __exportStar(require("./menu-helpers"), exports);
45
45
  __exportStar(require("./minified-catalog"), exports);
46
+ __exportStar(require("./offer-apply-helpers"), exports);
46
47
  __exportStar(require("./offers-helpers"), exports);
47
48
  __exportStar(require("./operational-roles-helpers"), exports);
48
49
  __exportStar(require("./order-engine"), exports);
@@ -0,0 +1,34 @@
1
+ import { IDiscountDetails, IGiftCard, IOffer, IOrderCategory } from '../../schemas';
2
+ export declare function getOrderSubtotalFromCategories(categories: IOrderCategory[] | undefined): number;
3
+ export interface IApplyDiscountResult {
4
+ success: boolean;
5
+ discountDetails: IDiscountDetails | null;
6
+ errorMessage: string | null;
7
+ }
8
+ export declare function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, }: {
9
+ offer: IOffer;
10
+ orderDiscountDetails: IDiscountDetails | null | undefined;
11
+ categories: IOrderCategory[] | undefined;
12
+ }): IApplyDiscountResult;
13
+ export declare function buildOfferPointsUpdate({ offer, orderDiscountDetails, }: {
14
+ offer: IOffer;
15
+ orderDiscountDetails: IDiscountDetails | null | undefined;
16
+ }): IApplyDiscountResult;
17
+ export declare function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, }: {
18
+ offer: IOffer;
19
+ orderDiscountDetails: IDiscountDetails | null | undefined;
20
+ categories: IOrderCategory[] | undefined;
21
+ }): IApplyDiscountResult;
22
+ export declare function buildOfferRewardUpdate({ offer, orderDiscountDetails, }: {
23
+ offer: IOffer;
24
+ orderDiscountDetails: IDiscountDetails | null | undefined;
25
+ }): IApplyDiscountResult;
26
+ export declare function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categories, }: {
27
+ giftCard: IGiftCard;
28
+ orderDiscountDetails: IDiscountDetails | null | undefined;
29
+ categories: IOrderCategory[] | undefined;
30
+ }): IApplyDiscountResult;
31
+ export declare function buildVoucherDiscountUpdate({ code, orderDiscountDetails, }: {
32
+ code: string;
33
+ orderDiscountDetails: IDiscountDetails | null | undefined;
34
+ }): IDiscountDetails;
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOrderSubtotalFromCategories = getOrderSubtotalFromCategories;
4
+ exports.buildOfferDiscountUpdate = buildOfferDiscountUpdate;
5
+ exports.buildOfferPointsUpdate = buildOfferPointsUpdate;
6
+ exports.buildOfferCashbackUpdate = buildOfferCashbackUpdate;
7
+ exports.buildOfferRewardUpdate = buildOfferRewardUpdate;
8
+ exports.buildGiftCardDiscountUpdate = buildGiftCardDiscountUpdate;
9
+ exports.buildVoucherDiscountUpdate = buildVoucherDiscountUpdate;
10
+ const constants_1 = require("../../constants");
11
+ const common_1 = require("./common");
12
+ const cart_actions_1 = require("../store/cart-actions");
13
+ // ================================><================================= //
14
+ // === Shared order subtotal for discount logic === //
15
+ // ================================><================================= //
16
+ function getOrderSubtotalFromCategories(categories) {
17
+ if (!categories?.length)
18
+ return 0;
19
+ let subtotal = 0;
20
+ for (let i = 0; i < categories.length; i++) {
21
+ const items = categories[i].items;
22
+ for (let j = 0; j < items.length; j++) {
23
+ subtotal += items[j].subtotal ?? 0;
24
+ }
25
+ }
26
+ return subtotal;
27
+ }
28
+ // ================================><================================= //
29
+ // === buildOfferDiscountUpdate === //
30
+ // ================================><================================= //
31
+ function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, }) {
32
+ if (offer.reward_discount == null) {
33
+ return { success: false, discountDetails: null, errorMessage: null };
34
+ }
35
+ const discountSlot = offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ? 'loyalty' : 'voucher';
36
+ // Already-applied guard
37
+ if (orderDiscountDetails != null &&
38
+ (discountSlot === 'loyalty' ? orderDiscountDetails.loyalty_discount_id : orderDiscountDetails.voucher_discount_id)) {
39
+ return {
40
+ success: false,
41
+ discountDetails: null,
42
+ errorMessage: 'You already have an offer applied to your order.',
43
+ };
44
+ }
45
+ let { discount_value, is_discount_percentage } = offer.reward_discount;
46
+ const { max_discount_amount, max_discount_percentage, excluded_refs } = offer.reward_discount;
47
+ const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
48
+ // Handle excluded_refs
49
+ if (excluded_refs != null && excluded_refs.length > 0) {
50
+ const { subtotal: eligibleSubtotal, hasExcludedRefs } = (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
51
+ if (hasExcludedRefs) {
52
+ if (!is_discount_percentage) {
53
+ return { success: false, discountDetails: null, errorMessage: null };
54
+ }
55
+ if (eligibleSubtotal <= 0) {
56
+ return { success: false, discountDetails: null, errorMessage: null };
57
+ }
58
+ discount_value = (0, common_1.parseNum)((0, common_1.getCappedOfferDiscountAmount)({
59
+ baseAmount: eligibleSubtotal,
60
+ discountValue: discount_value,
61
+ isDiscountPercentage: is_discount_percentage,
62
+ maxDiscountAmount: max_discount_amount,
63
+ maxDiscountPercentage: max_discount_percentage,
64
+ }));
65
+ is_discount_percentage = false;
66
+ }
67
+ }
68
+ // Cap handling for non-excluded cases
69
+ const hasRelevantCap = is_discount_percentage &&
70
+ max_discount_amount != null &&
71
+ Number.isFinite(max_discount_amount) &&
72
+ max_discount_amount >= 0;
73
+ const hasRelevantPercentageCap = !is_discount_percentage &&
74
+ max_discount_percentage != null &&
75
+ Number.isFinite(max_discount_percentage) &&
76
+ max_discount_percentage >= 0;
77
+ if (hasRelevantCap || hasRelevantPercentageCap) {
78
+ discount_value = (0, common_1.parseNum)((0, common_1.getCappedOfferDiscountAmount)({
79
+ baseAmount: orderLevelDiscountBaseAmount,
80
+ discountValue: discount_value,
81
+ isDiscountPercentage: is_discount_percentage,
82
+ maxDiscountAmount: max_discount_amount,
83
+ maxDiscountPercentage: max_discount_percentage,
84
+ }));
85
+ is_discount_percentage = false;
86
+ }
87
+ const discountDetails = {
88
+ ...orderDiscountDetails,
89
+ ...(discountSlot === 'loyalty'
90
+ ? {
91
+ loyalty_discount_id: offer._id,
92
+ loyalty_discount_name: offer.name,
93
+ loyalty_discount: discount_value,
94
+ is_loyalty_discount_percentage: is_discount_percentage,
95
+ }
96
+ : {
97
+ voucher_discount_id: offer._id,
98
+ voucher_discount_name: offer.name,
99
+ voucher_discount: discount_value,
100
+ is_voucher_discount_percentage: is_discount_percentage,
101
+ }),
102
+ total_discount: 0,
103
+ };
104
+ return { success: true, discountDetails, errorMessage: null };
105
+ }
106
+ // ================================><================================= //
107
+ // === buildOfferPointsUpdate === //
108
+ // ================================><================================= //
109
+ function buildOfferPointsUpdate({ offer, orderDiscountDetails, }) {
110
+ if (offer.reward_points == null) {
111
+ return { success: false, discountDetails: null, errorMessage: null };
112
+ }
113
+ const discountSlot = offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ? 'loyalty' : 'voucher';
114
+ if (orderDiscountDetails != null &&
115
+ (discountSlot === 'loyalty' ? orderDiscountDetails.loyalty_discount_id : orderDiscountDetails.voucher_discount_id)) {
116
+ return {
117
+ success: false,
118
+ discountDetails: null,
119
+ errorMessage: 'You already have an offer applied to your order.',
120
+ };
121
+ }
122
+ const discountDetails = {
123
+ ...orderDiscountDetails,
124
+ ...(discountSlot === 'loyalty'
125
+ ? {
126
+ loyalty_discount_id: offer._id,
127
+ loyalty_discount_name: offer.name,
128
+ loyalty_discount: 0,
129
+ is_loyalty_discount_percentage: false,
130
+ }
131
+ : {
132
+ voucher_discount_id: offer._id,
133
+ voucher_discount_name: offer.name,
134
+ voucher_discount: 0,
135
+ is_voucher_discount_percentage: false,
136
+ }),
137
+ total_discount: 0,
138
+ };
139
+ return { success: true, discountDetails, errorMessage: null };
140
+ }
141
+ // ================================><================================= //
142
+ // === buildOfferCashbackUpdate === //
143
+ // ================================><================================= //
144
+ function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, }) {
145
+ if (offer.reward_cashback == null) {
146
+ return { success: false, discountDetails: null, errorMessage: null };
147
+ }
148
+ // Validate excluded_refs
149
+ const excluded_refs = offer.reward_cashback.excluded_refs ?? [];
150
+ if (excluded_refs.length > 0) {
151
+ const { subtotal: eligibleSubtotal } = (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
152
+ if (eligibleSubtotal <= 0) {
153
+ return { success: false, discountDetails: null, errorMessage: null };
154
+ }
155
+ }
156
+ const discountSlot = offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ? 'loyalty' : 'voucher';
157
+ if (orderDiscountDetails != null &&
158
+ (discountSlot === 'loyalty' ? orderDiscountDetails.loyalty_discount_id : orderDiscountDetails.voucher_discount_id)) {
159
+ return {
160
+ success: false,
161
+ discountDetails: null,
162
+ errorMessage: 'You already have an offer applied to your order.',
163
+ };
164
+ }
165
+ const discountDetails = {
166
+ ...orderDiscountDetails,
167
+ ...(discountSlot === 'loyalty'
168
+ ? {
169
+ loyalty_discount_id: offer._id,
170
+ loyalty_discount_name: offer.name,
171
+ loyalty_discount: 0,
172
+ is_loyalty_discount_percentage: false,
173
+ }
174
+ : {
175
+ voucher_discount_id: offer._id,
176
+ voucher_discount_name: offer.name,
177
+ voucher_discount: 0,
178
+ is_voucher_discount_percentage: false,
179
+ }),
180
+ total_discount: 0,
181
+ };
182
+ return { success: true, discountDetails, errorMessage: null };
183
+ }
184
+ // ================================><================================= //
185
+ // === buildOfferRewardUpdate === //
186
+ // === (for GIFT_CARDS and VOUCHER reward types — post-order) === //
187
+ // ================================><================================= //
188
+ function buildOfferRewardUpdate({ offer, orderDiscountDetails, }) {
189
+ const discountSlot = offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ? 'loyalty' : 'voucher';
190
+ if (orderDiscountDetails != null &&
191
+ (discountSlot === 'loyalty' ? orderDiscountDetails.loyalty_discount_id : orderDiscountDetails.voucher_discount_id)) {
192
+ return {
193
+ success: false,
194
+ discountDetails: null,
195
+ errorMessage: 'You already have an offer applied to your order.',
196
+ };
197
+ }
198
+ const discountDetails = {
199
+ ...orderDiscountDetails,
200
+ ...(discountSlot === 'loyalty'
201
+ ? {
202
+ loyalty_discount_id: offer._id,
203
+ loyalty_discount_name: offer.name,
204
+ loyalty_discount: 0,
205
+ is_loyalty_discount_percentage: false,
206
+ }
207
+ : {
208
+ voucher_discount_id: offer._id,
209
+ voucher_discount_name: offer.name,
210
+ voucher_discount: 0,
211
+ is_voucher_discount_percentage: false,
212
+ }),
213
+ total_discount: 0,
214
+ };
215
+ return { success: true, discountDetails, errorMessage: null };
216
+ }
217
+ // ================================><================================= //
218
+ // === buildGiftCardDiscountUpdate === //
219
+ // ================================><================================= //
220
+ function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categories, }) {
221
+ // Already-applied guard
222
+ if (orderDiscountDetails != null && orderDiscountDetails.special_discount_id) {
223
+ return {
224
+ success: false,
225
+ discountDetails: null,
226
+ errorMessage: 'You already have a gift card or special discount applied.',
227
+ };
228
+ }
229
+ const rewardType = giftCard.reward_type;
230
+ if (rewardType === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT) {
231
+ const reward = giftCard.reward_discount;
232
+ if (!reward)
233
+ return { success: false, discountDetails: null, errorMessage: null };
234
+ const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage } = reward;
235
+ const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
236
+ const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
237
+ ? (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
238
+ : { subtotal: orderLevelDiscountBaseAmount, hasExcludedRefs: false };
239
+ const hasRelevantCap = is_discount_percentage &&
240
+ max_discount_amount != null &&
241
+ Number.isFinite(max_discount_amount) &&
242
+ max_discount_amount >= 0;
243
+ const hasRelevantPercentageCap = !is_discount_percentage &&
244
+ max_discount_percentage != null &&
245
+ Number.isFinite(max_discount_percentage) &&
246
+ max_discount_percentage >= 0;
247
+ const shouldNormalizeToStatic = hasExcludedRefs || hasRelevantCap || hasRelevantPercentageCap;
248
+ const discountBaseAmount = hasExcludedRefs ? eligibleSubtotal : orderLevelDiscountBaseAmount;
249
+ if (shouldNormalizeToStatic && discountBaseAmount <= 0) {
250
+ return {
251
+ success: false,
252
+ discountDetails: null,
253
+ errorMessage: 'Gift card is not applicable to current cart items.',
254
+ };
255
+ }
256
+ const resolvedDiscount = shouldNormalizeToStatic
257
+ ? (0, common_1.parseNum)((0, common_1.getCappedOfferDiscountAmount)({
258
+ baseAmount: discountBaseAmount,
259
+ discountValue: discount_value,
260
+ isDiscountPercentage: is_discount_percentage,
261
+ maxDiscountAmount: max_discount_amount,
262
+ maxDiscountPercentage: max_discount_percentage,
263
+ }))
264
+ : discount_value;
265
+ const discountDetails = {
266
+ ...orderDiscountDetails,
267
+ special_discount_id: giftCard._id,
268
+ special_discount_name: giftCard.name,
269
+ special_discount: resolvedDiscount,
270
+ is_special_discount_percentage: shouldNormalizeToStatic ? false : is_discount_percentage,
271
+ special_reference_number: giftCard.code,
272
+ total_discount: 0,
273
+ };
274
+ return { success: true, discountDetails, errorMessage: null };
275
+ }
276
+ // POINTS, CASHBACK, VOUCHER, ITEMS, DISCOUNT_ITEMS, MYSTERY_GIFT — tag for backend resolution
277
+ const discountDetails = {
278
+ ...orderDiscountDetails,
279
+ special_discount_id: giftCard._id,
280
+ special_discount_name: giftCard.name,
281
+ special_discount: 0,
282
+ is_special_discount_percentage: false,
283
+ special_reference_number: giftCard.code,
284
+ total_discount: 0,
285
+ };
286
+ return { success: true, discountDetails, errorMessage: null };
287
+ }
288
+ // ================================><================================= //
289
+ // === buildVoucherDiscountUpdate === //
290
+ // ================================><================================= //
291
+ function buildVoucherDiscountUpdate({ code, orderDiscountDetails, }) {
292
+ return {
293
+ ...orderDiscountDetails,
294
+ voucher_reference_number: code.trim().toUpperCase(),
295
+ total_discount: 0,
296
+ };
297
+ }
@@ -1,4 +1,5 @@
1
1
  import { Schema } from 'mongoose';
2
+ import { GIFT_CARD_REWARD_TYPE_ENUM } from '../../constants';
2
3
  export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
3
4
  timestamps: true;
4
5
  versionKey: false;
@@ -16,26 +17,122 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
16
17
  brand_id: string;
17
18
  active: boolean;
18
19
  code: string;
19
- reward_type: import("../../constants").GIFT_CARD_REWARD_TYPE_ENUM;
20
+ reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
20
21
  used_count: number;
21
- reward_items?: any;
22
- reward_discount?: any;
23
- reward_discount_items?: any;
24
- reward_points?: any;
25
- reward_cashback?: any;
26
- reward_voucher?: any;
22
+ reward_items?: {
23
+ item_ids: import("mongoose").Types.ObjectId[];
24
+ excluded_refs: string[];
25
+ exclusive_refs: string[];
26
+ num_of_items: number;
27
+ allocation?: import("mongoose").Types.DocumentArray<{
28
+ item_ids: import("mongoose").Types.ObjectId[];
29
+ quantity: number;
30
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
31
+ item_ids: import("mongoose").Types.ObjectId[];
32
+ quantity: number;
33
+ }> & {
34
+ item_ids: import("mongoose").Types.ObjectId[];
35
+ quantity: number;
36
+ }> | null | undefined;
37
+ } | null | undefined;
38
+ reward_discount?: {
39
+ is_discount_percentage: boolean;
40
+ excluded_refs: string[];
41
+ discount_value: number;
42
+ max_discount_amount?: number | null | undefined;
43
+ max_discount_percentage?: number | null | undefined;
44
+ } | null | undefined;
45
+ reward_discount_items?: {
46
+ is_discount_percentage: boolean;
47
+ item_ids: import("mongoose").Types.ObjectId[];
48
+ excluded_refs: string[];
49
+ exclusive_refs: string[];
50
+ num_of_items: number;
51
+ discount_value: number;
52
+ allocation?: import("mongoose").Types.DocumentArray<{
53
+ item_ids: import("mongoose").Types.ObjectId[];
54
+ quantity: number;
55
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
56
+ item_ids: import("mongoose").Types.ObjectId[];
57
+ quantity: number;
58
+ }> & {
59
+ item_ids: import("mongoose").Types.ObjectId[];
60
+ quantity: number;
61
+ }> | null | undefined;
62
+ } | null | undefined;
63
+ reward_points?: {
64
+ num_of_points: number;
65
+ once_per_order: boolean;
66
+ } | null | undefined;
67
+ reward_cashback?: {
68
+ excluded_refs: string[];
69
+ cashback_value: number;
70
+ is_cashback_percentage: boolean;
71
+ max_cashback_amount?: number | null | undefined;
72
+ } | null | undefined;
73
+ reward_voucher?: {
74
+ voucher_ids: Map<string, number>;
75
+ } | null | undefined;
27
76
  max_uses?: number | null | undefined;
28
77
  max_uses_per_customer?: number | null | undefined;
29
78
  last_used_at?: NativeDate | null | undefined;
30
79
  expire_at?: NativeDate | null | undefined;
31
80
  reward_mystery_gift?: {
32
81
  choice_of_rewards: string[];
33
- reward_items?: any;
34
- reward_discount?: any;
35
- reward_discount_items?: any;
36
- reward_points?: any;
37
- reward_cashback?: any;
38
- reward_voucher?: any;
82
+ reward_items?: {
83
+ item_ids: import("mongoose").Types.ObjectId[];
84
+ excluded_refs: string[];
85
+ exclusive_refs: string[];
86
+ num_of_items: number;
87
+ allocation?: import("mongoose").Types.DocumentArray<{
88
+ item_ids: import("mongoose").Types.ObjectId[];
89
+ quantity: number;
90
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
91
+ item_ids: import("mongoose").Types.ObjectId[];
92
+ quantity: number;
93
+ }> & {
94
+ item_ids: import("mongoose").Types.ObjectId[];
95
+ quantity: number;
96
+ }> | null | undefined;
97
+ } | null | undefined;
98
+ reward_discount?: {
99
+ is_discount_percentage: boolean;
100
+ excluded_refs: string[];
101
+ discount_value: number;
102
+ max_discount_amount?: number | null | undefined;
103
+ max_discount_percentage?: number | null | undefined;
104
+ } | null | undefined;
105
+ reward_discount_items?: {
106
+ is_discount_percentage: boolean;
107
+ item_ids: import("mongoose").Types.ObjectId[];
108
+ excluded_refs: string[];
109
+ exclusive_refs: string[];
110
+ num_of_items: number;
111
+ discount_value: number;
112
+ allocation?: import("mongoose").Types.DocumentArray<{
113
+ item_ids: import("mongoose").Types.ObjectId[];
114
+ quantity: number;
115
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
116
+ item_ids: import("mongoose").Types.ObjectId[];
117
+ quantity: number;
118
+ }> & {
119
+ item_ids: import("mongoose").Types.ObjectId[];
120
+ quantity: number;
121
+ }> | null | undefined;
122
+ } | null | undefined;
123
+ reward_points?: {
124
+ num_of_points: number;
125
+ once_per_order: boolean;
126
+ } | null | undefined;
127
+ reward_cashback?: {
128
+ excluded_refs: string[];
129
+ cashback_value: number;
130
+ is_cashback_percentage: boolean;
131
+ max_cashback_amount?: number | null | undefined;
132
+ } | null | undefined;
133
+ reward_voucher?: {
134
+ voucher_ids: Map<string, number>;
135
+ } | null | undefined;
39
136
  } | null | undefined;
40
137
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
41
138
  createdAt: NativeDate;
@@ -50,26 +147,122 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
50
147
  brand_id: string;
51
148
  active: boolean;
52
149
  code: string;
53
- reward_type: import("../../constants").GIFT_CARD_REWARD_TYPE_ENUM;
150
+ reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
54
151
  used_count: number;
55
- reward_items?: any;
56
- reward_discount?: any;
57
- reward_discount_items?: any;
58
- reward_points?: any;
59
- reward_cashback?: any;
60
- reward_voucher?: any;
152
+ reward_items?: {
153
+ item_ids: import("mongoose").Types.ObjectId[];
154
+ excluded_refs: string[];
155
+ exclusive_refs: string[];
156
+ num_of_items: number;
157
+ allocation?: import("mongoose").Types.DocumentArray<{
158
+ item_ids: import("mongoose").Types.ObjectId[];
159
+ quantity: number;
160
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
161
+ item_ids: import("mongoose").Types.ObjectId[];
162
+ quantity: number;
163
+ }> & {
164
+ item_ids: import("mongoose").Types.ObjectId[];
165
+ quantity: number;
166
+ }> | null | undefined;
167
+ } | null | undefined;
168
+ reward_discount?: {
169
+ is_discount_percentage: boolean;
170
+ excluded_refs: string[];
171
+ discount_value: number;
172
+ max_discount_amount?: number | null | undefined;
173
+ max_discount_percentage?: number | null | undefined;
174
+ } | null | undefined;
175
+ reward_discount_items?: {
176
+ is_discount_percentage: boolean;
177
+ item_ids: import("mongoose").Types.ObjectId[];
178
+ excluded_refs: string[];
179
+ exclusive_refs: string[];
180
+ num_of_items: number;
181
+ discount_value: number;
182
+ allocation?: import("mongoose").Types.DocumentArray<{
183
+ item_ids: import("mongoose").Types.ObjectId[];
184
+ quantity: number;
185
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
186
+ item_ids: import("mongoose").Types.ObjectId[];
187
+ quantity: number;
188
+ }> & {
189
+ item_ids: import("mongoose").Types.ObjectId[];
190
+ quantity: number;
191
+ }> | null | undefined;
192
+ } | null | undefined;
193
+ reward_points?: {
194
+ num_of_points: number;
195
+ once_per_order: boolean;
196
+ } | null | undefined;
197
+ reward_cashback?: {
198
+ excluded_refs: string[];
199
+ cashback_value: number;
200
+ is_cashback_percentage: boolean;
201
+ max_cashback_amount?: number | null | undefined;
202
+ } | null | undefined;
203
+ reward_voucher?: {
204
+ voucher_ids: Map<string, number>;
205
+ } | null | undefined;
61
206
  max_uses?: number | null | undefined;
62
207
  max_uses_per_customer?: number | null | undefined;
63
208
  last_used_at?: NativeDate | null | undefined;
64
209
  expire_at?: NativeDate | null | undefined;
65
210
  reward_mystery_gift?: {
66
211
  choice_of_rewards: string[];
67
- reward_items?: any;
68
- reward_discount?: any;
69
- reward_discount_items?: any;
70
- reward_points?: any;
71
- reward_cashback?: any;
72
- reward_voucher?: any;
212
+ reward_items?: {
213
+ item_ids: import("mongoose").Types.ObjectId[];
214
+ excluded_refs: string[];
215
+ exclusive_refs: string[];
216
+ num_of_items: number;
217
+ allocation?: import("mongoose").Types.DocumentArray<{
218
+ item_ids: import("mongoose").Types.ObjectId[];
219
+ quantity: number;
220
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
221
+ item_ids: import("mongoose").Types.ObjectId[];
222
+ quantity: number;
223
+ }> & {
224
+ item_ids: import("mongoose").Types.ObjectId[];
225
+ quantity: number;
226
+ }> | null | undefined;
227
+ } | null | undefined;
228
+ reward_discount?: {
229
+ is_discount_percentage: boolean;
230
+ excluded_refs: string[];
231
+ discount_value: number;
232
+ max_discount_amount?: number | null | undefined;
233
+ max_discount_percentage?: number | null | undefined;
234
+ } | null | undefined;
235
+ reward_discount_items?: {
236
+ is_discount_percentage: boolean;
237
+ item_ids: import("mongoose").Types.ObjectId[];
238
+ excluded_refs: string[];
239
+ exclusive_refs: string[];
240
+ num_of_items: number;
241
+ discount_value: number;
242
+ allocation?: import("mongoose").Types.DocumentArray<{
243
+ item_ids: import("mongoose").Types.ObjectId[];
244
+ quantity: number;
245
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
246
+ item_ids: import("mongoose").Types.ObjectId[];
247
+ quantity: number;
248
+ }> & {
249
+ item_ids: import("mongoose").Types.ObjectId[];
250
+ quantity: number;
251
+ }> | null | undefined;
252
+ } | null | undefined;
253
+ reward_points?: {
254
+ num_of_points: number;
255
+ once_per_order: boolean;
256
+ } | null | undefined;
257
+ reward_cashback?: {
258
+ excluded_refs: string[];
259
+ cashback_value: number;
260
+ is_cashback_percentage: boolean;
261
+ max_cashback_amount?: number | null | undefined;
262
+ } | null | undefined;
263
+ reward_voucher?: {
264
+ voucher_ids: Map<string, number>;
265
+ } | null | undefined;
73
266
  } | null | undefined;
74
267
  }>> & import("mongoose").FlatRecord<{
75
268
  createdAt: NativeDate;
@@ -84,26 +277,122 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
84
277
  brand_id: string;
85
278
  active: boolean;
86
279
  code: string;
87
- reward_type: import("../../constants").GIFT_CARD_REWARD_TYPE_ENUM;
280
+ reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
88
281
  used_count: number;
89
- reward_items?: any;
90
- reward_discount?: any;
91
- reward_discount_items?: any;
92
- reward_points?: any;
93
- reward_cashback?: any;
94
- reward_voucher?: any;
282
+ reward_items?: {
283
+ item_ids: import("mongoose").Types.ObjectId[];
284
+ excluded_refs: string[];
285
+ exclusive_refs: string[];
286
+ num_of_items: number;
287
+ allocation?: import("mongoose").Types.DocumentArray<{
288
+ item_ids: import("mongoose").Types.ObjectId[];
289
+ quantity: number;
290
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
291
+ item_ids: import("mongoose").Types.ObjectId[];
292
+ quantity: number;
293
+ }> & {
294
+ item_ids: import("mongoose").Types.ObjectId[];
295
+ quantity: number;
296
+ }> | null | undefined;
297
+ } | null | undefined;
298
+ reward_discount?: {
299
+ is_discount_percentage: boolean;
300
+ excluded_refs: string[];
301
+ discount_value: number;
302
+ max_discount_amount?: number | null | undefined;
303
+ max_discount_percentage?: number | null | undefined;
304
+ } | null | undefined;
305
+ reward_discount_items?: {
306
+ is_discount_percentage: boolean;
307
+ item_ids: import("mongoose").Types.ObjectId[];
308
+ excluded_refs: string[];
309
+ exclusive_refs: string[];
310
+ num_of_items: number;
311
+ discount_value: number;
312
+ allocation?: import("mongoose").Types.DocumentArray<{
313
+ item_ids: import("mongoose").Types.ObjectId[];
314
+ quantity: number;
315
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
316
+ item_ids: import("mongoose").Types.ObjectId[];
317
+ quantity: number;
318
+ }> & {
319
+ item_ids: import("mongoose").Types.ObjectId[];
320
+ quantity: number;
321
+ }> | null | undefined;
322
+ } | null | undefined;
323
+ reward_points?: {
324
+ num_of_points: number;
325
+ once_per_order: boolean;
326
+ } | null | undefined;
327
+ reward_cashback?: {
328
+ excluded_refs: string[];
329
+ cashback_value: number;
330
+ is_cashback_percentage: boolean;
331
+ max_cashback_amount?: number | null | undefined;
332
+ } | null | undefined;
333
+ reward_voucher?: {
334
+ voucher_ids: Map<string, number>;
335
+ } | null | undefined;
95
336
  max_uses?: number | null | undefined;
96
337
  max_uses_per_customer?: number | null | undefined;
97
338
  last_used_at?: NativeDate | null | undefined;
98
339
  expire_at?: NativeDate | null | undefined;
99
340
  reward_mystery_gift?: {
100
341
  choice_of_rewards: string[];
101
- reward_items?: any;
102
- reward_discount?: any;
103
- reward_discount_items?: any;
104
- reward_points?: any;
105
- reward_cashback?: any;
106
- reward_voucher?: any;
342
+ reward_items?: {
343
+ item_ids: import("mongoose").Types.ObjectId[];
344
+ excluded_refs: string[];
345
+ exclusive_refs: string[];
346
+ num_of_items: number;
347
+ allocation?: import("mongoose").Types.DocumentArray<{
348
+ item_ids: import("mongoose").Types.ObjectId[];
349
+ quantity: number;
350
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
351
+ item_ids: import("mongoose").Types.ObjectId[];
352
+ quantity: number;
353
+ }> & {
354
+ item_ids: import("mongoose").Types.ObjectId[];
355
+ quantity: number;
356
+ }> | null | undefined;
357
+ } | null | undefined;
358
+ reward_discount?: {
359
+ is_discount_percentage: boolean;
360
+ excluded_refs: string[];
361
+ discount_value: number;
362
+ max_discount_amount?: number | null | undefined;
363
+ max_discount_percentage?: number | null | undefined;
364
+ } | null | undefined;
365
+ reward_discount_items?: {
366
+ is_discount_percentage: boolean;
367
+ item_ids: import("mongoose").Types.ObjectId[];
368
+ excluded_refs: string[];
369
+ exclusive_refs: string[];
370
+ num_of_items: number;
371
+ discount_value: number;
372
+ allocation?: import("mongoose").Types.DocumentArray<{
373
+ item_ids: import("mongoose").Types.ObjectId[];
374
+ quantity: number;
375
+ }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
376
+ item_ids: import("mongoose").Types.ObjectId[];
377
+ quantity: number;
378
+ }> & {
379
+ item_ids: import("mongoose").Types.ObjectId[];
380
+ quantity: number;
381
+ }> | null | undefined;
382
+ } | null | undefined;
383
+ reward_points?: {
384
+ num_of_points: number;
385
+ once_per_order: boolean;
386
+ } | null | undefined;
387
+ reward_cashback?: {
388
+ excluded_refs: string[];
389
+ cashback_value: number;
390
+ is_cashback_percentage: boolean;
391
+ max_cashback_amount?: number | null | undefined;
392
+ } | null | undefined;
393
+ reward_voucher?: {
394
+ voucher_ids: Map<string, number>;
395
+ } | null | undefined;
107
396
  } | null | undefined;
108
397
  }> & Required<{
109
398
  _id: import("mongoose").Types.ObjectId;
@@ -3,6 +3,168 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GIFT_CARDS_COLLECTION_NAME = exports.GiftCardsSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const constants_1 = require("../../constants");
6
+ const RewardItemsSchema = new mongoose_1.Schema({
7
+ num_of_items: {
8
+ type: Number,
9
+ required: true,
10
+ },
11
+ excluded_refs: {
12
+ type: [String],
13
+ required: true,
14
+ default: [],
15
+ },
16
+ exclusive_refs: {
17
+ type: [String],
18
+ required: true,
19
+ default: [],
20
+ },
21
+ item_ids: {
22
+ type: [mongoose_1.Schema.Types.ObjectId],
23
+ required: true,
24
+ min: 1,
25
+ },
26
+ allocation: {
27
+ type: [
28
+ {
29
+ quantity: {
30
+ type: Number,
31
+ required: true,
32
+ },
33
+ item_ids: {
34
+ type: [mongoose_1.Schema.Types.ObjectId],
35
+ required: true,
36
+ min: 1,
37
+ },
38
+ },
39
+ ],
40
+ required: false,
41
+ },
42
+ }, {
43
+ _id: false,
44
+ minimize: false,
45
+ });
46
+ const RewardDiscountSchema = new mongoose_1.Schema({
47
+ discount_value: {
48
+ type: Number,
49
+ required: true,
50
+ },
51
+ is_discount_percentage: {
52
+ type: Boolean,
53
+ required: true,
54
+ },
55
+ max_discount_amount: {
56
+ type: Number,
57
+ required: false,
58
+ default: null,
59
+ },
60
+ max_discount_percentage: {
61
+ type: Number,
62
+ required: false,
63
+ default: null,
64
+ },
65
+ excluded_refs: {
66
+ type: [String],
67
+ required: true,
68
+ default: [],
69
+ },
70
+ }, {
71
+ _id: false,
72
+ minimize: false,
73
+ });
74
+ const RewardDiscountItemsSchema = new mongoose_1.Schema({
75
+ num_of_items: {
76
+ type: Number,
77
+ required: true,
78
+ },
79
+ excluded_refs: {
80
+ type: [String],
81
+ required: true,
82
+ default: [],
83
+ },
84
+ exclusive_refs: {
85
+ type: [String],
86
+ required: true,
87
+ default: [],
88
+ },
89
+ item_ids: {
90
+ type: [mongoose_1.Schema.Types.ObjectId],
91
+ required: true,
92
+ min: 1,
93
+ },
94
+ allocation: {
95
+ type: [
96
+ {
97
+ quantity: {
98
+ type: Number,
99
+ required: true,
100
+ },
101
+ item_ids: {
102
+ type: [mongoose_1.Schema.Types.ObjectId],
103
+ required: true,
104
+ min: 1,
105
+ },
106
+ },
107
+ ],
108
+ required: false,
109
+ },
110
+ discount_value: {
111
+ type: Number,
112
+ required: true,
113
+ },
114
+ is_discount_percentage: {
115
+ type: Boolean,
116
+ required: true,
117
+ },
118
+ }, {
119
+ _id: false,
120
+ minimize: false,
121
+ });
122
+ const RewardPointsSchema = new mongoose_1.Schema({
123
+ num_of_points: {
124
+ type: Number,
125
+ required: true,
126
+ },
127
+ once_per_order: {
128
+ type: Boolean,
129
+ required: true,
130
+ },
131
+ }, {
132
+ _id: false,
133
+ minimize: false,
134
+ });
135
+ const RewardCashbackSchema = new mongoose_1.Schema({
136
+ cashback_value: {
137
+ type: Number,
138
+ required: true,
139
+ },
140
+ is_cashback_percentage: {
141
+ type: Boolean,
142
+ required: true,
143
+ },
144
+ max_cashback_amount: {
145
+ type: Number,
146
+ required: false,
147
+ default: null,
148
+ },
149
+ excluded_refs: {
150
+ type: [String],
151
+ required: true,
152
+ default: [],
153
+ },
154
+ }, {
155
+ _id: false,
156
+ minimize: false,
157
+ });
158
+ const RewardVoucherSchema = new mongoose_1.Schema({
159
+ voucher_ids: {
160
+ type: Map,
161
+ of: Number,
162
+ required: true,
163
+ },
164
+ }, {
165
+ _id: false,
166
+ minimize: false,
167
+ });
6
168
  const RewardMysteryGiftSchema = new mongoose_1.Schema({
7
169
  choice_of_rewards: {
8
170
  type: [String],
@@ -11,27 +173,27 @@ const RewardMysteryGiftSchema = new mongoose_1.Schema({
11
173
  min: 1,
12
174
  },
13
175
  reward_discount: {
14
- type: mongoose_1.Schema.Types.Mixed,
176
+ type: RewardDiscountSchema,
15
177
  required: false,
16
178
  },
17
179
  reward_discount_items: {
18
- type: mongoose_1.Schema.Types.Mixed,
180
+ type: RewardDiscountItemsSchema,
19
181
  required: false,
20
182
  },
21
183
  reward_points: {
22
- type: mongoose_1.Schema.Types.Mixed,
184
+ type: RewardPointsSchema,
23
185
  required: false,
24
186
  },
25
187
  reward_cashback: {
26
- type: mongoose_1.Schema.Types.Mixed,
188
+ type: RewardCashbackSchema,
27
189
  required: false,
28
190
  },
29
191
  reward_items: {
30
- type: mongoose_1.Schema.Types.Mixed,
192
+ type: RewardItemsSchema,
31
193
  required: false,
32
194
  },
33
195
  reward_voucher: {
34
- type: mongoose_1.Schema.Types.Mixed,
196
+ type: RewardVoucherSchema,
35
197
  required: false,
36
198
  },
37
199
  }, {
@@ -98,32 +260,46 @@ exports.GiftCardsSchema = new mongoose_1.Schema({
98
260
  required: true,
99
261
  },
100
262
  reward_items: {
101
- type: mongoose_1.Schema.Types.Mixed,
102
- required: false,
263
+ type: RewardItemsSchema,
264
+ required() {
265
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.ITEMS;
266
+ },
103
267
  },
104
268
  reward_discount: {
105
- type: mongoose_1.Schema.Types.Mixed,
106
- required: false,
269
+ type: RewardDiscountSchema,
270
+ required() {
271
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT;
272
+ },
107
273
  },
108
274
  reward_discount_items: {
109
- type: mongoose_1.Schema.Types.Mixed,
110
- required: false,
275
+ type: RewardDiscountItemsSchema,
276
+ required() {
277
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.DISCOUNT_ITEMS;
278
+ },
111
279
  },
112
280
  reward_points: {
113
- type: mongoose_1.Schema.Types.Mixed,
114
- required: false,
281
+ type: RewardPointsSchema,
282
+ required() {
283
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.POINTS;
284
+ },
115
285
  },
116
286
  reward_cashback: {
117
- type: mongoose_1.Schema.Types.Mixed,
118
- required: false,
287
+ type: RewardCashbackSchema,
288
+ required() {
289
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.CASHBACK;
290
+ },
119
291
  },
120
292
  reward_voucher: {
121
- type: mongoose_1.Schema.Types.Mixed,
122
- required: false,
293
+ type: RewardVoucherSchema,
294
+ required() {
295
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER;
296
+ },
123
297
  },
124
298
  reward_mystery_gift: {
125
299
  type: RewardMysteryGiftSchema,
126
- required: false,
300
+ required() {
301
+ return this.reward_type === constants_1.GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT;
302
+ },
127
303
  },
128
304
  expire_at: {
129
305
  type: mongoose_1.Schema.Types.Date,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.260",
3
+ "version": "0.2.262",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",