Closed am0029 closed 1 year ago
Look I don't undertand why and what is the error can you please make a repo so i can fork with the errors oyu are facing and I will try to fix it?
how can i make repository ? u mean i upload into github ? ok
it is my first time i come to github . it was all because of u . i will try to upload my code
I removed everything . upload part make .removed the cloudinary part .
i changed simple mde editor becasue i needed rtl but simple mde editor does not had rtl . but i did it
i changed . postcontroller , post.jsx.new-post.jsx
ok i will upload to github can u wait for me . website is my language . i translate some part of website
ok please wait i upload to github
i think it really take time i downloaded github desktop i think it take time untill ifigure out how upload my project
I upload files . but it was my first time . i did not upload nodemudles folder base on guides in google
based on my question on stack over flow . some one answered to me but i did not understand
I removed cloudinary part . and i change the simple mde . becasue of rtl option
but problem is when user sign up . and wants create post .he can not . it gives error this error https://stackoverflow.com/questions/74770359/tried-every-solution-why-this-error-occurs-body-casterror-cast-to-string-fai
i mean user can not post . i wanted to fix this issue . even some one answered my question in stack overflow . ican not fix
did u understand what am i saying ? sorry for bad english
user can not create post . this is problem
Is the latest repo from one hour ago is the one that's making the problem? If this repo i will download it and fix it.And yeah it will eventually be solved on stackoverflow and I already understand your problem because of the image not uploading (because its required) you can not create post
it is my changed source code . latest repository of you and then i changed too many many times
I removed simplemde react and added draft.js because of rtl option . and i changed language . this cloudinary i removed all things about cloudinary just avatar picture that u send to me that was good .
but user can not create post but he sign up is ok
i make it simple no cloudinary that clodinary problem was a cancer .
just user can post and thats it . simple and beatiful
Again.. Funny this repo is my project from November.. So yeah I oppened it and saw the error you are talking about please make sure to copy my repo right now and test the cloudinary part it will work I promise! and if it didn't without changing the lang upload the repo and i will download it and fix it from there and only when this happen you can change the lang and use it
u mean i uploaded project wrong ? your repo is not commited right now . are u sure ? i downloaded this yesterday sware to my dead mother i have fully know this project . i spend 1 month on it 24/7 .
now i download what project ? this repo last commited was
[switched cloudinary and mongo accounts] in server file and i downloaded yesterday . u mean i download this again ? last commited 2 days ago ?
but i did that yesterday . am i right ? u say i download again new repo that not work ? last commited 2 days ago ?
https://github.com/am0029/dev-to-clone-by-moradov
this is my project that i upload u wanted form me
problem is just i think this post controller that's it 1 file . but i can not understand what is worng i change and change and change but nothing same
`const Post = require('../model/Post'); const User = require('../model/User'); const Tag = require('../model/Tag'); const Comment = require('../model/Comment'); const cloudinary = require('../config/cloudinary'); const { uploadToCloudinary } = require('../utils/cloudinary'); const { getPostParams, unCapitalizeFirstLetter } = require('../helpers/string'); const { createTags, updateTags, deleteTags } = require('./tagsController'); const { likeNotification, removeLikeNotification, postNotification, removePostNotification, } = require('./notificationsController');
const createPost = async (req, res) => { const { title, file, body, tags, authorUsername } = req.body;
// const { url, public_id: publicId } = await uploadToCloudinary(file, 'Posts'); const author = await User.findOne({ username: authorUsername }).exec();
const formattedTags = tags .trim() .split(',') .map(w => w.trim().replace(/ /g, '-'));
const createdPost = await Post.create({ title, body, author: author._id, });
author.followers.map(followerId => { (async () => { await postNotification(author._id, createdPost._id, followerId); })(); });
await createTags(formattedTags, createdPost);
author.posts.push(createdPost._id);
await author.save();
res.status(200).json(createdPost.toObject({ getters: true })); };
const getPost = async (req, res) => { const author = await User.findOne({ username: req.params.username }).exec(); const authorId = await author?.toObject({ getters: true }).id;
const { postTitle, postId } = getPostParams(req.params.postUrl);
const foundPost = await Post.findOne({ author: authorId, title: postTitle, _id: postId, }) .populate('author') .populate('comments') .populate('tags') .exec();
res.status(200).json(foundPost.toObject({ getters: true })); };
const getPosts = async (req, res) => { const { userId } = req.params;
const posts = await Post.find(userId ? { bookmarks: userId } : {}) .sort({ createdAt: -1 }) .populate('author') .populate('tags'); if (!posts) res.status(204).json('No posts found');
res.status(200).json(posts.map(post => post.toObject({ getters: true }))); };
const updatePost = async (req, res) => { const authorId = await User.findOne({ username: req.params.username }).exec(); const { postTitle, postId } = getPostParams(req.params.postUrl);
const { url, public_id: publicId } = await uploadToCloudinary();
await cloudinary.uploader.destroy(req.body.image.publicId);
req.body.image = { url, publicId }; const formattedTags = req.body.tags .trim() .split(',') .map(w => w.trim().replace(/ /g, '-'));
const post = await Post.findOne({ author: authorId, title: postTitle, _id: postId, }) .populate('author') .populate('tags');
Object.keys(req.body).map(key => { if (key !== 'tags') post[key] = req.body[key]; });
await updateTags(formattedTags, post);
await post.save();
res.status(200).json(post.toObject({ getters: true })); };
const deletePostsByUserId = async user => { const { _id: userId } = user;
user.comments.forEach(commentId => { (async () => { await Post.updateMany({ comments: commentId }, { $pull: { comments: commentId } }); })(); });
const posts = await Post.find({ author: userId }).populate('tags');
['likes', 'unicorns', 'bookmarks'].forEach(k => { (async () => { await Post.updateMany({ [k]: userId }, { $pull: { [k]: userId } }); })(); });
posts.forEach(post => { (async () => { await deleteTags( post.tags.map(({ name }) => name), post, true ); await cloudinary.uploader.destroy(post.image.publicId); await Post.deleteOne({ _id: post._id }); })(); });
await Comment.deleteMany({ author: userId }); };
const deletePost = async (req, res) => { const author = await User.findOne({ username: req.params.username }).exec(); const { postTitle, postId } = getPostParams(req.params.postUrl);
await cloudinary.uploader.destroy(req.body.publicId);
const foundPost = await Post.findOne({ author: author._id, title: postTitle, _id: postId, }) .populate('tags') .exec();
if (!foundPost) return res.sendStatus(204);
const comments = await Comment.find({ parentPost: postId }).populate({ path: 'author', populate: 'followers', });
comments.forEach(({ author }) => (async () => { author.comments.forEach(comment => author.comments.pull(comment)); })() ); author.posts.pull(postId); await author.save();
await Comment.deleteMany({ parentPost: postId });
await deleteTags( foundPost.tags.map(({ name }) => name), foundPost, true );
removePostNotification(author._id, foundPost._id, author.followers);
await Post.deleteOne({ _id: foundPost._id });
res.status(200).json(foundPost.toObject({ getters: true })); };
const postReaction = async (req, res) => { const { userId } = req.body; const { action, postUrl } = req.params; const { postTitle, postId } = getPostParams(postUrl); const isUndoing = action.includes('remove'); const actionKey = isUndoing ? unCapitalizeFirstLetter(action.replace('remove', '')) + 's' : action + 's';
const author = await User.findOne({ username: req.params.username }).exec(); const authorId = await author.toObject({ getters: true }).id;
const updatedPost = await Post.findOneAndUpdate( { author: authorId, title: postTitle, _id: postId }, isUndoing ? { $pull: { [actionKey]: userId } } : { $addToSet: { [actionKey]: userId } }, { new: true, timestamps: false } );
if (isUndoing) await removeLikeNotification(userId, updatedPost._id, authorId); else await likeNotification(userId, updatedPost._id, authorId);
res.status(200).json(updatedPost.toObject({ getters: true })); };
module.exports = { createPost, getPosts, getPost, updatePost, deletePost, deletePostsByUserId, postReaction, }; `
That's wrong.. Sorry I can't describe how complicated is it, I will make this work for you only if you contacted me via email from your personal mail there's some to discuss.
sorry my friend . my last question i removed the cloudinary part from website but i face error that not going away at any const
can u answer please i did this . i removed cloudinary part but it just isError occurs
https://stackoverflow.com/questions/74770359/tried-every-solution-why-this-error-occurs-body-casterror-cast-to-string-fai