@lyxa.ai/core 1.1.98 → 1.1.99
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/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -125,32 +125,66 @@ function addSecondaryCurrencyToPriceBreakdowns(exchangeRate) {
|
|
|
125
125
|
input: '$priceBreakdowns',
|
|
126
126
|
as: 'breakdown',
|
|
127
127
|
in: {
|
|
128
|
-
$
|
|
129
|
-
|
|
130
|
-
{
|
|
128
|
+
$let: {
|
|
129
|
+
vars: {
|
|
131
130
|
secondaryPrice: (0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
132
131
|
$multiply: ['$$breakdown.price', exchangeRate],
|
|
133
132
|
}),
|
|
134
|
-
secondaryDiscountAmount: {
|
|
135
|
-
$cond: [
|
|
136
|
-
{ $gt: ['$productMarketing', null] },
|
|
137
|
-
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
138
|
-
$multiply: ['$$breakdown.discountAmount', exchangeRate],
|
|
139
|
-
}),
|
|
140
|
-
'$$REMOVE',
|
|
141
|
-
],
|
|
142
|
-
},
|
|
143
|
-
secondaryDiscountedPrice: {
|
|
144
|
-
$cond: [
|
|
145
|
-
{ $gt: ['$productMarketing', null] },
|
|
146
|
-
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
147
|
-
$multiply: ['$$breakdown.discountedPrice', exchangeRate],
|
|
148
|
-
}),
|
|
149
|
-
'$$REMOVE',
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
133
|
},
|
|
153
|
-
|
|
134
|
+
in: {
|
|
135
|
+
$mergeObjects: [
|
|
136
|
+
'$$breakdown',
|
|
137
|
+
{
|
|
138
|
+
secondaryPrice: '$$secondaryPrice',
|
|
139
|
+
secondaryDiscountAmount: {
|
|
140
|
+
$cond: [
|
|
141
|
+
{ $gt: ['$productMarketing', null] },
|
|
142
|
+
{
|
|
143
|
+
$cond: [
|
|
144
|
+
{ $eq: ['$productMarketing.valueType', enum_1.ValueType.FIXED] },
|
|
145
|
+
'$productMarketing.secondaryCurrencyValue',
|
|
146
|
+
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
147
|
+
$multiply: [
|
|
148
|
+
'$$secondaryPrice',
|
|
149
|
+
{
|
|
150
|
+
$divide: ['$productMarketing.value', 100],
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
}),
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
'$$REMOVE',
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
secondaryDiscountedPrice: {
|
|
160
|
+
$cond: [
|
|
161
|
+
{ $gt: ['$productMarketing', null] },
|
|
162
|
+
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
163
|
+
$subtract: [
|
|
164
|
+
'$$secondaryPrice',
|
|
165
|
+
{
|
|
166
|
+
$cond: [
|
|
167
|
+
{ $eq: ['$productMarketing.valueType', enum_1.ValueType.FIXED] },
|
|
168
|
+
'$productMarketing.secondaryCurrencyValue',
|
|
169
|
+
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
170
|
+
$multiply: [
|
|
171
|
+
'$$secondaryPrice',
|
|
172
|
+
{
|
|
173
|
+
$divide: ['$productMarketing.value', 100],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
}),
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
}),
|
|
181
|
+
'$$REMOVE',
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
154
188
|
},
|
|
155
189
|
},
|
|
156
190
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-pipeline-stages.js","sourceRoot":"/","sources":["utilities/pipelines/product-pipeline-stages.ts"],"names":[],"mappings":";;AAIA,0DAmHC;AA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EAAE;gDACzD,yBAAyB;gDAEzB,IAAA,qDAAyB,EAAC;oDACzB,SAAS,EAAE;wDACV,mBAAmB;wDACnB;4DACC,OAAO,EAAE,CAAC,yBAAyB,EAAE,GAAG,CAAC;yDACzC;qDACD;iDACD,CAAC;6CACF;yCACD;wCACD,UAAU;qCACV;iCACD;gCAED,eAAe,EAAE;oCAChB,KAAK,EAAE;wCACN,EAAE,GAAG,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC,EAAE;wCACpC,IAAA,qDAAyB,EAAC;4CACzB,SAAS,EAAE;gDACV,mBAAmB;gDACnB;oDACC,KAAK,EAAE;wDACN,EAAE,GAAG,EAAE,CAAC,6BAA6B,EAAE,gBAAS,CAAC,KAAK,CAAC,EAAE;wDACzD,yBAAyB;wDACzB,IAAA,qDAAyB,EAAC;4DACzB,SAAS,EAAE;gEACV,mBAAmB;gEACnB;oEACC,OAAO,EAAE,CAAC,yBAAyB,EAAE,GAAG,CAAC;iEACzC;6DACD;yDACD,CAAC;qDACF;iDACD;6CACD;yCACD,CAAC;wCACF,UAAU;qCACV;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD;KACD,CAAC;AACH,CAAC","sourcesContent":["import { PipelineStage } from 'mongoose';\nimport { MarketingType, ValueType } from '../enum';\nimport { getRoundBaseCurrencyStage, getRoundSecondaryCurrencyStage } from './common-pipeline-functions';\n\nexport function addProductMarketingInfo(\n\texchangeRate: number,\n\tsecondaryCurrencyName: string\n): PipelineStage[] {\n\treturn [\n\t\t{\n\t\t\t$lookup: {\n\t\t\t\tfrom: 'productMarketings',\n\t\t\t\tlet: { productId: '$_id', now: new Date() },\n\t\t\t\tpipeline: [\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: { $eq: ['$product', '$$productId'] },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$lookup: {\n\t\t\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\t\t\tas: 'marketing',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$unwind: '$marketing',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.status', 'active'] },\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.pausedAt', null] },\n\t\t\t\t\t\t\t\t\t{ $lte: ['$marketing.duration.start', '$$now'] },\n\t\t\t\t\t\t\t\t\t{ $gte: ['$marketing.duration.end', '$$now'] },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Compute and add secondary currency values to coupon documents\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tsecondaryCurrencyValue: {\n\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$valueType', 'fixed'] },\n\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t$multiply: ['$value', exchangeRate],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tlabel: {\n\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.BUY1GET1] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Buy 1 Get 1',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.PUNCH_MARKETING] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Punch',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.DISCOUNT] },\n\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsecondaryCurrencyName,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t' ',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $toString: '$secondaryCurrencyValue' },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.PERCENTAGE] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [{ $toString: '$value' }, '%'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefault: 'Discount',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tdefault: '$marketing.marketingType',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\tmarketing: '$marketing._id',\n\t\t\t\t\t\t\tisBuy1Get1: '$isBuy1Get1',\n\t\t\t\t\t\t\tvalueType: '$valueType',\n\t\t\t\t\t\t\tvalue: '$value',\n\t\t\t\t\t\t\tsecondaryCurrencyValue: '$secondaryCurrencyValue',\n\t\t\t\t\t\t\tlabel: '$label',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tas: 'productMarketing',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t$unwind: { path: '$productMarketing', preserveNullAndEmptyArrays: true },\n\t\t},\n\t];\n}\n\nexport function addSecondaryCurrencyToPriceBreakdowns(exchangeRate: number): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsecondaryPrice: getRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.price', exchangeRate],\n\t\t\t\t\t\t\t\t}),\n\n\t\t\t\t\t\t\t\tsecondaryDiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.discountAmount', exchangeRate],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsecondaryDiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.discountedPrice', exchangeRate],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function addDiscountAmountsToPriceBreakdowns(): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t// if valueType is fixed, use value directly\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is percentage, calculate percentage of price\n\t\t\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Add discounted price\n\t\t\t\t\t\t\t\tdiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$subtract: [\n\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"product-pipeline-stages.js","sourceRoot":"/","sources":["utilities/pipelines/product-pipeline-stages.ts"],"names":[],"mappings":";;AAIA,0DAmHC;AAED,sFA6EC;AAED,kFAkEC;AAzQD,kCAAmD;AACnD,2EAAwG;AAExG,SAAgB,uBAAuB,CACtC,YAAoB,EACpB,qBAA6B;IAE7B,OAAO;QACN;YACC,OAAO,EAAE;gBACR,IAAI,EAAE,mBAAmB;gBACzB,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;gBAC3C,QAAQ,EAAE;oBACT;wBACC,MAAM,EAAE;4BACP,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,EAAE;yBAC3C;qBACD;oBACD;wBACC,OAAO,EAAE;4BACR,IAAI,EAAE,YAAY;4BAClB,UAAU,EAAE,WAAW;4BACvB,YAAY,EAAE,KAAK;4BACnB,EAAE,EAAE,WAAW;yBACf;qBACD;oBACD;wBACC,OAAO,EAAE,YAAY;qBACrB;oBACD;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AyB;gDAEzB,IAAA,qDAAyB,EAAC;oDACzB,SAAS,EAAE;wDACV,mBAAmB;wDACnB;4DACC,OAAO,EAAE,CAAC,yBAAyB,EAAE,GAAG,CAAC;yDACzC;qDACD;iDACD,CAAC;6CACF;yCACD;wCACD,UAAU;qCACV;iCACD;gCAED,eAAe,EAAE;oCAChB,KAAK,EAAE;wCACN,EAAE,GAAG,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC,EAAE;wCACpC,IAAA,qDAAyB,EAAC;4CACzB,SAAS,EAAE;gDACV,mBAAmB;gDACnB;oDACC,KAAK,EAAE;wDACN,EAAE,GAAG,EAAE,CAAC,6BAA6B,EAAE,gBAAS,CAAC,KAAK,CAAC,EAAE;wDACzD,yBAAyB;wDACzB,IAAA,qDAAyB,EAAC;4DACzB,SAAS,EAAE;gEACV,mBAAmB;gEACnB;oEACC,OAAO,EAAE,CAAC,yBAAyB,EAAE,GAAG,CAAC;iEACzC;6DACD;yDACD,CAAC;qDACF;iDACD;6CACD;yCACD,CAAC;wCACF,UAAU;qCACV;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD;KACD,CAAC;AACH,CAAC","sourcesContent":["import { PipelineStage } from 'mongoose';\nimport { MarketingType, ValueType } from '../enum';\nimport { getRoundBaseCurrencyStage, getRoundSecondaryCurrencyStage } from './common-pipeline-functions';\n\nexport function addProductMarketingInfo(\n\texchangeRate: number,\n\tsecondaryCurrencyName: string\n): PipelineStage[] {\n\treturn [\n\t\t{\n\t\t\t$lookup: {\n\t\t\t\tfrom: 'productMarketings',\n\t\t\t\tlet: { productId: '$_id', now: new Date() },\n\t\t\t\tpipeline: [\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: { $eq: ['$product', '$$productId'] },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$lookup: {\n\t\t\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\t\t\tas: 'marketing',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$unwind: '$marketing',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.status', 'active'] },\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.pausedAt', null] },\n\t\t\t\t\t\t\t\t\t{ $lte: ['$marketing.duration.start', '$$now'] },\n\t\t\t\t\t\t\t\t\t{ $gte: ['$marketing.duration.end', '$$now'] },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Compute and add secondary currency values to coupon documents\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tsecondaryCurrencyValue: {\n\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$valueType', 'fixed'] },\n\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t$multiply: ['$value', exchangeRate],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tlabel: {\n\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.BUY1GET1] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Buy 1 Get 1',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.PUNCH_MARKETING] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Punch',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.DISCOUNT] },\n\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsecondaryCurrencyName,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t' ',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $toString: '$secondaryCurrencyValue' },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.PERCENTAGE] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [{ $toString: '$value' }, '%'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefault: 'Discount',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tdefault: '$marketing.marketingType',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\tmarketing: '$marketing._id',\n\t\t\t\t\t\t\tisBuy1Get1: '$isBuy1Get1',\n\t\t\t\t\t\t\tvalueType: '$valueType',\n\t\t\t\t\t\t\tvalue: '$value',\n\t\t\t\t\t\t\tsecondaryCurrencyValue: '$secondaryCurrencyValue',\n\t\t\t\t\t\t\tlabel: '$label',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tas: 'productMarketing',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t$unwind: { path: '$productMarketing', preserveNullAndEmptyArrays: true },\n\t\t},\n\t];\n}\n\nexport function addSecondaryCurrencyToPriceBreakdowns(exchangeRate: number): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$let: {\n\t\t\t\t\t\t\tvars: {\n\t\t\t\t\t\t\t\tsecondaryPrice: getRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.price', exchangeRate],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tin: {\n\t\t\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tsecondaryPrice: '$$secondaryPrice',\n\n\t\t\t\t\t\t\t\t\t\tsecondaryDiscountAmount: {\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is fixed, use value directly\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.secondaryCurrencyValue',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is percentage, calculate percentage of price\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$secondaryPrice',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\t\t\tsecondaryDiscountedPrice: {\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t$subtract: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$secondaryPrice',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.secondaryCurrencyValue',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$secondaryPrice',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function addDiscountAmountsToPriceBreakdowns(): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t// if valueType is fixed, use value directly\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is percentage, calculate percentage of price\n\t\t\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Add discounted price\n\t\t\t\t\t\t\t\tdiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$subtract: [\n\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n"]}
|