From e9c62ac622f6407823b6a9e801d7aa753ded21cb Mon Sep 17 00:00:00 2001 From: Andrew Brazzatti Date: Tue, 17 Dec 2024 00:26:14 +0000 Subject: [PATCH] Fixed issue where default values for date params were not being set. Fixed issue where date parameters with values of type days were not being set correctly on the request. --- typescript/api/services/NamedQueryService.ts | 41 ++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/typescript/api/services/NamedQueryService.ts b/typescript/api/services/NamedQueryService.ts index 0197e3e9a..f715f09be 100644 --- a/typescript/api/services/NamedQueryService.ts +++ b/typescript/api/services/NamedQueryService.ts @@ -253,26 +253,27 @@ export module Services { let query = {}; if (_.isUndefined(value)) { if (queryParam.whenUndefined == NamedQueryWhenUndefinedOptions.defaultValue) { - if(queryParam.format == NamedQueryFormatOptions.days) { - let days = _.toInteger(queryParam.defaultValue); - let nowDateAddOrSubtract = moment(); - if (days > 0) { - //Going forward in time X number of days - nowDateAddOrSubtract = nowDateAddOrSubtract.add(days, 'days'); - } else if(days < 0) { - //This "additional" step makes the code self explanatory - days = days * -1; - //Going backwards in time X number of days - nowDateAddOrSubtract = nowDateAddOrSubtract.subtract(days, 'days'); - } - value = nowDateAddOrSubtract.toISOString(); - } else if(queryParam.format == NamedQueryFormatOptions.ISODate) { - value = queryParam.defaultValue; - } - query[queryParam.queryType] = value; - value = query; + value = queryParam.defaultValue; } } + if(queryParam.format == NamedQueryFormatOptions.days) { + let days = _.toInteger(value); + let nowDateAddOrSubtract = moment(); + if (days > 0) { + //Going forward in time X number of days + nowDateAddOrSubtract = nowDateAddOrSubtract.add(days, 'days'); + } else if(days < 0) { + //This "additional" step makes the code self explanatory + days = days * -1; + //Going backwards in time X number of days + nowDateAddOrSubtract = nowDateAddOrSubtract.subtract(days, 'days'); + } + value = nowDateAddOrSubtract.toISOString(); + } + + query[queryParam.queryType] = value; + value = query; + } } @@ -314,8 +315,8 @@ enum NamedQueryWhenUndefinedOptions { } enum NamedQueryFormatOptions { - days, - ISODate + days = 'days', + ISODate = 'ISODate' } class QueryParameterDefinition {