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:
2026-01-04 11:52:05 +01:00
parent c33508a227
commit 9fecf94c7d
13 changed files with 240 additions and 48 deletions

View File

@@ -1,9 +1,12 @@
import mongoose, { Schema, Document } from 'mongoose';
import mongoose, { Schema, Document, Model } from 'mongoose';
import { CalendarEvent } from '@caldav/shared';
import { IdVirtual } from './types';
export interface EventDocument extends Omit<CalendarEvent, 'id'>, Document {}
export interface EventDocument extends Omit<CalendarEvent, 'id'>, Document {
toJSON(): CalendarEvent;
}
const EventSchema = new Schema<EventDocument>(
const EventSchema = new Schema<EventDocument, Model<EventDocument, {}, {}, IdVirtual>, {}, {}, IdVirtual>(
{
userId: {
type: String,
@@ -40,9 +43,16 @@ const EventSchema = new Schema<EventDocument>(
},
{
timestamps: true,
virtuals: {
id: {
get() {
return this._id.toString();
},
},
},
toJSON: {
virtuals: true,
transform: (_, ret: Record<string, unknown>) => {
ret.id = String(ret._id);
delete ret._id;
delete ret.__v;
return ret;