@managesome/eposmatic-toolkit 0.2.630 → 0.2.631
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/lib/helpers/offer/generate-offer.d.ts +11 -0
- package/lib/helpers/offer/generate-offer.js +143 -0
- package/lib/helpers/offer/index.d.ts +1 -0
- package/lib/helpers/offer/index.js +17 -0
- package/lib/helpers/utils/offers-helpers.d.ts +7 -0
- package/lib/helpers/utils/offers-helpers.js +150 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Mongoose from 'mongoose';
|
|
2
|
+
import { IItemSpecialHour, IOffer } from '../../schemas';
|
|
3
|
+
export declare function generateOfferSpecialHours(specialHours?: IItemSpecialHour[] | null): IItemSpecialHour[] | null;
|
|
4
|
+
export declare function generateOfferOnCreate<T extends IOffer | Partial<IOffer>>(offer: T): T;
|
|
5
|
+
export declare function generateOfferOnUpdate(partialUpdatedOffer: Partial<IOffer>): {
|
|
6
|
+
updateOperation: {
|
|
7
|
+
$unset?: (Mongoose.AnyKeys<IOffer> & Mongoose.AnyObject) | undefined;
|
|
8
|
+
$set?: (Mongoose.AnyKeys<IOffer> & Mongoose.AnyObject) | undefined;
|
|
9
|
+
};
|
|
10
|
+
partialResponseOffer: Partial<IOffer>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateOfferSpecialHours = generateOfferSpecialHours;
|
|
7
|
+
exports.generateOfferOnCreate = generateOfferOnCreate;
|
|
8
|
+
exports.generateOfferOnUpdate = generateOfferOnUpdate;
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
function toObjectId(value) {
|
|
11
|
+
return new mongoose_1.default.Types.ObjectId(value);
|
|
12
|
+
}
|
|
13
|
+
function toObjectIdArray(values) {
|
|
14
|
+
return values.map((value) => toObjectId(value));
|
|
15
|
+
}
|
|
16
|
+
function generateOfferSpecialHours(specialHours) {
|
|
17
|
+
if (specialHours == null)
|
|
18
|
+
return null;
|
|
19
|
+
return specialHours.map((specialHour) => ({
|
|
20
|
+
...specialHour,
|
|
21
|
+
start_date: specialHour.start_date != null ? new Date(specialHour.start_date) : null,
|
|
22
|
+
end_date: specialHour.end_date != null ? new Date(specialHour.end_date) : null,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
function getOfferPathway(offer) {
|
|
26
|
+
const normalizedPathway = {};
|
|
27
|
+
if (offer.pathway_to_unlock_type_items != null) {
|
|
28
|
+
normalizedPathway.pathway_to_unlock_type_items = {
|
|
29
|
+
...offer.pathway_to_unlock_type_items,
|
|
30
|
+
item_ids: toObjectIdArray(offer.pathway_to_unlock_type_items.item_ids),
|
|
31
|
+
category_ids: toObjectIdArray(offer.pathway_to_unlock_type_items.category_ids),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (offer.pathway_to_unlock_type_vouchers != null) {
|
|
35
|
+
normalizedPathway.pathway_to_unlock_type_vouchers = {
|
|
36
|
+
...offer.pathway_to_unlock_type_vouchers,
|
|
37
|
+
voucher_ids: toObjectIdArray(offer.pathway_to_unlock_type_vouchers.voucher_ids),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return normalizedPathway;
|
|
41
|
+
}
|
|
42
|
+
function getNormalizedRewardItems(rewardItems) {
|
|
43
|
+
return {
|
|
44
|
+
...rewardItems,
|
|
45
|
+
item_ids: toObjectIdArray(rewardItems.item_ids),
|
|
46
|
+
...(rewardItems.allocation != null
|
|
47
|
+
? {
|
|
48
|
+
allocation: rewardItems.allocation.map((allocation) => ({
|
|
49
|
+
...allocation,
|
|
50
|
+
item_ids: toObjectIdArray(allocation.item_ids),
|
|
51
|
+
})),
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function getNormalizedRewardDiscountItems(rewardDiscountItems) {
|
|
57
|
+
return {
|
|
58
|
+
...rewardDiscountItems,
|
|
59
|
+
item_ids: toObjectIdArray(rewardDiscountItems.item_ids),
|
|
60
|
+
...(rewardDiscountItems.allocation != null
|
|
61
|
+
? {
|
|
62
|
+
allocation: rewardDiscountItems.allocation.map((allocation) => ({
|
|
63
|
+
...allocation,
|
|
64
|
+
item_ids: toObjectIdArray(allocation.item_ids),
|
|
65
|
+
})),
|
|
66
|
+
}
|
|
67
|
+
: {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function getOfferReward(offer) {
|
|
71
|
+
const normalizedReward = {};
|
|
72
|
+
if (offer.reward_items != null) {
|
|
73
|
+
normalizedReward.reward_items = getNormalizedRewardItems(offer.reward_items);
|
|
74
|
+
}
|
|
75
|
+
if (offer.reward_discount_items != null) {
|
|
76
|
+
normalizedReward.reward_discount_items = getNormalizedRewardDiscountItems(offer.reward_discount_items);
|
|
77
|
+
}
|
|
78
|
+
return normalizedReward;
|
|
79
|
+
}
|
|
80
|
+
const OFFER_VARIANT_FIELDS = [
|
|
81
|
+
'pathway_to_unlock_type_items',
|
|
82
|
+
'pathway_to_unlock_type_orders',
|
|
83
|
+
'pathway_to_unlock_type_points',
|
|
84
|
+
'pathway_to_unlock_type_vouchers',
|
|
85
|
+
'reward_items',
|
|
86
|
+
'reward_discount',
|
|
87
|
+
'reward_discount_items',
|
|
88
|
+
'reward_points',
|
|
89
|
+
'reward_cashback',
|
|
90
|
+
'reward_gift_cards',
|
|
91
|
+
'reward_voucher',
|
|
92
|
+
];
|
|
93
|
+
function generateOfferOnCreate(offer) {
|
|
94
|
+
const newOffer = {
|
|
95
|
+
...offer,
|
|
96
|
+
...getOfferPathway(offer),
|
|
97
|
+
...getOfferReward(offer),
|
|
98
|
+
...(offer.offer_special_hours != null
|
|
99
|
+
? { offer_special_hours: generateOfferSpecialHours(offer.offer_special_hours) }
|
|
100
|
+
: {}),
|
|
101
|
+
_id: toObjectId(offer._id),
|
|
102
|
+
};
|
|
103
|
+
const cleanedOffer = newOffer;
|
|
104
|
+
if (cleanedOffer.offer_special_hours == null) {
|
|
105
|
+
delete cleanedOffer.offer_special_hours;
|
|
106
|
+
}
|
|
107
|
+
OFFER_VARIANT_FIELDS.forEach((field) => {
|
|
108
|
+
if (cleanedOffer[field] == null) {
|
|
109
|
+
delete cleanedOffer[field];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return cleanedOffer;
|
|
113
|
+
}
|
|
114
|
+
// ===============================>>><<<=====================================
|
|
115
|
+
function generateOfferOnUpdate(partialUpdatedOffer) {
|
|
116
|
+
const partialResponseOffer = {
|
|
117
|
+
...partialUpdatedOffer,
|
|
118
|
+
};
|
|
119
|
+
const unset = {};
|
|
120
|
+
const set = {
|
|
121
|
+
...partialUpdatedOffer,
|
|
122
|
+
...getOfferPathway(partialUpdatedOffer),
|
|
123
|
+
...getOfferReward(partialUpdatedOffer),
|
|
124
|
+
...(partialUpdatedOffer.offer_special_hours != null
|
|
125
|
+
? { offer_special_hours: generateOfferSpecialHours(partialUpdatedOffer.offer_special_hours) }
|
|
126
|
+
: {}),
|
|
127
|
+
};
|
|
128
|
+
if (set.offer_special_hours === null) {
|
|
129
|
+
delete set.offer_special_hours;
|
|
130
|
+
unset['offer_special_hours'] = '';
|
|
131
|
+
}
|
|
132
|
+
OFFER_VARIANT_FIELDS.forEach((field) => {
|
|
133
|
+
if (set[field] === null) {
|
|
134
|
+
delete set[field];
|
|
135
|
+
unset[field] = '';
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const updateOperation = {
|
|
139
|
+
...(Object.keys(set).length > 0 ? { $set: set } : {}),
|
|
140
|
+
...(Object.keys(unset).length > 0 ? { $unset: unset } : {}),
|
|
141
|
+
};
|
|
142
|
+
return { updateOperation, partialResponseOffer };
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generate-offer';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generate-offer"), exports);
|
|
@@ -233,4 +233,11 @@ export declare function getOffersWithStats({ offers, customer, vouchers, giftCar
|
|
|
233
233
|
offersWithStatsHashKey: string;
|
|
234
234
|
unlockedOffersApplicableTimesHashKey: string;
|
|
235
235
|
};
|
|
236
|
+
export declare function generateOfferOnUpdate(partialUpdatedOffer: Partial<IOffer>): {
|
|
237
|
+
updateOperation: {
|
|
238
|
+
$unset?: (import("mongoose").AnyKeys<IOffer> & import("mongoose").AnyObject) | undefined;
|
|
239
|
+
$set?: (import("mongoose").AnyKeys<IOffer> & import("mongoose").AnyObject) | undefined;
|
|
240
|
+
};
|
|
241
|
+
partialResponseOffer: Partial<IOffer>;
|
|
242
|
+
};
|
|
236
243
|
export {};
|
|
@@ -30,6 +30,7 @@ exports.buildWalletGiftCardRedemptionPatch = buildWalletGiftCardRedemptionPatch;
|
|
|
30
30
|
exports.buildWalletGiftCardRedemptionClaimPatch = buildWalletGiftCardRedemptionClaimPatch;
|
|
31
31
|
exports.buildClearWalletRedemptionsPatch = buildClearWalletRedemptionsPatch;
|
|
32
32
|
exports.getOffersWithStats = getOffersWithStats;
|
|
33
|
+
exports.generateOfferOnUpdate = generateOfferOnUpdate;
|
|
33
34
|
const constants_1 = require("../../constants");
|
|
34
35
|
const common_1 = require("./common");
|
|
35
36
|
const platform_catalog_1 = require("./platform-catalog");
|
|
@@ -3045,3 +3046,152 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3045
3046
|
unlockedOffersApplicableTimesHashKey: getUnlockedOffersApplicableTimesHashKey(unlockedOffersApplicableTimes, isEdit),
|
|
3046
3047
|
};
|
|
3047
3048
|
}
|
|
3049
|
+
// ===============================>>><<<=====================================
|
|
3050
|
+
function generateOfferOnUpdate(partialUpdatedOffer) {
|
|
3051
|
+
const partialResponseOffer = {
|
|
3052
|
+
...partialUpdatedOffer,
|
|
3053
|
+
};
|
|
3054
|
+
const unset = {};
|
|
3055
|
+
const set = {
|
|
3056
|
+
...partialUpdatedOffer,
|
|
3057
|
+
};
|
|
3058
|
+
if (set.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS) {
|
|
3059
|
+
delete set.pathway_to_unlock_type_orders;
|
|
3060
|
+
delete set.pathway_to_unlock_type_points;
|
|
3061
|
+
delete set.pathway_to_unlock_type_vouchers;
|
|
3062
|
+
unset['pathway_to_unlock_type_orders'] = '';
|
|
3063
|
+
unset['pathway_to_unlock_type_points'] = '';
|
|
3064
|
+
unset['pathway_to_unlock_type_vouchers'] = '';
|
|
3065
|
+
}
|
|
3066
|
+
else if (set.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS) {
|
|
3067
|
+
delete set.pathway_to_unlock_type_items;
|
|
3068
|
+
delete set.pathway_to_unlock_type_points;
|
|
3069
|
+
delete set.pathway_to_unlock_type_vouchers;
|
|
3070
|
+
unset['pathway_to_unlock_type_items'] = '';
|
|
3071
|
+
unset['pathway_to_unlock_type_points'] = '';
|
|
3072
|
+
unset['pathway_to_unlock_type_vouchers'] = '';
|
|
3073
|
+
}
|
|
3074
|
+
else if (set.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS) {
|
|
3075
|
+
delete set.pathway_to_unlock_type_items;
|
|
3076
|
+
delete set.pathway_to_unlock_type_orders;
|
|
3077
|
+
delete set.pathway_to_unlock_type_vouchers;
|
|
3078
|
+
unset['pathway_to_unlock_type_items'] = '';
|
|
3079
|
+
unset['pathway_to_unlock_type_orders'] = '';
|
|
3080
|
+
unset['pathway_to_unlock_type_vouchers'] = '';
|
|
3081
|
+
}
|
|
3082
|
+
else if (set.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
|
|
3083
|
+
delete set.pathway_to_unlock_type_items;
|
|
3084
|
+
delete set.pathway_to_unlock_type_orders;
|
|
3085
|
+
delete set.pathway_to_unlock_type_points;
|
|
3086
|
+
unset['pathway_to_unlock_type_items'] = '';
|
|
3087
|
+
unset['pathway_to_unlock_type_orders'] = '';
|
|
3088
|
+
unset['pathway_to_unlock_type_points'] = '';
|
|
3089
|
+
}
|
|
3090
|
+
if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS) {
|
|
3091
|
+
delete set.reward_discount;
|
|
3092
|
+
delete set.reward_discount_items;
|
|
3093
|
+
delete set.reward_points;
|
|
3094
|
+
delete set.reward_cashback;
|
|
3095
|
+
delete set.reward_gift_cards;
|
|
3096
|
+
delete set.reward_voucher;
|
|
3097
|
+
unset['reward_discount'] = '';
|
|
3098
|
+
unset['reward_discount_items'] = '';
|
|
3099
|
+
unset['reward_points'] = '';
|
|
3100
|
+
unset['reward_cashback'] = '';
|
|
3101
|
+
unset['reward_gift_cards'] = '';
|
|
3102
|
+
unset['reward_voucher'] = '';
|
|
3103
|
+
}
|
|
3104
|
+
else if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT) {
|
|
3105
|
+
delete set.reward_items;
|
|
3106
|
+
delete set.reward_discount_items;
|
|
3107
|
+
delete set.reward_points;
|
|
3108
|
+
delete set.reward_cashback;
|
|
3109
|
+
delete set.reward_gift_cards;
|
|
3110
|
+
delete set.reward_voucher;
|
|
3111
|
+
unset['reward_items'] = '';
|
|
3112
|
+
unset['reward_discount_items'] = '';
|
|
3113
|
+
unset['reward_points'] = '';
|
|
3114
|
+
unset['reward_cashback'] = '';
|
|
3115
|
+
unset['reward_gift_cards'] = '';
|
|
3116
|
+
unset['reward_voucher'] = '';
|
|
3117
|
+
}
|
|
3118
|
+
else if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
|
|
3119
|
+
delete set.reward_items;
|
|
3120
|
+
delete set.reward_points;
|
|
3121
|
+
delete set.reward_discount;
|
|
3122
|
+
delete set.reward_cashback;
|
|
3123
|
+
delete set.reward_gift_cards;
|
|
3124
|
+
delete set.reward_voucher;
|
|
3125
|
+
unset['reward_items'] = '';
|
|
3126
|
+
unset['reward_points'] = '';
|
|
3127
|
+
unset['reward_discount'] = '';
|
|
3128
|
+
unset['reward_cashback'] = '';
|
|
3129
|
+
unset['reward_gift_cards'] = '';
|
|
3130
|
+
unset['reward_voucher'] = '';
|
|
3131
|
+
}
|
|
3132
|
+
else if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.POINTS) {
|
|
3133
|
+
delete set.reward_items;
|
|
3134
|
+
delete set.reward_discount;
|
|
3135
|
+
delete set.reward_discount_items;
|
|
3136
|
+
delete set.reward_cashback;
|
|
3137
|
+
delete set.reward_gift_cards;
|
|
3138
|
+
delete set.reward_voucher;
|
|
3139
|
+
unset['reward_items'] = '';
|
|
3140
|
+
unset['reward_discount'] = '';
|
|
3141
|
+
unset['reward_discount_items'] = '';
|
|
3142
|
+
unset['reward_cashback'] = '';
|
|
3143
|
+
unset['reward_gift_cards'] = '';
|
|
3144
|
+
unset['reward_voucher'] = '';
|
|
3145
|
+
}
|
|
3146
|
+
else if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK) {
|
|
3147
|
+
delete set.reward_items;
|
|
3148
|
+
delete set.reward_discount;
|
|
3149
|
+
delete set.reward_discount_items;
|
|
3150
|
+
delete set.reward_points;
|
|
3151
|
+
delete set.reward_gift_cards;
|
|
3152
|
+
delete set.reward_voucher;
|
|
3153
|
+
unset['reward_items'] = '';
|
|
3154
|
+
unset['reward_discount'] = '';
|
|
3155
|
+
unset['reward_discount_items'] = '';
|
|
3156
|
+
unset['reward_points'] = '';
|
|
3157
|
+
unset['reward_gift_cards'] = '';
|
|
3158
|
+
unset['reward_voucher'] = '';
|
|
3159
|
+
}
|
|
3160
|
+
else if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
|
|
3161
|
+
delete set.reward_items;
|
|
3162
|
+
delete set.reward_discount;
|
|
3163
|
+
delete set.reward_discount_items;
|
|
3164
|
+
delete set.reward_points;
|
|
3165
|
+
delete set.reward_cashback;
|
|
3166
|
+
delete set.reward_voucher;
|
|
3167
|
+
unset['reward_items'] = '';
|
|
3168
|
+
unset['reward_discount'] = '';
|
|
3169
|
+
unset['reward_discount_items'] = '';
|
|
3170
|
+
unset['reward_points'] = '';
|
|
3171
|
+
unset['reward_cashback'] = '';
|
|
3172
|
+
unset['reward_voucher'] = '';
|
|
3173
|
+
}
|
|
3174
|
+
else if (set.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
|
|
3175
|
+
delete set.reward_items;
|
|
3176
|
+
delete set.reward_discount;
|
|
3177
|
+
delete set.reward_discount_items;
|
|
3178
|
+
delete set.reward_points;
|
|
3179
|
+
delete set.reward_cashback;
|
|
3180
|
+
delete set.reward_gift_cards;
|
|
3181
|
+
unset['reward_items'] = '';
|
|
3182
|
+
unset['reward_discount'] = '';
|
|
3183
|
+
unset['reward_discount_items'] = '';
|
|
3184
|
+
unset['reward_points'] = '';
|
|
3185
|
+
unset['reward_cashback'] = '';
|
|
3186
|
+
unset['reward_gift_cards'] = '';
|
|
3187
|
+
}
|
|
3188
|
+
if (set.offer_special_hours === null) {
|
|
3189
|
+
delete set.offer_special_hours;
|
|
3190
|
+
unset['offer_special_hours'] = '';
|
|
3191
|
+
}
|
|
3192
|
+
const updateOperation = {
|
|
3193
|
+
...(Object.keys(set).length > 0 ? { $set: set } : {}),
|
|
3194
|
+
...(Object.keys(unset).length > 0 ? { $unset: unset } : {}),
|
|
3195
|
+
};
|
|
3196
|
+
return { updateOperation, partialResponseOffer };
|
|
3197
|
+
}
|