implement event persistence and improve Mongoose TypeScript patterns
- Add event persistence: confirmed events are now saved to MongoDB - Refactor Mongoose models to use virtuals for id field with IdVirtual interface - Update repositories to use toJSON() with consistent type casting - Add more test responses for chat (doctor, birthday, gym, etc.) - Show event description in ProposedEventCard - Change mongo-express port to 8083 - Update CLAUDE.md with Mongoose model pattern documentation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ChatMessage, ChatResponse, SendMessageDTO, ConversationSummary, GetMessagesOptions, ProposedEventChange, getDay } from '@caldav/shared';
|
||||
import { ChatMessage, ChatResponse, SendMessageDTO, ConversationSummary, GetMessagesOptions, ProposedEventChange, getDay, CreateEventDTO } from '@caldav/shared';
|
||||
import { ChatRepository, EventRepository, AIProvider } from './interfaces';
|
||||
|
||||
// Test responses array (cycles through responses)
|
||||
@@ -41,6 +41,120 @@ const testResponses: Array<{ content: string; proposedChange?: ProposedEventChan
|
||||
"Samstag, 18.01. - 10:00 Uhr: Badezimmer putzen\n\n" +
|
||||
"Insgesamt 3 Termine.",
|
||||
},
|
||||
// Response 4: Doctor appointment with description
|
||||
{
|
||||
content: "Ich habe dir einen Arzttermin eingetragen. Denk daran, deine Versichertenkarte mitzunehmen!",
|
||||
proposedChange: {
|
||||
action: 'create',
|
||||
event: {
|
||||
title: "Arzttermin Dr. Müller",
|
||||
startTime: getDay('Wednesday', 1, 9, 30),
|
||||
endTime: getDay('Wednesday', 1, 10, 30),
|
||||
description: "Routineuntersuchung - Versichertenkarte nicht vergessen",
|
||||
}
|
||||
}
|
||||
},
|
||||
// Response 5: Birthday - yearly recurring
|
||||
{
|
||||
content: "Geburtstage vergisst man leicht - aber nicht mit mir! Ich habe Mamas Geburtstag eingetragen:",
|
||||
proposedChange: {
|
||||
action: 'create',
|
||||
event: {
|
||||
title: "Mamas Geburtstag",
|
||||
startTime: getDay('Thursday', 2, 0, 0),
|
||||
endTime: getDay('Thursday', 2, 23, 59),
|
||||
isRecurring: true,
|
||||
recurrenceRule: "FREQ=YEARLY",
|
||||
}
|
||||
}
|
||||
},
|
||||
// Response 6: Gym - recurring for 2 months (8 weeks)
|
||||
{
|
||||
content: "Perfekt! Ich habe dein Probetraining eingetragen - jeden Dienstag für die nächsten 2 Monate:",
|
||||
proposedChange: {
|
||||
action: 'create',
|
||||
event: {
|
||||
title: "Fitnessstudio Probetraining",
|
||||
startTime: getDay('Tuesday', 1, 18, 0),
|
||||
endTime: getDay('Tuesday', 1, 19, 30),
|
||||
isRecurring: true,
|
||||
recurrenceRule: "FREQ=WEEKLY;BYDAY=TU;COUNT=8",
|
||||
}
|
||||
}
|
||||
},
|
||||
// Response 7: Weekly calendar overview (text only)
|
||||
{
|
||||
content: "Hier ist dein Überblick für nächste Woche:\n\n" +
|
||||
"Montag - Keine Termine\n" +
|
||||
"Dienstag, 18:00 Uhr: Fitnessstudio\n" +
|
||||
"Mittwoch, 09:30 Uhr: Arzttermin Dr. Müller\n" +
|
||||
"Donnerstag - Keine Termine\n" +
|
||||
"Freitag, 14:00 Uhr: Meeting mit Jens\n" +
|
||||
"Samstag, 10:00 Uhr: Badezimmer putzen\n" +
|
||||
"Sonntag, 11:00 Uhr: Telefonat mit Mama\n\n" +
|
||||
"Insgesamt 5 Termine nächste Woche.",
|
||||
},
|
||||
// Response 8: Help response (text only)
|
||||
{
|
||||
content: "Ich bin dein Kalender-Assistent! Du kannst mir einfach sagen, welche Termine du erstellen, ändern oder löschen möchtest. Zum Beispiel:\n\n" +
|
||||
"• \"Erstelle einen Termin für morgen um 15 Uhr\"\n" +
|
||||
"• \"Was habe ich nächste Woche vor?\"\n" +
|
||||
"• \"Verschiebe das Meeting auf Donnerstag\"\n\n" +
|
||||
"Wie kann ich dir helfen?",
|
||||
},
|
||||
// Response 9: Phone call - short appointment
|
||||
{
|
||||
content: "Alles klar! Ich habe das Telefonat mit deiner Mutter eingetragen:",
|
||||
proposedChange: {
|
||||
action: 'create',
|
||||
event: {
|
||||
title: "Telefonat mit Mama",
|
||||
startTime: getDay('Sunday', 0, 11, 0),
|
||||
endTime: getDay('Sunday', 0, 11, 30),
|
||||
}
|
||||
}
|
||||
},
|
||||
// Response 10: Birthday party - evening event
|
||||
{
|
||||
content: "Super! Die Geburtstagsfeier ist eingetragen. Viel Spaß!",
|
||||
proposedChange: {
|
||||
action: 'create',
|
||||
event: {
|
||||
title: "Geburtstagsfeier Lisa",
|
||||
startTime: getDay('Saturday', 2, 19, 0),
|
||||
endTime: getDay('Saturday', 2, 23, 0),
|
||||
description: "Geschenk: Buch über Fotografie",
|
||||
}
|
||||
}
|
||||
},
|
||||
// Response 11: Language course - limited to 8 weeks
|
||||
{
|
||||
content: "Dein Spanischkurs ist eingetragen! Er läuft jeden Donnerstag für die nächsten 8 Wochen:",
|
||||
proposedChange: {
|
||||
action: 'create',
|
||||
event: {
|
||||
title: "Spanischkurs VHS",
|
||||
startTime: getDay('Thursday', 1, 19, 0),
|
||||
endTime: getDay('Thursday', 1, 20, 30),
|
||||
isRecurring: true,
|
||||
recurrenceRule: "FREQ=WEEKLY;BYDAY=TH;COUNT=8",
|
||||
}
|
||||
}
|
||||
},
|
||||
// Response 12: Monthly calendar overview (text only)
|
||||
{
|
||||
content: "Hier ist deine Monatsübersicht für Januar:\n\n" +
|
||||
"KW 2: 3 Termine\n" +
|
||||
" • Mi 08.01., 09:30: Arzttermin Dr. Müller\n" +
|
||||
" • Fr 10.01., 14:00: Meeting mit Jens\n" +
|
||||
" • Sa 11.01., 10:00: Badezimmer putzen\n\n" +
|
||||
"KW 3: 4 Termine\n" +
|
||||
" • Di 14.01., 18:00: Fitnessstudio\n" +
|
||||
" • Do 16.01., 19:00: Spanischkurs VHS\n" +
|
||||
" • Sa 18.01., 10:00: Badezimmer putzen\n" +
|
||||
" • Sa 18.01., 19:00: Geburtstagsfeier Lisa\n\n" +
|
||||
"Insgesamt 7 Termine im Januar.",
|
||||
},
|
||||
// }}}
|
||||
];
|
||||
|
||||
@@ -66,12 +180,14 @@ export class ChatService {
|
||||
return { message, conversationId: message.conversationId };
|
||||
}
|
||||
|
||||
async confirmEvent(userId: string, conversationId: string, messageId: string): Promise<ChatResponse> {
|
||||
async confirmEvent(userId: string, conversationId: string, messageId: string, event: CreateEventDTO): Promise<ChatResponse> {
|
||||
const createdEvent = await this.eventRepo.create(userId, event);
|
||||
|
||||
const message: ChatMessage = {
|
||||
id: Date.now().toString(),
|
||||
conversationId,
|
||||
sender: 'assistant',
|
||||
content: 'Der Vorschlag wurde angenommen.',
|
||||
content: `Der Termin "${createdEvent.title}" wurde erstellt.`,
|
||||
};
|
||||
return { message, conversationId };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user