From 78cf12ce822d7de80b62868164e0b2e5887584ab Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 13 Dec 2024 11:15:52 -0500 Subject: [PATCH] extract remove period method to utils --- lib/elasticsearch/config.js | 12 ++++-------- lib/util.js | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/elasticsearch/config.js b/lib/elasticsearch/config.js index 8dbb7af..79d7524 100644 --- a/lib/elasticsearch/config.js +++ b/lib/elasticsearch/config.js @@ -1,3 +1,5 @@ +const util = require('../util') + // Configure search scopes: const SEARCH_SCOPES = { all: { @@ -78,17 +80,11 @@ const FILTER_CONFIG = { owner: { operator: 'match', field: ['items.owner.id', 'items.owner.label'], repeatable: true, path: 'items' }, subjectLiteral: { transform: (val, logger) => { - const removePeriod = (x) => { - if (x.slice(-1) === '.') { - logger.debug('Removing terminal period', JSON.stringify(val, null, 4)) - return x.slice(0, -1) - } else return x - } if (typeof val === 'string') { - return removePeriod(val) + return util.removeTrailingPeriod(val, logger) } if (Array.isArray(val)) { - return val.map(removePeriod) + return val.map((val) => util.removeTrailingPeriod(val, logger)) } }, operator: 'match', diff --git a/lib/util.js b/lib/util.js index f0da4ef..636d95b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,6 +1,13 @@ const logger = require('./logger') const { isItemNyplOwned } = require('./ownership_determination') +exports.removeTrailingPeriod = (x, logger) => { + if (x.slice(-1) === '.') { + logger.debug('Removing terminal period', JSON.stringify(x, null, 4)) + return x.slice(0, -1) + } else return x +} + exports.sortOnPropWithUndefinedLast = (property) => { return function (a, b) { // equal items sort equally