mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 23:18:26 +00:00
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
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({
|
|
id: z.string(),
|
|
});
|
|
|
|
const { action, loader } = createHybridActionApiRoute(
|
|
{
|
|
body: DeleteEpisodeBodyRequest,
|
|
allowJWT: true,
|
|
method: "DELETE",
|
|
authorization: {
|
|
action: "delete",
|
|
},
|
|
corsStrategy: "all",
|
|
},
|
|
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: output?.episodeUuid,
|
|
userId: authentication.userId,
|
|
});
|
|
|
|
if (!result.episodeDeleted) {
|
|
return json(
|
|
{
|
|
error: "Episode not found or unauthorized",
|
|
code: "not_found",
|
|
},
|
|
{ status: 404 },
|
|
);
|
|
}
|
|
|
|
await deleteIngestionQueue(ingestionQueue.id);
|
|
|
|
return json({
|
|
success: true,
|
|
message: "Episode deleted successfully",
|
|
deleted: {
|
|
episode: result.episodeDeleted,
|
|
statements: result.statementsDeleted,
|
|
entities: result.entitiesDeleted,
|
|
facts: result.factsDeleted,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error("Error deleting episode:", error);
|
|
return json(
|
|
{
|
|
error: "Failed to delete episode",
|
|
code: "internal_error",
|
|
},
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
export { action, loader };
|