🔨」 fix: change to isLogged boolean

This commit is contained in:
2025-10-19 17:02:27 +02:00
parent 2757c5796d
commit c4403de099
2 changed files with 23 additions and 16 deletions

View File

@ -36,6 +36,6 @@ Can return:
- 200 - 200
```json ```json
{ {
"lastSeenTime": "<last seen time>" "isLogged": "<true/false>"
} }
``` ```

View File

@ -1,21 +1,28 @@
/** /**
* @param {import('fastify').FastifyRequest} request * @param {import('fastify').FastifyRequest} request
* @param {import('fastify').FastifyReply} reply * @param {import('fastify').FastifyReply} reply
* @param {import('fastify').FastifyInstance} fastify * @param {import('fastify').FastifyInstance} fastify
*/ */
export async function gPing(request, reply, fastify, getActivityTime) { export async function gPing(request, reply, fastify, getActivityTime) {
try { try {
const user = request.params.userId; const user = request.params.userId;
const time = getActivityTime.get(user);
const time = getActivityTime.get(user); if (!time || !time.time) {
console.log(time) return reply.code(404).send({ error: "User not found or no activity time recorded" });
}
return reply.code(200) const lastSeenTime = new Date(time.time);
.send({ const now = new Date();
lastSeenTime: time.time const oneMinuteAgo = new Date(now.getTime() - 60000); // 60,000 ms = 1 minute
});
} catch (err) { const isActiveInLastMinute = lastSeenTime >= oneMinuteAgo;
fastify.log.error(err);
return reply.code(500).send({ error: "Internal server error" }); return reply.code(200).send({
} isLogged: isActiveInLastMinute
});
} catch (err) {
fastify.log.error(err);
return reply.code(500).send({ error: "Internal server error" });
}
} }