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,29 +1,21 @@
|
||||
import { User } from '@caldav/shared';
|
||||
import { UserRepository, CreateUserData } from '../../services/interfaces';
|
||||
import { UserModel, UserDocument } from './models';
|
||||
import { UserModel } from './models';
|
||||
|
||||
export class MongoUserRepository implements UserRepository {
|
||||
private toUser(doc: UserDocument): User {
|
||||
return {
|
||||
id: doc._id.toString(),
|
||||
email: doc.email,
|
||||
displayName: doc.displayName,
|
||||
createdAt: doc.createdAt,
|
||||
updatedAt: doc.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<User | null> {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
async findByEmail(email: string): Promise<User | null> {
|
||||
const user = await UserModel.findOne({ email: email.toLowerCase() });
|
||||
return user ? this.toUser(user) : null;
|
||||
// NOTE: Casting required because Mongoose's toJSON() type doesn't reflect our virtual 'id' field
|
||||
return (user?.toJSON() as unknown as User) ?? null;
|
||||
}
|
||||
|
||||
async create(data: CreateUserData): Promise<User> {
|
||||
const user = await UserModel.create(data);
|
||||
return this.toUser(user);
|
||||
// NOTE: Casting required because Mongoose's toJSON() type doesn't reflect our virtual 'id' field
|
||||
return user.toJSON() as unknown as User;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user