Hello.
I have a collection that stores customers and the info relatad to a service plan they have. What I want to do is to query all users whose Free plans are not valid anymore (the “validUntil” field is a date before than today). This is an example of my collection:
In order to do this I have a HTTP function:
export async function get_testing(request) {
const response = {
"headers": {
"Content-Type": "application/json"
}
};
let email = request.query["email"];
let today = new Date();
const { items: freePlans } = await wixData.query('plansCollection')
.eq("currentPlan", "Free")
.lt("validUntil", today) // gt() works but lt() doesn't!!!
.find();
if (freePlans.length > 0) {
response.body = {
"userEmail": "first email found " + freePlans[0].title,
"plan": freePlans[0].currentPlan,
"validUntil": freePlans[0].validUntil,
"comparetodate": today,
"usageCount": freePlans[0].usageCount
}
} else {
response.body = {
"not_found_msg": "no entries found",
"comparetodate" : today
};
}
return ok(response);
}
So assume today is the 24/03/2023 and when I call the testing GET endpoint the query doesn’t find anything and I get:
{
"not_found_msg": "no entries found",
"comparetodate": "2023-03-24T20:16:43.997Z"
}
Nevertheless, just for trying, I changed lt() for gt() and indeed I get the user whose validUntil field value in the collection is a date after today:
{
"userEmail": "first email found user2@test.com",
"plan": "Free",
"validUntil": "2023-04-24T20:15:06.000Z",
"comparetodate": "2023-03-24T20:16:00.996Z",
"usageCount": 300000
}
This does not make any sense to me as it implies that lt() and gt() don’t work the same way for dates. Am I using the lt() in an unproper way or is this a bug? Thanks in advance for all your comments!