This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import { db } from "../../../db";
|
||||
import { timeEntries, members, timeEntryTags } from "../../../db/schema";
|
||||
import { timeEntries, members } from "../../../db/schema";
|
||||
import { eq, and, isNull } from "drizzle-orm";
|
||||
import { nanoid } from "nanoid";
|
||||
import { validateTimeEntryResources } from "../../../lib/validation";
|
||||
@@ -11,7 +11,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
const body = await request.json();
|
||||
const description = body.description || "";
|
||||
const clientId = body.clientId;
|
||||
const tags = body.tags || [];
|
||||
const tagId = body.tagId || null;
|
||||
|
||||
if (!clientId) {
|
||||
return new Response("Client is required", { status: 400 });
|
||||
@@ -42,7 +42,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
const validation = await validateTimeEntryResources({
|
||||
organizationId: member.organizationId,
|
||||
clientId,
|
||||
tagIds: tags,
|
||||
tagId,
|
||||
});
|
||||
|
||||
if (!validation.valid) {
|
||||
@@ -57,19 +57,11 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
userId: locals.user.id,
|
||||
organizationId: member.organizationId,
|
||||
clientId,
|
||||
tagId,
|
||||
startTime,
|
||||
description,
|
||||
isManual: false,
|
||||
});
|
||||
|
||||
if (tags.length > 0) {
|
||||
await db.insert(timeEntryTags).values(
|
||||
tags.map((tagId: string) => ({
|
||||
timeEntryId: id,
|
||||
tagId,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ id, startTime }), { status: 200 });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user