i am trying to check if current filter object falls into date range and based on data return boolean , if it data is not in date range that object should be filtered out. with below code its always returning the data. any idea what is implemented wrong or correct approach to achieve this task ?
main.ts
function mapResponse() {
const _startDate = "2018-12-15";
const _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 should be
response = [
{
rxNumber: "15139",
rxIssueDate: "",
fillDate: "2019-01-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
}]