Files
calchat/apps/server/src/repositories/mongo/MongoUserRepository.ts
Linus Waldowsky 9fecf94c7d 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
2026-01-04 11:52:05 +01:00

22 lines
863 B
TypeScript

import { User } from '@caldav/shared';
import { UserRepository, CreateUserData } from '../../services/interfaces';
import { UserModel } from './models';
export class MongoUserRepository implements UserRepository {
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() });
// 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);
// NOTE: Casting required because Mongoose's toJSON() type doesn't reflect our virtual 'id' field
return user.toJSON() as unknown as User;
}
}