Created
July 6, 2020 13:11
-
-
Save kianaditya/bd4dbcc0b6cc31ddac937f4a111c9faa 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
const db = require('../index') | |
const getAllPosts = async () => { | |
const allPosts = await db.Post.findAll({ | |
attributes: ['id', 'title', 'content'], | |
include: [ | |
{ | |
model: db.User, | |
as: 'Author', | |
attributes: ['firstName', 'lastName'], | |
}, | |
], | |
}) | |
return allPosts | |
} | |
const getSpecificPost = async (postId) => { | |
const specificPost = await db.Post.findOne({ | |
where: { | |
id: postId, | |
}, | |
attributes: ['id', 'title', 'content'], | |
include: [ | |
{ | |
model: db.User, | |
as: 'Author', | |
attributes: ['firstName', 'lastName'], | |
}, | |
{ | |
model: db.User, | |
as: 'savedBy', | |
attributes: ['firstName', 'lastName'], | |
through: { | |
attributes: [], | |
}, | |
}, | |
], | |
}) | |
return specificPost | |
} | |
module.exports = { | |
getAllPosts, | |
getSpecificPost, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment