cleaned doc & friends provided with display names

This commit is contained in:
Tzvetan Trave
2025-10-19 22:02:01 +02:00
parent f63aec4b9c
commit 3a9d726f57
4 changed files with 311 additions and 282 deletions

View File

@ -8,10 +8,16 @@ export async function gFriends(request, reply, fastify, getUserInfo, getFriends)
if (Number(iEnd) < Number(iStart)) {
return reply.code(400).send({ error: "Starting index cannot be strictly inferior to ending index" });
}
const friends = getFriends.all(userId, Number(iEnd) - Number(iStart), Number(iStart));
if (!friends.length) {
const friendNames = getFriends.all(userId, Number(iEnd) - Number(iStart), Number(iStart));
if (!friendNames.length) {
return reply.code(404).send({ error: "No friends exist in the selected range" });
}
const promises = friendNames.map(async (friendName) => {
const friend = getUserInfo.get(friendName.friendName);
friendName.friendDisplayName = friend.displayName;
return friendName;
});
const friends = await Promise.all(promises);
return reply.code(200).send({ friends });
} catch (err) {
fastify.log.error(err);