display work time in issue detail pane

This commit is contained in:
Oliver Bryan
2026-01-11 17:18:55 +00:00
parent 511a2d4bea
commit d44f378403
13 changed files with 177 additions and 30 deletions

View File

@@ -24,6 +24,15 @@ export async function getActiveTimedSession(userId: number, issueId: number) {
return timedSession ?? null;
}
export async function getInactiveTimedSessions(issueId: number) {
const timedSessions = await db
.select()
.from(TimedSession)
.where(and(eq(TimedSession.issueId, issueId), isNotNull(TimedSession.endedAt)))
.orderBy(desc(TimedSession.createdAt));
return timedSessions ?? null;
}
export async function getTimedSessionById(id: number) {
const [timedSession] = await db.select().from(TimedSession).where(eq(TimedSession.id, id));
return timedSession ?? null;

View File

@@ -72,6 +72,7 @@ const main = async () => {
"/timer/toggle": withCors(withAuth(withCSRF(routes.timerToggle))),
"/timer/end": withCors(withAuth(withCSRF(routes.timerEnd))),
"/timer/get": withCors(withAuth(withCSRF(routes.timerGet))),
"/timer/get-inactive": withCors(withAuth(withCSRF(routes.timerGetInactive))),
"/timers": withCors(withAuth(withCSRF(routes.timers))),
},
});

View File

@@ -28,6 +28,7 @@ import projectWithCreator from "./project/with-creator";
import projectsWithCreators from "./project/with-creators";
import timerEnd from "./timer/end";
import timerGet from "./timer/get";
import timerGetInactive from "./timer/get-inactive";
import timerToggle from "./timer/toggle";
import timers from "./timers";
import userByUsername from "./user/by-username";
@@ -76,6 +77,7 @@ export const routes = {
timerToggle,
timerGet,
timerGetInactive,
timerEnd,
timers,
};

View File

@@ -0,0 +1,25 @@
import { calculateBreakTimeMs, calculateWorkTimeMs } from "@issue/shared";
import type { AuthedRequest } from "../../auth/middleware";
import { getInactiveTimedSessions } from "../../db/queries";
// GET /timer?issueId=123
export default async function timerGetInactive(req: AuthedRequest) {
const url = new URL(req.url);
const issueId = url.searchParams.get("issueId");
if (!issueId || Number.isNaN(Number(issueId))) {
return new Response("missing issue id", { status: 400 });
}
const sessions = await getInactiveTimedSessions(Number(issueId));
if (!sessions[0] || !sessions) {
return Response.json(null);
}
return Response.json(
sessions.map((session) => ({
...session,
workTimeMs: calculateWorkTimeMs(session.timestamps),
breakTimeMs: calculateBreakTimeMs(session.timestamps),
})),
);
}