import { type Session, type InsertSession, type DeviceProfile, type InsertDeviceProfile } from "@shared/schema"; import { randomUUID } from "crypto"; export interface IStorage { // Sessions createSession(session: InsertSession): Promise; getSessionsByDeviceId(deviceId: string, limit?: number): Promise; getSessionsInDateRange(deviceId: string, startDate: Date, endDate: Date): Promise; // Device Profiles createDeviceProfile(profile: InsertDeviceProfile): Promise; getDeviceProfile(deviceId: string): Promise; updateDeviceProfileActivity(deviceId: string): Promise; } export class MemStorage implements IStorage { private sessions: Map = new Map(); private deviceProfiles: Map = new Map(); async createSession(insertSession: InsertSession): Promise { const id = randomUUID(); const session: Session = { ...insertSession, id, }; this.sessions.set(id, session); return session; } async getSessionsByDeviceId(deviceId: string, limit = 50): Promise { const sessions = Array.from(this.sessions.values()) .filter(session => session.deviceId === deviceId) .sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()) .slice(0, limit); return sessions; } async getSessionsInDateRange(deviceId: string, startDate: Date, endDate: Date): Promise { const sessions = Array.from(this.sessions.values()) .filter(session => { const sessionDate = new Date(session.startedAt); return session.deviceId === deviceId && sessionDate >= startDate && sessionDate <= endDate; }) .sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()); return sessions; } async createDeviceProfile(insertProfile: InsertDeviceProfile): Promise { const id = randomUUID(); const now = new Date(); const profile: DeviceProfile = { ...insertProfile, id, createdAt: now, lastActiveAt: now, }; this.deviceProfiles.set(insertProfile.deviceId, profile); return profile; } async getDeviceProfile(deviceId: string): Promise { return this.deviceProfiles.get(deviceId); } async updateDeviceProfileActivity(deviceId: string): Promise { const profile = this.deviceProfiles.get(deviceId); if (profile) { profile.lastActiveAt = new Date(); this.deviceProfiles.set(deviceId, profile); } } } export const storage = new MemStorage();