Skip to content

Instantly share code, notes, and snippets.

@vedranjukic
Last active December 16, 2017 12:58
Show Gist options
  • Save vedranjukic/0dbcb0e06a4c3c4cb45c654c99fa12ce to your computer and use it in GitHub Desktop.
Save vedranjukic/0dbcb0e06a4c3c4cb45c654c99fa12ce to your computer and use it in GitHub Desktop.
User repository Mongo db adapter factory
//
// UserRepositoryMongo factory implementing UserRepository interface
//
export default db => {
const users = db.get('users')
const create = async (user) => {
const { userId } = user
await users.insert(user)
}
const getById = async (userId) => {
const user = await users.findOne({userId})
if (!user) {
throw new UserNotFoundException()
}
return user
}
const save = async (user) => {
const { userId } = user
await users.update({
userId
}, user)
}
return {
create,
getById,
save
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment