Skip to content

Commit

Permalink
More direct fetch in delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas committed Dec 12, 2024
1 parent ffb865c commit abfd5f8
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions front/lib/api/assistant/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { canAccessConversation } from "@app/lib/api/assistant/conversation";
import type { AgentMessageFeedbackDirection } from "@app/lib/api/assistant/conversation/feedbacks";
import type { Authenticator } from "@app/lib/auth";
import { AgentConfiguration } from "@app/lib/models/assistant/agent";
import { AgentMessage } from "@app/lib/models/assistant/conversation";
import {
AgentMessage,
AgentMessageFeedback,
} from "@app/lib/models/assistant/conversation";
import { Message } from "@app/lib/models/assistant/conversation";
import { AgentMessageFeedbackResource } from "@app/lib/resources/agent_message_feedback_resource";

Expand Down Expand Up @@ -282,35 +285,39 @@ export async function deleteMessageFeedback(
sId: messageId,
conversationId: conversation.id,
},
include: [
{
model: AgentMessage,
as: "agentMessage",
include: [
{
model: AgentMessageFeedbackResource.model,
as: "feedbacks",
where: {
userId: user.id,
},
},
],
},
],
attributes: ["agentMessageId"],
});

if (!message || !message.agentMessageId) {
return null;
}

const agentMessage = await AgentMessage.findOne({
where: {
id: message.agentMessageId,
},
});

if (!agentMessage) {
return null;
}

const feedback =
await AgentMessageFeedbackResource.fetchByUserAndAgentMessage({
auth,
user,
agentMessage,
});

if (!feedback) {
if (
!message ||
!message.agentMessage ||
!message.agentMessage.feedbacks ||
message.agentMessage.feedbacks.length === 0
) {
return null;
}

const deletedFeedback = await feedback.delete(auth);
const feedback = message.agentMessage.feedbacks[0];
const feedbackRessource = new AgentMessageFeedbackResource(
AgentMessageFeedback,
feedback.get()
);
const deletedFeedback = await feedbackRessource.delete(auth);

return deletedFeedback.isOk();
}

0 comments on commit abfd5f8

Please sign in to comment.