I want to get two different return values from the same address in the sever - one for all the data after some filtering and one for the length of the data before filtering, but I don't need them at the same time. Is it possible to create two different GET request for some address and get a different information by specifying which data I want?
This how I'm doing it now:
app.get('/api/orders', (req, res) => {
const page = <number>(req.query.page || 1);
const search = <string>(req.query.search || "");
const filter = <string>(req.query.filter || "order");
let length = allOrders.length;
let orders: any[];
let counter = 0;
allOrders.map((order) => {
if (order.fulfillmentStatus === 'not-fulfilled') {
counter += 1;
}
})
if (search !== "") {
if (filter === "item") {
orders = allOrders.filter((order) => order.items.filter((item: {id: string, quantity: number}) =>
products[item.id].name.toLowerCase().includes(search.toLowerCase())).length != 0);
}
else {
orders = allOrders.filter((order) =>
(order.customer.name.toLowerCase() + order.id).includes(search.toLowerCase()));
}
length = orders.length;
orders = orders.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
}
else {
orders = allOrders.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
}
res.send({orders, length, counter});
});
But I want to be able to get the counter
without calculating the other two values (orders
and length
)