Looking to determine if the current filter object falls within a specific date range and return a boolean value based on that condition. However, the code provided always returns the data. Can anyone spot the error in the implementation or suggest a better approach to achieving this task?
main.ts
function mapResponse() {
let _startDate = "2018-12-15";
let _endDate = "2019-01-15";
_startDate = moment.utc(_startDate || twentyfourMonthsAgo, ["YYYY-MM-DD", "MM-DD-YYYY", "MM/DD/YYYY"]).format("YYYY-MM-DD");
_endDate = moment.utc(_endDate || today, ["YYYY-MM-DD", "MM-DD-YYYY", "MM/DD/YYYY"]).format("MM/DD/YYYY");
const response = [
{
rxNumber: "15139",
rxIssueDate: "",
fillDate: "2019-01-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
},
{
rxNumber: "16131",
rxIssueDate: "",
fillDate: "2019-12-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
}
]
response = response.filter(
function renameSpecialtyAttributesToPBM(specialtyRx: any) {
const mappedRx = specialtyRx as Partial < any >;
const dateFilter = checkDateRange(_startDate, _endDate, specialtyRx.fillDate);
if (!dateFilter) {
return false;
}
mappedRx.fillDate = specialtyRx.fillDate;
mappedRx.refillEligible = !!mappedRx.refillStatusText;
mappedRx.renewEligible = !!specialtyRenewStatus;
return true;
});
}
return response;
}
checkDateRange.ts
function checkDateRange(startDate: any, endDate: any, fillDate: RxDetailsEntity): boolean {
if (fillDate > startDate && fillDate < endDate) {
return true;
}
return false;
}
Expected output from mapResponse:
response = [
{
rxNumber: "15139",
rxIssueDate: "",
fillDate: "2019-01-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
}]