backend/fastify/leaderboard/server.js
2024-05-26 22:28:08 +02:00

31 lines
608 B
JavaScript
Executable File

// Declare a route
module.exports = function (fastify, opts, done) {
const pb = opts.pb;
fastify.post('/leaderboard', async (request, reply) => {
const data = request.body;
const startDate = data?.startDate;
const endDate = data?.endDate;
let output;
try {
output = await pb.collection("portfolios").getFullList({
filter: `created >= "${startDate}" && created < "${endDate}"`,
expand: 'user'
})
}
catch(e) {
//console.log(e)
output = []
}
reply.send({ items: output })
});
done();
};