Hello everyone, could somebody help with below find query. I have a custom controller, in which i have a find query defined, now i have requirement to query to execute this based on _start and _limit parameters for pagination.
This works fine with default get API. But i need it working for this one.
My actual query goes like this:
entityS = await strapi.query(‘subscriptions’).model.find({$and:[{enterprise_id:ctx.query.enterprise_id},{$or:[{subscription_status:‘ToBeSubscribed’},{subscription_status:‘ToBeUnsubscribed’}]}]},{
_start:0,_limit:10,
api_id:1}
Can you let me know in brief on actually what you are doing with subscription collection. Like a detailed explanation, then I can try to build the query
For what i’ve gathered you are trying to find
all rows of subscription that has enterpriceID === ctx.query.enterprise_id AND it’s subscription_status is either ToBeSubscribed OR ToBeUnsubscribed and then paginating it with start and limit but what about this api_id:1
If api_id needs to be 1 all the time we can add it to AND condition ??
{api_id:1} definition is for retrieving the only selected fields from the collection, i have around 30 fields defined, i would only need 10 out of them. I am adding whole original query below:
entityS = await strapi.query(‘subscriptions’).model.find({$and:[{enterprise_id:ctx.query.enterprise_id},{$or:[{subscription_status:‘ToBeSubscribed’},{subscription_status:‘ToBeUnsubscribed’}]}]},{
api_id:1,
consumer_id:1,
plan_id:1,
section_id:1,
subscription_requested_date:1,
unsubscription_requested_date:1,
consumption_start_date: 1,
consumption_end_date:1,
approved_date:1,
rejected_date:1,
subscription_status:1,
subscription_processed_by:1,
unsubscription_processed_by:1,
//Below fields added for Admin history list
api_type:1,
comment:1
});
in case that anyone is looking for a full solution. This one works for Strapi v3.
//////////// put below code into services.js to extend your controller functionality: