This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import { db } from "../../../db";
|
||||
import {
|
||||
timeEntries,
|
||||
members,
|
||||
timeEntryTags,
|
||||
categories,
|
||||
} from "../../../db/schema";
|
||||
import { timeEntries, members, timeEntryTags } from "../../../db/schema";
|
||||
import { eq, and, isNull } from "drizzle-orm";
|
||||
import { nanoid } from "nanoid";
|
||||
import { validateTimeEntryResources } from "../../../lib/validation";
|
||||
|
||||
export const POST: APIRoute = async ({ request, locals }) => {
|
||||
if (!locals.user) return new Response("Unauthorized", { status: 401 });
|
||||
@@ -48,19 +44,15 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
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),
|
||||
),
|
||||
)
|
||||
.get();
|
||||
const validation = await validateTimeEntryResources({
|
||||
organizationId: member.organizationId,
|
||||
clientId,
|
||||
categoryId,
|
||||
tagIds: tags,
|
||||
});
|
||||
|
||||
if (!category) {
|
||||
return new Response("Invalid category", { status: 400 });
|
||||
if (!validation.valid) {
|
||||
return new Response(validation.error, { status: 400 });
|
||||
}
|
||||
|
||||
const startTime = new Date();
|
||||
|
||||
Reference in New Issue
Block a user