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,9 +1,12 @@
|
||||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
import mongoose, { Schema, Document, Model } from 'mongoose';
|
||||
import { User } from '@caldav/shared';
|
||||
import { IdVirtual } from './types';
|
||||
|
||||
export interface UserDocument extends Omit<User, 'id'>, Document {}
|
||||
export interface UserDocument extends Omit<User, 'id'>, Document {
|
||||
toJSON(): User;
|
||||
}
|
||||
|
||||
const UserSchema = new Schema<UserDocument>(
|
||||
const UserSchema = new Schema<UserDocument, Model<UserDocument, {}, {}, IdVirtual>, {}, {}, IdVirtual>(
|
||||
{
|
||||
email: {
|
||||
type: String,
|
||||
@@ -24,9 +27,16 @@ const UserSchema = new Schema<UserDocument>(
|
||||
},
|
||||
{
|
||||
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;
|
||||
delete ret.passwordHash;
|
||||
|
||||
Reference in New Issue
Block a user