this is really confusing me and I'm not even sure how to debug it. Basically what is happening is I am running this query:
ts file:
this.httpService.getLastModified({ internalId: this.companyID }).subscribe((res) => {
if (res && res[0].lastModified) {
// code to do inside if (update the lastModified)
} else {
// code to do inside else (use a last modified date as the beginning of last year and then set it to now)
}
service file:
getLastModified(body): Observable<Cases> {
return this.http.post('/db/cases/lastModified/', body);
}
routes:
router.post('/lastModified/', (req, res) => {
const { body } = req;
Companies.find({ internalId: body.internalId }, (err, data) => {
res.json(data);
});
});
database:
So the very first time I run the code I expect to go into the else section and inside there it will use the date as the beginning of last year and then set the lastModified (now) in the database. From then onwards it should always be in the if section.
Now the strange part. On the first load of the day, the code runs the else statement, even though there is a lastModified value there. It is returning only the id of the object. However from then on it works fine all day, until the next day again the first load -- this carries on like this always.
This is driving me crazy as Im waiting a day just to debug and i only get one shot at it.
Does anyone have any idea why it is failing or come across anything like this?