Merge branch 'master' into edit-profile-image-upload

This commit is contained in:
2019-10-27 23:46:15 -04:00
committed by GitHub
9 changed files with 155 additions and 58 deletions

View File

@@ -4,9 +4,9 @@ exports.putPost = (req, res) => {
const newPost = {
body: req.body.body,
userHandle: req.body.userHandle,
userHandle: req.userData.handle,
userImage: req.body.userImage,
userID: req.userData.userID,
userID: req.userData.userId,
microBlogTitle: req.body.microBlogTitle,
createdAt: new Date().toISOString(),
likeCount: 0,
@@ -28,7 +28,7 @@ exports.putPost = (req, res) => {
};
exports.getallPostsforUser = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
.then((data) => {
let posts = [];
data.forEach(function(doc) {

View File

@@ -1,5 +1,5 @@
/* eslint-disable promise/always-return */
const admin = require('firebase-admin');
const { admin, db } = require("../util/admin");
exports.putTopic = (req, res) => {
const newTopic = {
@@ -9,6 +9,7 @@ exports.putTopic = (req, res) => {
admin.firestore().collection('topics').add(newTopic)
.then((doc) => {
const resTopic = newTopic;
newTopic.topicId = doc.id;
return res.status(200).json(resTopic);
})
.catch((err) => {
@@ -17,8 +18,6 @@ exports.putTopic = (req, res) => {
});
};
exports.getAllTopics = (req, res) => {
admin.firestore().collection('topics').get()
.then((data) => {
@@ -30,6 +29,24 @@ exports.getAllTopics = (req, res) => {
})
.catch((err) => {
console.error(err);
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
return res.status(500).json({error: 'Failed to fetch all topics.'})
})
};
};
exports.deleteTopic = (req, res) => {
const topic = db.doc(`/topics/${req.params.topicId}`);
topic.get().then((doc) => {
if (!doc.exists) {
return res.status(404).json({error: 'Topic not found'});
} else {
return topic.delete();
}
})
.then(() => {
res.json({ message: 'Topic successfully deleted!'});
})
.catch((err) => {
console.error(err);
return res.status(500).json({error: 'Failed to delete topic.'})
})
}

View File

@@ -80,7 +80,8 @@ exports.signup = (req, res) => {
handle: newUser.handle,
createdAt: newUser.createdAt,
imageUrl: `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${noImg}?alt=media`,
userId
userId,
followedTopics: []
};
handle2Email.set(userCred.handle, userCred.email);
return db.doc(`/users/${newUser.handle}`).set(userCred);