forked from forcedotcom/commerce-on-lightning-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (27 loc) · 954 Bytes
/
utils.js
File metadata and controls
28 lines (27 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* For full license text, see the LICENSE file in the repo
* root or https://opensource.org/licenses/apache-2-0/
*/
/**
* @typedef {{[key: string]: *}} JsonData
*/
/**
* Transform the Tier Pricing Adjustments Contents
* @param {JsonData} [data] The specified product pricing data
* @returns {Array<JsonData>} transformed/normalized price adjustments contents
*/
export function transformTierAdjustmentContents(data) {
return (data?.priceAdjustment?.priceAdjustmentTiers ?? []).map(
({ id, adjustmentType, adjustmentValue, lowerBound, upperBound, tierUnitPrice }) => ({
id,
adjustmentValue,
adjustmentValueFormat: adjustmentType === 'PercentageBasedAdjustment' ? 'percent-fixed' : 'currency',
lowerBound,
upperBound,
tierUnitPrice,
})
);
}