Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecercise update #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions exercises/modules/node/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const data = require('./data')
const data=require("./data");

const getUserById = (id, cb) => {
// simulate API call
setTimeout(() => {
setTimeout(() => {
const user = data.users.find(user => user.id === id)
cb(user)
}, 150)
Expand All @@ -11,12 +11,12 @@ const getUserById = (id, cb) => {
const getPostsForUser = (userId, cb) => {
// simulate API call
setTimeout(() => {
const posts = data.posts.filter(post => post.createdBy === userId)
cb(posts)
const _posts = data.posts.filter(post => post.createdBy === userId)
cb(_posts)
}, 150)
}

module.exports = {
getUserById,
getPostsForUser
}
module.exports={
getPostsForUser,
getUserById
}
14 changes: 8 additions & 6 deletions exercises/modules/node/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const api = require('./api')
const { getPostsForUser, getUserById} =require("./api");

window.App = window.App || {}

const showPostsForCurrentUser = (userId, cb) => {
api.getPostsForUser(userId, posts => {
getPostsForUser(userId, posts => {
const postTemplates = posts.map(post => {
return `
<div class="post">
Expand All @@ -15,19 +17,19 @@ const showPostsForCurrentUser = (userId, cb) => {
}

const showUserProfile = (userId, cb) => {
api.getUserById(userId, user => {
getUserById(userId, user => {
const profile = `
<div>
${user.name}
</div>
`
cb(profile)
cb(user)
})
}

module.exports = {

module.exports={
showPostsForCurrentUser,
showUserProfile
}


2 changes: 1 addition & 1 deletion exercises/modules/node/data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
module.exports= {
users: [
{id: 1, name: 'Weezy'}
],
Expand Down
Loading