Skip to content

Commit

Permalink
Fixed issue where default values for date params were not being set.
Browse files Browse the repository at this point in the history
Fixed issue where date parameters with values of type days were not being set correctly on the request.
  • Loading branch information
andrewbrazzatti committed Dec 17, 2024
1 parent e9007d3 commit e9c62ac
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions typescript/api/services/NamedQueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}

Expand Down Expand Up @@ -314,8 +315,8 @@ enum NamedQueryWhenUndefinedOptions {
}

enum NamedQueryFormatOptions {
days,
ISODate
days = 'days',
ISODate = 'ISODate'
}

class QueryParameterDefinition {
Expand Down

0 comments on commit e9c62ac

Please sign in to comment.