mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-12-31 21:56:41 +01:00
finished, functional API
This commit is contained in:
16
src/api/user/gUsers.js
Normal file
16
src/api/user/gUsers.js
Normal file
@ -0,0 +1,16 @@
|
||||
export async function gUsers(request, reply, fastify, getUserData) {
|
||||
try {
|
||||
const { iStart, iEnd } = request.query;
|
||||
if (Number(iEnd) < Number(iStart)) {
|
||||
return reply.code(400).send({ error: "Starting index cannot be strictly inferior to ending index" });
|
||||
}
|
||||
const users = getUserData.all(Number(iEnd) - Number(iStart), Number(iStart));
|
||||
if (!users.length) {
|
||||
return reply.code(404).send({ error: "No users exist in the selected range" });
|
||||
}
|
||||
return reply.code(200).send({ users });
|
||||
} catch (err) {
|
||||
fastify.log.error(err);
|
||||
return reply.code(500).send({ error: "Internal server error" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user