birDB
birDB is a birdwatching journal and social media site allowing you to learn about recent birds sighted, add field notes and images to a personal birdwatching journal, share sightings with others, and chat about similar interests.
Personal Tasks
- Front end site population for multiple and single posts.
- Comment functionality - add, edit and delete comments.
- Follow user functionality.
- Implemented backend route handling and functionality for home and post pages.
Languages/Technologies
Code Snippet - Follow Another User, Database Update and Send Back Info
//add follow
router.put('/user/:userPostsID', gatekeeper, async (req,res) => {
console.log('put');
let userPostsID = req.params.userPostsID
let record = await db.users.findByPk(req.user.id);
let userID = record.id
let dates = [];
let date = new Date();
let unsplitFollowing = record.following
let followingIDList = (unsplitFollowing !== null)? unsplitFollowing.split(','): [];
if(!followingIDList.includes(userPostsID)){
if (unsplitFollowing){
unsplitFollowing += `,${userPostsID}`
} else {
unsplitFollowing = userPostsID
}
await db.users.update({following: unsplitFollowing}, {where: {id: userID}});
}
date.setDate(date.getDate() - 3);
let updatedRecord = await db.users.findByPk(req.user.id);
let recentPosts = await db.posts.findAll({where: {userID: userPostsID} });
let updatedFollowing = updatedRecord.following
let updatedFollowingList = (updatedFollowing !== null)? updatedFollowing.split(','): []
console.log(updatedFollowingList);
let usernames = await arrayIterator(recentPosts, getUsername);
let following = await arrayIterator(followingIDList, getFollowingUsers);
recentPosts.forEach(post => {
let rawDate = post.dataValues.createdAt
let formattedDate = {
"month": monthNames[rawDate.getMonth()],
"day": rawDate.getDate()
}
dates.push(formattedDate);
});
res.render('index', {
username: record.username,
userID: record.id,
following: updatedFollowingList,
recentPosts: recentPosts,
dates: dates,
usernames: usernames
});
});