32 lines
892 B
JavaScript
32 lines
892 B
JavaScript
const Blogs = require("../models/Blogs");
|
|
const SavedBlogs = require("../models/SavedBlogs");
|
|
const { getSaved } = require("./query");
|
|
const { checkLenText } = require("./tools");
|
|
|
|
exports.createBlog = async function(data, user){
|
|
const checkTitle = checkLenText(data.title, 5, 25);
|
|
const checkText = checkLenText(data.text, 10, 1000);
|
|
if(checkTitle && checkText){
|
|
return await Blogs.create({
|
|
title: data.title,
|
|
text: data.text,
|
|
categoryId: data.cate,
|
|
userId: user.id
|
|
});
|
|
}else{
|
|
return false;
|
|
};
|
|
};
|
|
|
|
exports.createSaved = async function({blogId, userId}){
|
|
const checkQuery = await getSaved({blogId: blogId, userId: userId});
|
|
|
|
if(!checkQuery){
|
|
return await SavedBlogs.create({
|
|
blogId: blogId,
|
|
userId: userId
|
|
});
|
|
}else{
|
|
return false;
|
|
};
|
|
}; |