Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
39 lines
993 B
TypeScript
39 lines
993 B
TypeScript
import { type User, type InsertUser } from "@shared/schema";
|
|
import { randomUUID } from "crypto";
|
|
|
|
// modify the interface with any CRUD methods
|
|
// you might need
|
|
|
|
export interface IStorage {
|
|
getUser(id: string): Promise<User | undefined>;
|
|
getUserByUsername(username: string): Promise<User | undefined>;
|
|
createUser(user: InsertUser): Promise<User>;
|
|
}
|
|
|
|
export class MemStorage implements IStorage {
|
|
private users: Map<string, User>;
|
|
|
|
constructor() {
|
|
this.users = new Map();
|
|
}
|
|
|
|
async getUser(id: string): Promise<User | undefined> {
|
|
return this.users.get(id);
|
|
}
|
|
|
|
async getUserByUsername(username: string): Promise<User | undefined> {
|
|
return Array.from(this.users.values()).find(
|
|
(user) => user.username === username,
|
|
);
|
|
}
|
|
|
|
async createUser(insertUser: InsertUser): Promise<User> {
|
|
const id = randomUUID();
|
|
const user: User = { ...insertUser, id };
|
|
this.users.set(id, user);
|
|
return user;
|
|
}
|
|
}
|
|
|
|
export const storage = new MemStorage();
|