Last active
April 30, 2023 21:21
-
-
Save christopherbauer/04a5131bf138d751207e65ab29fcb6da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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