File size: 969 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { RedisCache } from "./redis-client";

// No expiration - feedback is stored permanently
const feedbackCache = new RedisCache("chat:feedback", 0);

export interface ChatFeedback {
  type: "positive" | "negative" | "other";
  comment?: string;
  createdAt: string;
  userId: string;
  teamId: string;
  chatId: string;
  messageId: string;
}

export const chatFeedbackCache = {
  set: (
    chatId: string,
    messageId: string,
    userId: string,
    feedback: Omit<ChatFeedback, "chatId" | "messageId" | "userId">,
  ): Promise<void> => {
    const key = `${chatId}:${messageId}:${userId}`;
    const fullFeedback: ChatFeedback = {
      ...feedback,
      chatId,
      messageId,
      userId,
    };

    return feedbackCache.set(key, fullFeedback, 0);
  },

  delete: (
    chatId: string,
    messageId: string,
    userId: string,
  ): Promise<void> => {
    const key = `${chatId}:${messageId}:${userId}`;
    return feedbackCache.delete(key);
  },
};