mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
display work time in issue detail pane
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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))),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
25
packages/backend/src/routes/timer/get-inactive.ts
Normal file
25
packages/backend/src/routes/timer/get-inactive.ts
Normal 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),
|
||||
})),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user