import { users, classes, bookings, newsletters, contactMessages } from "@shared/schema"; import type { User, InsertUser, Class, InsertClass, Booking, InsertBooking, Newsletter, InsertNewsletter, ContactMessage, InsertContactMessage } from "@shared/schema"; import session from "express-session"; import createMemoryStore from "memorystore"; const MemoryStore = createMemoryStore(session); export interface IStorage { // User Management getUser(id: number): Promise; getUserByUsername(username: string): Promise; getUserByEmail(email: string): Promise; createUser(user: InsertUser): Promise; // Class Management getClasses(): Promise; getClass(id: number): Promise; createClass(classData: InsertClass): Promise; // Booking Management getBookings(userId?: number): Promise; getBooking(id: number): Promise; createBooking(booking: InsertBooking): Promise; updateBookingStatus(id: number, status: string): Promise; // Newsletter Management getNewsletterByEmail(email: string): Promise; createNewsletter(newsletter: InsertNewsletter): Promise; // Contact Management createContactMessage(message: InsertContactMessage): Promise; // Session Store sessionStore: session.SessionStore; } export class MemStorage implements IStorage { private users: Map; private classes: Map; private bookings: Map; private newsletters: Map; private contactMessages: Map; currentUserId: number; currentClassId: number; currentBookingId: number; currentNewsletterId: number; currentContactMessageId: number; sessionStore: session.SessionStore; constructor() { this.users = new Map(); this.classes = new Map(); this.bookings = new Map(); this.newsletters = new Map(); this.contactMessages = new Map(); this.currentUserId = 1; this.currentClassId = 1; this.currentBookingId = 1; this.currentNewsletterId = 1; this.currentContactMessageId = 1; this.sessionStore = new MemoryStore({ checkPeriod: 86400000 // prune expired entries every 24h }); // Initialize with some default classes this.seedClasses(); } // User Management async getUser(id: number): Promise { return this.users.get(id); } async getUserByUsername(username: string): Promise { return Array.from(this.users.values()).find( (user) => user.username === username ); } async getUserByEmail(email: string): Promise { return Array.from(this.users.values()).find( (user) => user.email === email ); } async createUser(insertUser: InsertUser): Promise { const id = this.currentUserId++; const user: User = { ...insertUser, id, createdAt: new Date() }; this.users.set(id, user); return user; } // Class Management async getClasses(): Promise { return Array.from(this.classes.values()); } async getClass(id: number): Promise { return this.classes.get(id); } async createClass(classData: InsertClass): Promise { const id = this.currentClassId++; const newClass: Class = { ...classData, id }; this.classes.set(id, newClass); return newClass; } // Booking Management async getBookings(userId?: number): Promise { const bookings = Array.from(this.bookings.values()); if (userId) { return bookings.filter(booking => booking.userId === userId); } return bookings; } async getBooking(id: number): Promise { return this.bookings.get(id); } async createBooking(booking: InsertBooking): Promise { const id = this.currentBookingId++; const newBooking: Booking = { ...booking, id, createdAt: new Date() }; this.bookings.set(id, newBooking); return newBooking; } async updateBookingStatus(id: number, status: string): Promise { const booking = this.bookings.get(id); if (booking) { const updatedBooking = { ...booking, status }; this.bookings.set(id, updatedBooking); return updatedBooking; } return undefined; } // Newsletter Management async getNewsletterByEmail(email: string): Promise { return Array.from(this.newsletters.values()).find( (newsletter) => newsletter.email === email ); } async createNewsletter(newsletter: InsertNewsletter): Promise { const id = this.currentNewsletterId++; const newNewsletter: Newsletter = { ...newsletter, id, createdAt: new Date() }; this.newsletters.set(id, newNewsletter); return newNewsletter; } // Contact Management async createContactMessage(message: InsertContactMessage): Promise { const id = this.currentContactMessageId++; const newMessage: ContactMessage = { ...message, id, createdAt: new Date() }; this.contactMessages.set(id, newMessage); return newMessage; } // Seed default data private seedClasses() { const defaultClasses: InsertClass[] = [ { name: "Mat Pilates", description: "A foundational class focusing on core strength, proper alignment, and mindful movement patterns.", duration: 60, price: 2500, // $25.00 capacity: 15, classType: "group", imageUrl: "https://images.unsplash.com/photo-1571902943202-507ec2618e8f" }, { name: "Reformer", description: "Equipment-based sessions that enhance resistance training for deeper muscle engagement.", duration: 55, price: 4000, // $40.00 capacity: 8, classType: "small-group", imageUrl: "https://images.unsplash.com/photo-1562088287-bde35a1ea917" }, { name: "Private Sessions", description: "Personalized attention and customized programming to meet your specific goals and needs.", duration: 60, price: 7500, // $75.00 capacity: 1, classType: "private", imageUrl: "https://images.unsplash.com/photo-1616279969856-759f316a5ac1" } ]; defaultClasses.forEach(classData => { this.createClass(classData); }); } } export const storage = new MemStorage();