Skip to content

Commit

Permalink
Merge pull request #418 from Financial-Times/reformatLowercase
Browse files Browse the repository at this point in the history
ACC-2118 Capitalize first letter of time period before save to DB
  • Loading branch information
asugar13 authored Dec 14, 2022
2 parents 16e4d44 + 5f75ff1 commit 2a91c65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ft-next-syndication-api",
"description": "Next Syndication API",
"version": "0.41.6",
"version": "0.41.7",
"private": true,
"dependencies": {
"@dotcom-reliability-kit/middleware-log-errors": "^1.2.5",
Expand Down
14 changes: 12 additions & 2 deletions server/lib/reformat-salesforce-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,25 @@ module.exports = exports = SFContract => {


function formatAsset(item) {
//if the contract data is coming all lowercase from salesforce, capitalize the first letter before saving to the DB. This is because of the enum_time_period in next-syndication-db-schema, which only accepts uppercase.
const lowerCaseEnumTimePeriods = ['day', 'week', 'month', 'year'];

let maxPermittedPrintUsagePeriod = item.maxPermittedPrintUsagePeriod || 'Year';

let maxPermittedOnlineUsagePeriod = item.maxPermittedOnlineUsagePeriod || 'Year';

maxPermittedPrintUsagePeriod = lowerCaseEnumTimePeriods.includes(maxPermittedPrintUsagePeriod) ? maxPermittedPrintUsagePeriod.charAt(0).toUpperCase() + maxPermittedPrintUsagePeriod.slice(1) : maxPermittedPrintUsagePeriod;
maxPermittedOnlineUsagePeriod = lowerCaseEnumTimePeriods.includes(maxPermittedOnlineUsagePeriod) ? maxPermittedOnlineUsagePeriod.charAt(0).toUpperCase() + maxPermittedOnlineUsagePeriod.slice(1) : maxPermittedOnlineUsagePeriod;

return {
asset_class: item.assetType,
asset_id: item.assetId,
asset_type: item.assetName,
content_type: ASSET_TYPE_TO_CONTENT_TYPE[item.assetName],
product: item.productName,
print_usage_period: item.maxPermittedPrintUsagePeriod || 'Year',
print_usage_period: maxPermittedPrintUsagePeriod,
print_usage_limit: item.maxPermittedPrintUsage,
online_usage_period: item.maxPermittedOnlineUsagePeriod || 'Year',
online_usage_period: maxPermittedOnlineUsagePeriod,
online_usage_limit: item.maxPermittedOnlineUsage,
embargo_period: item.embargoPeriod || 0,
content_set: item.contentSet,
Expand Down

0 comments on commit 2a91c65

Please sign in to comment.