Created
February 13, 2022 10:36
-
-
Save vjrngn/73153313fd6e41866058fae9a171b42c to your computer and use it in GitHub Desktop.
Contrived JS DI
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
const User = require('./db/user'); | |
const interface = { | |
find(id) {}, | |
update(id, data) {} | |
} | |
// index.js or main.js | |
// const userRoute = requrie('./routes/users'); | |
const mongo = { | |
find(id) {}, | |
update(id, data) {} | |
} | |
const firestore = { | |
find(id) {}, | |
update(id, data) {} | |
} | |
const userRoutes = userRoute(firestore); | |
router.get('/users', userRoutes.getUser); | |
module.exports = function (database) { | |
return { | |
async getUser(req, res) { | |
const user = await database.find(req.body.id); | |
// logic to compute inventory | |
database.update(); | |
return res.json({ | |
user | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment