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 } from "drizzle-orm";
|
||||
import { nanoid } from "nanoid";
|
||||
import {
|
||||
@@ -17,7 +17,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { description, clientId, startTime, endTime, tags } = body;
|
||||
const { description, clientId, startTime, endTime, tagId } = body;
|
||||
|
||||
// Validation
|
||||
if (!clientId) {
|
||||
@@ -74,7 +74,7 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
const resourceValidation = await validateTimeEntryResources({
|
||||
organizationId: member.organizationId,
|
||||
clientId,
|
||||
tagIds: Array.isArray(tags) ? tags : undefined,
|
||||
tagId: tagId || null,
|
||||
});
|
||||
|
||||
if (!resourceValidation.valid) {
|
||||
@@ -93,22 +93,13 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
||||
userId: locals.user.id,
|
||||
organizationId: member.organizationId,
|
||||
clientId,
|
||||
tagId: tagId || null,
|
||||
startTime: startDate,
|
||||
endTime: endDate,
|
||||
description: description || null,
|
||||
isManual: true,
|
||||
});
|
||||
|
||||
// Insert tags if provided
|
||||
if (tags && Array.isArray(tags) && tags.length > 0) {
|
||||
await db.insert(timeEntryTags).values(
|
||||
tags.map((tagId: string) => ({
|
||||
timeEntryId: id,
|
||||
tagId,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user