mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-12 00:18:27 +00:00
Enhance: knowledge graphs with implicit relationships - Added a new API route for deleting episodes, including related statements and entities. - Introduced error handling for unauthorized access and non-existent episodes. - Enhanced the KnowledgeGraphService with methods for resolving entities and managing relationships during deletions. - Updated entity and episode models to support new deletion logic and ensure data integrity.
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { z } from "zod";
|
|
import { json } from "@remix-run/node";
|
|
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
|
|
import { deleteEpisodeWithRelatedNodes } from "~/services/graphModels/episode";
|
|
|
|
export const DeleteEpisodeBodyRequest = z.object({
|
|
episodeUuid: z.string().uuid("Episode UUID must be a valid UUID"),
|
|
});
|
|
|
|
const { action, loader } = createActionApiRoute(
|
|
{
|
|
body: DeleteEpisodeBodyRequest,
|
|
allowJWT: true,
|
|
method: "DELETE",
|
|
authorization: {
|
|
action: "delete",
|
|
},
|
|
corsStrategy: "all",
|
|
},
|
|
async ({ body, authentication }) => {
|
|
try {
|
|
const result = await deleteEpisodeWithRelatedNodes({
|
|
episodeUuid: body.episodeUuid,
|
|
userId: authentication.userId,
|
|
});
|
|
|
|
if (!result.episodeDeleted) {
|
|
return json(
|
|
{
|
|
error: "Episode not found or unauthorized",
|
|
code: "not_found"
|
|
},
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
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 }; |