This file contains 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 getInfo = () => | |
axios.get('/users') | |
.then(users => { | |
console.log(users) | |
}) | |
.then(() => getGroups()) | |
.then(groups => { | |
console.log(groups) | |
}) | |
.then(() => getFavorites()) |
This file contains 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 getInfo = async () => { | |
console.log(await axios.get('/users')) | |
console.log(await getGroups()) | |
console.log(await getFavorites()) | |
return 'all done'; | |
} | |
getInfo(); |
This file contains 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 associateUsers = () => { | |
try { | |
doSynchronousThings() | |
return getUsers() | |
.then(users => users.map(user => user.getAddress())); | |
.catch(e => console.error(e)) | |
} catch(err){ | |
console.error(err) | |
} | |
} |
This file contains 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 associateUsers = async () => { | |
try { | |
doSynchronousthings() | |
const users = await getUsers() | |
return users.map(user => user.getAddress()); | |
} catch(err){ | |
console.error(err) | |
} | |
} |
This file contains 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
router.get('/user/:id', async (req, res, next) => { | |
try { | |
const user = await getUserFromDb({ id: req.params.id }) | |
res.json(user); | |
} catch (e) { | |
//this will eventually be handled by your error handling middleware | |
next(e) | |
} | |
}) |
This file contains 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 asyncMiddleware = fn => | |
(req, res, next) => { | |
Promise.resolve(fn(req, res, next)) | |
.catch(next); | |
}; |
This file contains 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 asyncMiddleware = require('./utils/asyncMiddleware'); | |
router.get('/users/:id', asyncMiddleware(async (req, res, next) => { | |
/* | |
if there is an error thrown in getUserFromDb, asyncMiddleware | |
will pass it to next() and express will handle the error; | |
*/ | |
const user = await getUserFromDb({ id: req.params.id }) | |
res.json(user); | |
})); |
This file contains 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 db = require('../_db'); | |
const Sequelize = require('sequelize'); | |
class tag extends Sequelize.Model { | |
//methods, hooks, etc.... | |
} | |
tag.init({ | |
name: { | |
type: Sequelize.STRING(100), |
This file contains 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 db = require('../_db'); | |
const Sequelize = require('sequelize'); | |
class story extends Sequelize.Model { | |
//methods, hooks, etc.... | |
} | |
story.init({ | |
title: { | |
type: Sequelize.STRING, |
This file contains 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 Tag = require('./tag') | |
const Story = require('./story') | |
Tag.belongsToMany(Story) | |
Story.belongsToMany(Tag) | |
OlderNewer