Fix: delete episode api -> ingestion delete api

This commit is contained in:
Harshith Mullapudi 2025-07-17 15:17:58 +05:30
parent 7fa0320d91
commit ac811bfcb3
7 changed files with 48 additions and 40 deletions

View File

@ -310,7 +310,7 @@ export const Graph = forwardRef<GraphRef, GraphProps>(
...settings,
barnesHutOptimize: true,
strongGravityMode: false,
gravity: 0.1,
gravity: 1,
scalingRatio: 10,
slowDown: 5,
},

View File

@ -20,6 +20,7 @@ interface LogTextCollapseProps {
text?: string;
error?: string;
logData: any;
id: string;
episodeUUID?: string;
}
@ -27,6 +28,7 @@ export function LogTextCollapse({
episodeUUID,
text,
error,
id,
logData,
}: LogTextCollapseProps) {
const [dialogOpen, setDialogOpen] = useState(false);
@ -34,17 +36,16 @@ export function LogTextCollapse({
const deleteFetcher = useFetcher();
const handleDelete = () => {
console.log(logData);
if (!episodeUUID) {
console.error("No episodeUuid found in log data");
return;
}
deleteFetcher.submit(
{ episodeUuid: episodeUUID },
{ id },
{
method: "DELETE",
action: "/api/v1/episode/delete",
action: "/api/v1/ingestion_queue/delete",
encType: "application/json",
},
);

View File

@ -100,6 +100,7 @@ function LogItemRenderer(
text={log.ingestText}
error={log.error}
logData={log.data}
id={log.id}
episodeUUID={log.episodeUUID}
/>
</CardContent>

View File

@ -2,9 +2,13 @@ import { z } from "zod";
import { json } from "@remix-run/node";
import { createHybridActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { deleteEpisodeWithRelatedNodes } from "~/services/graphModels/episode";
import {
deleteIngestionQueue,
getIngestionQueue,
} from "~/services/ingestionLogs.server";
export const DeleteEpisodeBodyRequest = z.object({
episodeUuid: z.string().uuid("Episode UUID must be a valid UUID"),
id: z.string(),
});
const { action, loader } = createHybridActionApiRoute(
@ -19,8 +23,22 @@ const { action, loader } = createHybridActionApiRoute(
},
async ({ body, authentication }) => {
try {
const ingestionQueue = await getIngestionQueue(body.id);
if (!ingestionQueue) {
return json(
{
error: "Episode not found or unauthorized",
code: "not_found",
},
{ status: 404 },
);
}
const output = ingestionQueue.output as any;
const result = await deleteEpisodeWithRelatedNodes({
episodeUuid: body.episodeUuid,
episodeUuid: output?.episodeUuid,
userId: authentication.userId,
});
@ -34,6 +52,8 @@ const { action, loader } = createHybridActionApiRoute(
);
}
await deleteIngestionQueue(ingestionQueue.id);
return json({
success: true,
message: "Episode deleted successfully",

View File

@ -1,30 +0,0 @@
import { json } from "@remix-run/node";
import { z } from "zod";
import { createHybridActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
const TestSchema = z.object({
message: z.string(),
});
// This route can be called with either:
// 1. Personal access token: Authorization: Bearer <token>
// 2. Cookie-based authentication (when logged in via browser)
const { action, loader } = createHybridActionApiRoute(
{
body: TestSchema,
method: "POST",
corsStrategy: "all",
},
async ({ body, authentication }) => {
return json({
success: true,
message: body.message,
authType: authentication.type,
userId: authentication.userId,
// Only include scopes if it's API key authentication
...(authentication.type === "PRIVATE" && { scopes: authentication.scopes }),
});
},
);
export { action, loader };

View File

@ -44,3 +44,19 @@ export async function getIngestionLogs(
},
};
}
export const getIngestionQueue = async (id: string) => {
return await prisma.ingestionQueue.findUnique({
where: {
id,
},
});
};
export const deleteIngestionQueue = async (id: string) => {
return await prisma.ingestionQueue.delete({
where: {
id,
},
});
};

View File

@ -272,7 +272,7 @@ async function handleMessageResponse(
// Handle "activity" messages
if (grouped["activity"]) {
return await handleActivityMessage(
await handleActivityMessage(
grouped["activity"],
integrationAccountId as string,
userId,
@ -281,7 +281,7 @@ async function handleMessageResponse(
// Handle "state" messages
if (grouped["state"]) {
return await handleStateMessage(
await handleStateMessage(
grouped["state"],
integrationAccountId as string,
);
@ -289,12 +289,12 @@ async function handleMessageResponse(
// Handle "identifier" messages
if (grouped["identifier"]) {
return await handleIdentifierMessage(grouped["identifier"][0]);
await handleIdentifierMessage(grouped["identifier"][0]);
}
// Handle "account" messages (these may involve Prisma writes)
if (grouped["account"]) {
return await handleAccountMessage(
await handleAccountMessage(
grouped["account"],
integrationDefinition,
workspaceId,