Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Created July 1, 2020 12:21
Show Gist options
  • Save kianaditya/c6d3ebad376d78f7219b76efa8b23bdd to your computer and use it in GitHub Desktop.
Save kianaditya/c6d3ebad376d78f7219b76efa8b23bdd to your computer and use it in GitHub Desktop.
const db = require('../models')
exports.getUser = async (req, res, next) => {
const user = await db.User.findOne({
where: { email: req.user.email },
attributes: ['firstName', 'lastName'],
include: [
{
model: db.Post,
as: 'Written',
attributes: ['id', 'title', 'content'],
},
{
model: db.Post,
as: 'Saved',
attributes: ['id', 'title', 'content'],
through: {
attributes: [],
},
},
],
})
res.status(200).send(user)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment