Skip to content

Instantly share code, notes, and snippets.

@christopherbauer
Last active April 30, 2023 21:21
Show Gist options
  • Save christopherbauer/04a5131bf138d751207e65ab29fcb6da to your computer and use it in GitHub Desktop.
Save christopherbauer/04a5131bf138d751207e65ab29fcb6da to your computer and use it in GitHub Desktop.
export interface User {
firstName: string;
lastName: string;
}
class NotFoundError extends Error {}
export class DataAccessLayer {
users: Record<number, User> = {};
findUser(id: number): User {
return this.users[id];
}
updateUser(id: number, user: User): Boolean {
if (this.users[id]) {
this.users[id] = user;
return true;
}
throw new NotFoundError();
}
insertUser(user: User): number {
const id = Object.keys(this.users).length;
this.users[id] = user;
return id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment