Node/modules/comments/middlewares/post.js
Batuhan Coşkun 88839b0f4d Güncelleme
2025-03-20 13:28:23 +03:00

24 lines
923 B
JavaScript

const { getBlog } = require("../../blogs/middlewares/query");
const { createNotification } = require("../../notifications/middlewares/proccess");
const { getNotificationCode } = require("../../notifications/middlewares/query");
const { Comments } = require("../models/Comments");
exports.createComments = async function({text, blogId, userId}){
return await Comments.create({
text: text,
blogId: blogId,
userId: userId
}).then(async (res) => {
if(res){
await createNotification({
data: {
user: userId,
blog: blogId
},
userId: await getBlog({ blogId: blogId }).then(blog => blog.userId),
notificationCodeId: await getNotificationCode({ draftCode: "blog-comment" }).then(draft => draft.id)
});
return (res) ? true : false;
};
});
};