⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
import { eq } from "drizzle-orm";
import { HTTPException } from "hono/http-exception";
import db from "../../database";
import { timeEntryTable } from "../../database/schema";
import { resolveDuration } from "../duration";
type UpdateTimeEntryParams = {
timeEntryId: string;
startTime: Date;
endTime?: Date;
description?: string;
};
async function updateTimeEntry(params: UpdateTimeEntryParams) {
const { timeEntryId, startTime, endTime, description } = params;
const [existingTimeEntry] = await db
.select()
.from(timeEntryTable)
.where(eq(timeEntryTable.id, timeEntryId));
if (!existingTimeEntry) {
throw new HTTPException(404, {
message: "Time entry not found",
});
}
const effectiveEndTime = endTime ?? existingTimeEntry.endTime;
const duration = resolveDuration(startTime, effectiveEndTime ?? undefined);
const [updatedTimeEntry] = await db
.update(timeEntryTable)
.set({
startTime,
endTime: effectiveEndTime,
duration,
...(description !== undefined && { description }),
})
.where(eq(timeEntryTable.id, timeEntryId))
.returning();
return updatedTimeEntry;
}
export default updateTimeEntry;