24 lines
923 B
JavaScript
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;
|
|
};
|
|
});
|
|
}; |