Adding manual entries + UI cleanup

This commit is contained in:
2026-01-16 16:28:06 -07:00
parent 38fe0ea9ce
commit 15b903f1af
12 changed files with 817 additions and 135 deletions

View File

@@ -1,51 +1,66 @@
import type { APIRoute } from 'astro';
import { db } from '../../../db';
import { timeEntries, members, timeEntryTags, categories } from '../../../db/schema';
import { eq, and, isNull } from 'drizzle-orm';
import { nanoid } from 'nanoid';
import type { APIRoute } from "astro";
import { db } from "../../../db";
import {
timeEntries,
members,
timeEntryTags,
categories,
} from "../../../db/schema";
import { eq, and, isNull } from "drizzle-orm";
import { nanoid } from "nanoid";
export const POST: APIRoute = async ({ request, locals }) => {
if (!locals.user) return new Response('Unauthorized', { status: 401 });
if (!locals.user) return new Response("Unauthorized", { status: 401 });
const body = await request.json();
const description = body.description || '';
const description = body.description || "";
const clientId = body.clientId;
const categoryId = body.categoryId;
const tags = body.tags || [];
if (!clientId) {
return new Response('Client is required', { status: 400 });
return new Response("Client is required", { status: 400 });
}
if (!categoryId) {
return new Response('Category is required', { status: 400 });
return new Response("Category is required", { status: 400 });
}
const runningEntry = await db.select().from(timeEntries).where(
and(
eq(timeEntries.userId, locals.user.id),
isNull(timeEntries.endTime)
const runningEntry = await db
.select()
.from(timeEntries)
.where(
and(eq(timeEntries.userId, locals.user.id), isNull(timeEntries.endTime)),
)
).get();
.get();
if (runningEntry) {
return new Response('Timer already running', { status: 400 });
return new Response("Timer already running", { status: 400 });
}
const member = await db.select().from(members).where(eq(members.userId, locals.user.id)).limit(1).get();
const member = await db
.select()
.from(members)
.where(eq(members.userId, locals.user.id))
.limit(1)
.get();
if (!member) {
return new Response('No organization found', { status: 400 });
return new Response("No organization found", { status: 400 });
}
const category = await db.select().from(categories).where(
and(
eq(categories.id, categoryId),
eq(categories.organizationId, member.organizationId)
const category = await db
.select()
.from(categories)
.where(
and(
eq(categories.id, categoryId),
eq(categories.organizationId, member.organizationId),
),
)
).get();
.get();
if (!category) {
return new Response('Invalid category', { status: 400 });
return new Response("Invalid category", { status: 400 });
}
const startTime = new Date();
@@ -59,6 +74,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
categoryId,
startTime,
description,
isManual: false,
});
if (tags.length > 0) {
@@ -66,7 +82,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
tags.map((tagId: string) => ({
timeEntryId: id,
tagId,
}))
})),
);
}