Güncelleme
This commit is contained in:
parent
6398729133
commit
88839b0f4d
110
database/dump.js
110
database/dump.js
@ -1,8 +1,12 @@
|
||||
const Blogs = require("../modules/blogs/models/Blogs");
|
||||
const Categories = require("../modules/blogs/models/Categories");
|
||||
const { ReBlog } = require("../modules/blogs/models/ReBlogs");
|
||||
const SavedBlogs = require("../modules/blogs/models/SavedBlogs");
|
||||
const { Comments } = require("../modules/comments/models/Comments");
|
||||
const { Follow } = require("../modules/follows/models");
|
||||
const Login = require("../modules/logins/models/login");
|
||||
const { Notifications, NotificationCodes } = require("../modules/notifications/models/Notifications");
|
||||
const { CustomSettings } = require("../modules/settings/models/Settings");
|
||||
const User = require("../modules/users/models/user");
|
||||
|
||||
User.User.hasMany(Login, {
|
||||
@ -13,6 +17,30 @@ User.User.hasMany(Login, {
|
||||
});
|
||||
Login.belongsTo(User.User);
|
||||
|
||||
User.User.hasMany(CustomSettings, {
|
||||
foreignKey: {
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
CustomSettings.belongsTo(User.User);
|
||||
|
||||
User.User.hasMany(Notifications, {
|
||||
foreignKey: {
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
Notifications.belongsTo(User.User);
|
||||
|
||||
NotificationCodes.hasMany(Notifications, {
|
||||
foreignKey: {
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
Notifications.belongsTo(NotificationCodes);
|
||||
|
||||
User.User.hasMany(Blogs, {
|
||||
foreignKey:{
|
||||
allowNull: false,
|
||||
@ -45,6 +73,38 @@ User.User.hasMany(SavedBlogs, {
|
||||
});
|
||||
SavedBlogs.belongsTo(User.User);
|
||||
|
||||
User.User.hasMany(ReBlog, {
|
||||
foreignKey:{
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
ReBlog.belongsTo(User.User);
|
||||
|
||||
Blogs.hasMany(ReBlog, {
|
||||
foreignKey:{
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
ReBlog.belongsTo(Blogs);
|
||||
|
||||
Blogs.hasMany(Comments, {
|
||||
foreignKey:{
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
Comments.belongsTo(Blogs);
|
||||
|
||||
User.User.hasMany(Comments, {
|
||||
foreignKey:{
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
Comments.belongsTo(User.User);
|
||||
|
||||
User.Education.hasMany(User.User, {
|
||||
foreignKey:{
|
||||
allowNull: true,
|
||||
@ -130,43 +190,73 @@ exports.createTesting = async function(){
|
||||
email: "batuhancoskun@yaani.com",
|
||||
password: "Yaren2010",
|
||||
userId: 1
|
||||
},{
|
||||
email: "bc1428@yaani.com",
|
||||
password: "Sena1996",
|
||||
userId: 2
|
||||
},{
|
||||
email: "bc1428@vuhuv.com",
|
||||
password: "Sena2023",
|
||||
userId: 3
|
||||
}]);
|
||||
|
||||
await Categories.bulkCreate([{
|
||||
id: 1,
|
||||
title: "Profil"
|
||||
title: "Profil",
|
||||
href: "profile"
|
||||
},{
|
||||
id: 2,
|
||||
title: "Teknoloji"
|
||||
title: "Teknoloji",
|
||||
href: "technology"
|
||||
},{
|
||||
id: 3,
|
||||
title: "Siyaset"
|
||||
title: "Siyaset",
|
||||
href: "politics"
|
||||
},{
|
||||
id: 4,
|
||||
title: "Sağlık"
|
||||
title: "Sağlık",
|
||||
href: "health"
|
||||
},{
|
||||
id: 5,
|
||||
title: "Felsefe"
|
||||
title: "Felsefe",
|
||||
href: "philosophy"
|
||||
},{
|
||||
id: 6,
|
||||
title: "Doğa"
|
||||
title: "Doğa",
|
||||
href: "nature"
|
||||
},{
|
||||
id: 7,
|
||||
title: "Gıda"
|
||||
title: "Gıda",
|
||||
href: "food"
|
||||
}]);
|
||||
|
||||
await Blogs.bulkCreate([{
|
||||
id: 1,
|
||||
title: "Bu Bir Başlıktır",
|
||||
text: "Merhaba, bu benim yazımdır.",
|
||||
title: "",
|
||||
text: "Gönderi - 1.",
|
||||
userId: 1,
|
||||
categoryId: 1
|
||||
},{
|
||||
id: 2,
|
||||
text: "Merhaba, bu benim yazımdır.",
|
||||
text: "Gönderi - 2.",
|
||||
userId: 2,
|
||||
categoryId: 4
|
||||
},{
|
||||
id: 3,
|
||||
text: "Gönderi - 3.",
|
||||
userId: 3,
|
||||
categoryId: 4
|
||||
}]);
|
||||
|
||||
await NotificationCodes.bulkCreate([{
|
||||
id: 1,
|
||||
code: "blog-saved"
|
||||
}, {
|
||||
id: 2,
|
||||
code: "blog-reblog"
|
||||
}, {
|
||||
id: 3,
|
||||
code: "blog-comment"
|
||||
}]);
|
||||
};
|
||||
};
|
||||
4
index.js
4
index.js
@ -52,12 +52,16 @@ const moduleBlog = require("./modules/blogs/app");
|
||||
const moduleUser = require("./modules/users/app");
|
||||
const moduleStream = require("./modules/streams/app");
|
||||
const moduleFollow = require("./modules/follows/app");
|
||||
const moduleNotification = require("./modules/notifications/app");
|
||||
const moduleComment = require("./modules/comments/app");
|
||||
|
||||
app.use(moduleLogin);
|
||||
app.use(moduleBlog);
|
||||
app.use(moduleUser);
|
||||
app.use(moduleStream);
|
||||
app.use(moduleFollow);
|
||||
app.use(moduleNotification);
|
||||
app.use(moduleComment);
|
||||
|
||||
// DATABASES
|
||||
const DatabaseDump = require("./database/dump");
|
||||
|
||||
@ -1,6 +1,21 @@
|
||||
{
|
||||
"homepage" : "Homepage",
|
||||
"blogs" : "Blogs",
|
||||
"notifications" : "Notifications",
|
||||
"peoples" : "Peoples",
|
||||
"services" : "Services"
|
||||
"settings" : "Settings",
|
||||
"services" : "Services",
|
||||
"name" : "Name",
|
||||
"surname" : "Surname",
|
||||
"language" : "Language",
|
||||
"hometown" : "Hometown",
|
||||
"profession" : "Profession",
|
||||
"birthday" : "Birthday",
|
||||
"minute" : "Minute",
|
||||
"hour" : "Hour",
|
||||
"day" : "Day",
|
||||
|
||||
"saved_your_post" : "saved your post",
|
||||
"reblog_your_post" : "reblog your post",
|
||||
"comment_your_post" : "commented your post"
|
||||
}
|
||||
@ -1,6 +1,17 @@
|
||||
{
|
||||
"homepage" : "",
|
||||
"blogs" : "nç̌ara",
|
||||
"homepage" : "Nana Masvare",
|
||||
"blogs" : "Nç̌ara",
|
||||
"notifications" : "Mçinpe",
|
||||
"peoples" : "Şurepe",
|
||||
"services" : ""
|
||||
"settings" : "Ǩampe",
|
||||
"services" : "Servisepe",
|
||||
"name" : "Yoxo",
|
||||
"surname" : "Sacumalo",
|
||||
"language" : "Nena",
|
||||
"hometown" : "Dobadona",
|
||||
"profession" : "Slop̌ua",
|
||||
"birthday" : "Dobadu",
|
||||
"minute" : "Ťeǩeǩe",
|
||||
"hour" : "Saaťi",
|
||||
"day" : "Ğoma"
|
||||
}
|
||||
@ -1,6 +1,22 @@
|
||||
{
|
||||
"homepage" : "Anasayfa",
|
||||
"blogs" : "Yazılar",
|
||||
"peoples" : "Kişiler",
|
||||
"services" : "Servisler"
|
||||
"homepage" : "Anasayfa",
|
||||
"blogs" : "Yazılar",
|
||||
"notifications" : "Bildirimler",
|
||||
"peoples" : "Kişiler",
|
||||
"settings" : "Ayarlar",
|
||||
"services" : "Servisler",
|
||||
"name" : "İsim",
|
||||
"surname" : "Soyisim",
|
||||
"language" : "Dil",
|
||||
"hello" : "hello",
|
||||
"hometown" : "Memleket",
|
||||
"profession" : "Meslek",
|
||||
"birthday" : "Doğum Günü",
|
||||
"minute" : "Dakika",
|
||||
"hour" : "Saat",
|
||||
"day" : "Gün",
|
||||
|
||||
"saved_your_post" : "gönderinizi beğendi",
|
||||
"reblog_your_post" : "gönderinizi paylaştı",
|
||||
"comment_your_post" : "gönderinize yorum yaptı"
|
||||
}
|
||||
7
middlewares/general/checks.js
Normal file
7
middlewares/general/checks.js
Normal file
@ -0,0 +1,7 @@
|
||||
exports.isEmptyForString = function(text){
|
||||
return !((typeof text === "string") && (
|
||||
text === undefined ||
|
||||
text === null ||
|
||||
text === ""
|
||||
));
|
||||
};
|
||||
40
middlewares/general/datatime.js
Normal file
40
middlewares/general/datatime.js
Normal file
@ -0,0 +1,40 @@
|
||||
exports.buildDatetime = function({date}){
|
||||
const data = new Object({
|
||||
differance: new Object(),
|
||||
normal: new Object(),
|
||||
locale: {
|
||||
minute: "minute",
|
||||
hour: "hour",
|
||||
day: "day"
|
||||
}
|
||||
});
|
||||
|
||||
date = new Date(date);
|
||||
const now = Date.now();
|
||||
const differance = now - date;
|
||||
|
||||
data.differance.minute = (differance / (1000 * 60)).toFixed();
|
||||
data.differance.hour = (differance / (1000 * 60 * 60)).toFixed();
|
||||
data.differance.day = (differance / (1000 * 60 * 60 * 24)).toFixed();
|
||||
|
||||
if(data.differance.minute < 60){
|
||||
data.differance.current = "minute";
|
||||
}else if(data.differance.hour < 24 && data.differance.hour >= 1){
|
||||
data.differance.current = "hour";
|
||||
}else if(data.differance.day >= 1 && data.differance.day < 7){
|
||||
data.differance.current = "day";
|
||||
};
|
||||
|
||||
data.normal.day = date.getUTCDate();
|
||||
data.normal.month = date.getMonth() + 1;
|
||||
data.normal.year = date.getFullYear();
|
||||
data.normal.hour = date.getHours();
|
||||
data.normal.minute = date.getMinutes();
|
||||
data.normal.dateText = `${repairTextDate(data.normal.day)}.${repairTextDate(data.normal.month)}.${repairTextDate(data.normal.year)} ${repairTextDate(data.normal.hour)}:${repairTextDate(data.normal.minute)}`;
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const repairTextDate = function(date){
|
||||
return (date < 10) ? "0" + date : date;
|
||||
};
|
||||
@ -1,16 +1,21 @@
|
||||
const { createNotification } = require("../../notifications/middlewares/proccess");
|
||||
const { getNotificationCode } = require("../../notifications/middlewares/query");
|
||||
const { getUserWithId } = require("../../users/middlewares/query");
|
||||
const Blogs = require("../models/Blogs");
|
||||
const { ReBlog } = require("../models/ReBlogs");
|
||||
const SavedBlogs = require("../models/SavedBlogs");
|
||||
const { getSaved } = require("./query");
|
||||
const { getSaved, getBlog } = 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){
|
||||
console.log(data, user)
|
||||
return await Blogs.create({
|
||||
title: data.title,
|
||||
text: data.text,
|
||||
categoryId: data.cate,
|
||||
categoryId: data.categoryId,
|
||||
userId: user.id
|
||||
});
|
||||
}else{
|
||||
@ -26,7 +31,18 @@ exports.createSaved = async function({blogId, userId}){
|
||||
blogId: blogId,
|
||||
userId: userId,
|
||||
statu: true
|
||||
}).then(get => {return (get) ? true : false});
|
||||
}).then(async get => {
|
||||
const myUser = await getUserWithId({ userId: userId });
|
||||
await createNotification({
|
||||
data: {
|
||||
user: userId,
|
||||
blog: blogId
|
||||
},
|
||||
userId: await getBlog({ blogId: blogId }).then(blog => blog.userId),
|
||||
notificationCodeId: await getNotificationCode({ draftCode: "blog-saved" }).then(draft => draft.id)
|
||||
});
|
||||
return (get) ? true : false
|
||||
});
|
||||
return {Status: "Success", data: result}
|
||||
}else if(checkQuery){
|
||||
const result = await SavedBlogs.update(
|
||||
@ -37,9 +53,42 @@ exports.createSaved = async function({blogId, userId}){
|
||||
userId: userId
|
||||
}
|
||||
}
|
||||
).then(get => {return (get) && !checkQuery.statu});
|
||||
).then(async get => {;
|
||||
if(!checkQuery.statu == true){
|
||||
// await createNotification({
|
||||
// data: {
|
||||
// user: userId,
|
||||
// blog: blogId
|
||||
// },
|
||||
// userId: await getBlog({ blogId: blogId }).then(blog => blog.userId),
|
||||
// notificationCodeId: await getNotificationCode({ draftCode: "blog-saved" }).then(draft => draft.id)
|
||||
// });
|
||||
};
|
||||
return (get) && !checkQuery.statu;
|
||||
});
|
||||
return {Status: "Success", data: result};
|
||||
}else{
|
||||
return {Status: "Failed"};
|
||||
};
|
||||
};
|
||||
|
||||
exports.createReBlog = async function(blogId, userId){
|
||||
return await ReBlog.create({
|
||||
userId: userId,
|
||||
blogId: blogId
|
||||
}).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-reblog" }).then(draft => draft.id)
|
||||
});
|
||||
return {Status: "Success", data: res};
|
||||
}else{
|
||||
return {Status: "Failed"};
|
||||
};
|
||||
});
|
||||
};
|
||||
60
modules/blogs/middlewares/proccess.js
Normal file
60
modules/blogs/middlewares/proccess.js
Normal file
@ -0,0 +1,60 @@
|
||||
const { buildDatetime } = require("../../../middlewares/general/datatime");
|
||||
|
||||
exports.editedListPosts = async function(blogs, reBlogs){
|
||||
const blogsId = blogs.map(get => get.id);
|
||||
const reBlogsId = new Array();
|
||||
|
||||
const result = new Array(...blogs);
|
||||
|
||||
reBlogs.map(res => {
|
||||
if(res.blog){
|
||||
editedReBlog(res);
|
||||
if(!blogsId.includes(res.blog.id) && !reBlogsId.includes(res.blog.id)){
|
||||
res.blog.dataValues.reblog = true;
|
||||
res.blog.dataValues.reUser = res.user;
|
||||
result.push(res.blog);
|
||||
reBlogsId.push(res.blog.id);
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
result.map(res => {
|
||||
editedPost(res);
|
||||
});
|
||||
|
||||
result.sort((a, b) => b.createdAt - a.createdAt);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const editedPost = function(blog){
|
||||
blog.dataValues.date = new Object();
|
||||
blog.dataValues.date.createdAt = buildDatetime({date: blog.createdAt});
|
||||
blog.dataValues.date.updatedAt = buildDatetime({date: blog.updatedAt});
|
||||
};
|
||||
exports.editedPost = editedPost;
|
||||
|
||||
const editedReBlog = function(data){
|
||||
data.blog.dataValues.reBlog = new Object({
|
||||
date: new Object()
|
||||
});
|
||||
|
||||
data.blog.dataValues.reBlog.date.createdAt = buildDatetime({date: data.createdAt});
|
||||
data.blog.dataValues.reBlog.date.updatedAt = buildDatetime({date: data.updatedAt});
|
||||
};
|
||||
exports.editedReBlog = editedReBlog;
|
||||
|
||||
const startAndEndDates = function(blogs, endDate){
|
||||
if(blogs.length > 0){
|
||||
return {
|
||||
status: true,
|
||||
startDate: (endDate) ?? blogs[0].createdAt,
|
||||
endDate: blogs[blogs.length - 1].createdAt
|
||||
};
|
||||
}else {
|
||||
return {
|
||||
status: false
|
||||
};
|
||||
};
|
||||
};
|
||||
exports.startAndEndDates = startAndEndDates;
|
||||
@ -1,10 +1,37 @@
|
||||
const User = require("../../users/models/user").User;
|
||||
const { where, Op } = require("sequelize");
|
||||
const { Follow } = require("../../follows/models");
|
||||
const Blogs = require("../models/Blogs");
|
||||
const Categories = require("../models/Categories");
|
||||
const SavedBlogs = require("../models/SavedBlogs");
|
||||
const { getFollowingsForIds } = require("../../follows/middlewares/query");
|
||||
const { ReBlog } = require("../models/ReBlogs");
|
||||
const { editedListPosts, editedPost, startAndEndDates } = require("./proccess");
|
||||
const { Comments } = require("../../comments/models/Comments");
|
||||
|
||||
exports.getBlog = async function({blogId, myUserId}) {
|
||||
const blog = await Blogs.findOne({
|
||||
where: {
|
||||
id: blogId
|
||||
},
|
||||
include: [User, Categories, {
|
||||
model: SavedBlogs,
|
||||
where: [(myUserId) ? {
|
||||
userId: myUserId
|
||||
} : {}],
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}]
|
||||
});
|
||||
|
||||
(blog) && editedPost(blog);
|
||||
|
||||
return blog;
|
||||
};
|
||||
|
||||
exports.getBlogs = async function({myUserId}){
|
||||
console.log(myUserId, 456);
|
||||
return await Blogs.findAll({
|
||||
include: [User, Categories, {
|
||||
model: SavedBlogs,
|
||||
@ -17,12 +44,90 @@ exports.getBlogs = async function({myUserId}){
|
||||
});
|
||||
};
|
||||
|
||||
exports.getBlogsWithUsername = async function({username, category, myUserId}){
|
||||
return await Blogs.findAll({
|
||||
exports.getBlogsWithUserId = async function({userId, category, myUserId, endDate = false, blogIds = false}){
|
||||
endDate = (endDate !== false) && new Date(endDate);
|
||||
console.log(endDate)
|
||||
const blogs = await Blogs.findAll({
|
||||
where: {
|
||||
[Op.and]: [{
|
||||
userId: userId
|
||||
}, (blogIds !== false) && {
|
||||
[Op.not]: {
|
||||
id: blogIds
|
||||
}
|
||||
},(endDate !== false) && {
|
||||
createdAt: {
|
||||
[Op.lt]: endDate
|
||||
}
|
||||
}]
|
||||
},
|
||||
include:[(category) ? {
|
||||
model: Categories,
|
||||
where: {
|
||||
title: category
|
||||
href: category
|
||||
}
|
||||
} : Categories, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: myUserId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}, User],
|
||||
limit: 20,
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
const date = startAndEndDates(blogs, endDate);
|
||||
|
||||
const reblogs = await ReBlog.findAll({
|
||||
where:[{
|
||||
userId: userId
|
||||
}, (date.status === true && blogIds) ? {
|
||||
createdAt: {
|
||||
[Op.between]: [date.endDate, date.startDate]
|
||||
}
|
||||
} : {}],
|
||||
include: [{
|
||||
model: Blogs,
|
||||
where: {
|
||||
[Op.not]: {
|
||||
id: blogIds
|
||||
}
|
||||
},
|
||||
include: [(category) ? {
|
||||
model: Categories,
|
||||
where: {
|
||||
href: category
|
||||
}
|
||||
} : Categories, User, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: myUserId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}]
|
||||
}, User],
|
||||
limit: 20,
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
const result = await editedListPosts(blogs, reblogs);
|
||||
|
||||
return result.slice(0, 20);
|
||||
};
|
||||
|
||||
exports.getBlogsWithUsername = async function({username, category, myUserId}){
|
||||
const blogs = await Blogs.findAll({
|
||||
include:[(category) ? {
|
||||
model: Categories,
|
||||
where: {
|
||||
href: category
|
||||
}
|
||||
} : Categories, {
|
||||
model: User,
|
||||
@ -38,9 +143,40 @@ exports.getBlogsWithUsername = async function({username, category, myUserId}){
|
||||
}],
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
const reblogs = await ReBlog.findAll({
|
||||
include: [{
|
||||
model: Blogs,
|
||||
include: [Categories, {
|
||||
model: User,
|
||||
include: {
|
||||
model: Follow,
|
||||
where: {
|
||||
user: myUserId
|
||||
}
|
||||
},
|
||||
required: true
|
||||
}, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: myUserId
|
||||
}
|
||||
}]
|
||||
}, User]
|
||||
});
|
||||
|
||||
const result = new Array(...blogs);
|
||||
|
||||
reblogs.map(res => {
|
||||
res.blog.dataValues.reblog = true;
|
||||
res.blog.dataValues.reUser = res.user;
|
||||
result.push(res.blog);
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.getBlogsWithCategory = async function({categoryId, categoryTitle, myUserId}){
|
||||
exports.getBlogsWithCategory = async function({categoryId, categoryTitle, categoryHref, myUserId}){
|
||||
return await Blogs.findAll({
|
||||
include: [User, Categories, {
|
||||
model: Categories,
|
||||
@ -48,6 +184,8 @@ exports.getBlogsWithCategory = async function({categoryId, categoryTitle, myUser
|
||||
id: categoryId
|
||||
}, (categoryTitle) && {
|
||||
title: categoryTitle
|
||||
}, (categoryHref) && {
|
||||
href: categoryHref
|
||||
}]
|
||||
},{
|
||||
model: SavedBlogs,
|
||||
@ -60,6 +198,325 @@ exports.getBlogsWithCategory = async function({categoryId, categoryTitle, myUser
|
||||
});
|
||||
};
|
||||
|
||||
exports.getBlogsWithFollows = async function({userId, endDate, blogIds = false}){
|
||||
endDate = (endDate) && new Date(endDate);
|
||||
console.log(blogIds)
|
||||
const blogs = await Blogs.findAll({
|
||||
where: {
|
||||
[Op.and]: [(blogIds !== false) && {
|
||||
[Op.not]: {
|
||||
id: blogIds
|
||||
}
|
||||
}, (endDate) && {
|
||||
createdAt: {
|
||||
[Op.lt]: endDate
|
||||
}
|
||||
}]
|
||||
},
|
||||
include: [{
|
||||
model: User,
|
||||
include: {
|
||||
model: Follow,
|
||||
where: {
|
||||
user: userId
|
||||
},
|
||||
},
|
||||
required: true
|
||||
}, Categories, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}],
|
||||
limit: 20
|
||||
});
|
||||
|
||||
const date = startAndEndDates(blogs, endDate);
|
||||
|
||||
const reblogs = await ReBlog.findAll({
|
||||
where:[(date.status === true && blogIds) ? {
|
||||
createdAt: {
|
||||
[Op.between]: [date.endDate, date.startDate]
|
||||
}
|
||||
} : {}],
|
||||
include: [{
|
||||
model: User,
|
||||
include: {
|
||||
model: Follow,
|
||||
where: {
|
||||
user: userId
|
||||
},
|
||||
},
|
||||
required: true
|
||||
}, {
|
||||
model: Blogs,
|
||||
include: [Categories, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}, User]
|
||||
}],
|
||||
limit: 20
|
||||
});
|
||||
|
||||
const result = await editedListPosts(blogs, reblogs);
|
||||
|
||||
return result.slice(0, 20);
|
||||
};
|
||||
|
||||
exports.getBlogsForFollowsWithCategory = async function({userId, category, endDate = false, blogIds = false}){
|
||||
endDate = (endDate !== false) && new Date(endDate);
|
||||
const blogs = await Blogs.findAll({
|
||||
where: {
|
||||
[Op.and]: [(blogIds !== false) && {
|
||||
[Op.not]: {
|
||||
id: blogIds
|
||||
}
|
||||
}, (endDate !== false) && {
|
||||
createdAt: {
|
||||
[Op.lt]: endDate
|
||||
}
|
||||
}]
|
||||
},
|
||||
include: [{
|
||||
model: User,
|
||||
include: {
|
||||
model: Follow,
|
||||
where: {
|
||||
user: userId
|
||||
}
|
||||
},
|
||||
required: true
|
||||
}, {
|
||||
model: Categories,
|
||||
where: {
|
||||
href: category
|
||||
}
|
||||
}, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}],
|
||||
limit: 20
|
||||
});
|
||||
|
||||
const date = startAndEndDates(blogs, endDate);
|
||||
|
||||
const reblogs = await ReBlog.findAll({
|
||||
where:[(date.status === true && blogIds) ? {
|
||||
createdAt: {
|
||||
[Op.between]: [date.endDate, date.startDate]
|
||||
}
|
||||
} : {}],
|
||||
include: [{
|
||||
model: User,
|
||||
include: {
|
||||
model: Follow,
|
||||
where: {
|
||||
user: userId
|
||||
}
|
||||
},
|
||||
required: true
|
||||
}, {
|
||||
model: Blogs,
|
||||
include: [{
|
||||
model: Categories,
|
||||
where: {
|
||||
href: category
|
||||
}
|
||||
}, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}, User],
|
||||
required: true
|
||||
}],
|
||||
limit: 20
|
||||
});
|
||||
|
||||
const result = await editedListPosts(blogs, reblogs);
|
||||
|
||||
return result.slice(0, 20);
|
||||
};
|
||||
|
||||
exports.getBlogsForDiscover = async function({userId, endDate, blogIds = false}){
|
||||
endDate = (endDate) && new Date(endDate);
|
||||
|
||||
const followsIds = await getFollowingsForIds({
|
||||
userId: userId
|
||||
});
|
||||
|
||||
const blogs = await Blogs.findAll({
|
||||
where:[{
|
||||
[Op.not]: {
|
||||
userId: [followsIds, userId]
|
||||
}
|
||||
}, (endDate) ? {
|
||||
createdAt: {
|
||||
[Op.lt]: endDate
|
||||
}
|
||||
} : {}, (blogIds) ? {
|
||||
[Op.not]: {
|
||||
id: [blogIds, userId]
|
||||
}
|
||||
} : {}],
|
||||
include: [Categories, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}, User],
|
||||
limit: 20,
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
|
||||
const date = startAndEndDates(blogs, endDate);
|
||||
|
||||
const reblogs = await ReBlog.findAll({
|
||||
where: [{
|
||||
[Op.not]: {
|
||||
userId: [followsIds, userId]
|
||||
}
|
||||
}, (date.status === true && blogIds) ? {
|
||||
createdAt: {
|
||||
[Op.between]: [date.endDate, date.startDate]
|
||||
}
|
||||
} : {}],
|
||||
include:[{
|
||||
model: Blogs,
|
||||
where: {
|
||||
[Op.not]: {
|
||||
userId: [followsIds, userId]
|
||||
}
|
||||
},
|
||||
include: [Categories, User, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}]
|
||||
}, User],
|
||||
limit: 20,
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
const result = await editedListPosts(blogs, reblogs);
|
||||
|
||||
return result.splice(0, 20);
|
||||
};
|
||||
|
||||
exports.getBlogsForDiscoverWithCategory = async function({userId, category, endDate, blogIds = false}){
|
||||
endDate = (endDate) && new Date(endDate);
|
||||
|
||||
const followsIds = await getFollowingsForIds({
|
||||
userId: userId
|
||||
});
|
||||
|
||||
console.log(endDate, blogIds);
|
||||
|
||||
const blogs = await Blogs.findAll({
|
||||
where:[{
|
||||
[Op.not]: {
|
||||
userId: [followsIds, userId]
|
||||
}
|
||||
}, (endDate) && {
|
||||
createdAt: {
|
||||
[Op.lt]: endDate
|
||||
}
|
||||
}],
|
||||
include: [{
|
||||
model: Categories,
|
||||
where: {
|
||||
href: category
|
||||
},
|
||||
required: true
|
||||
}, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}, User],
|
||||
limit: 20,
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
const date = startAndEndDates(blogs, endDate);
|
||||
|
||||
const reblogs = await ReBlog.findAll({
|
||||
where: [{
|
||||
[Op.not]: {
|
||||
userId: [followsIds, userId]
|
||||
}
|
||||
}, (date.status === true && blogIds) ? {
|
||||
createdAt: {
|
||||
[Op.between]: [date.endDate, date.startDate]
|
||||
}
|
||||
} : {}],
|
||||
include:[{
|
||||
model: Blogs,
|
||||
where:[{
|
||||
[Op.not]: {
|
||||
userId: [followsIds, userId]
|
||||
}
|
||||
}],
|
||||
include: [{
|
||||
model: Categories,
|
||||
where: {
|
||||
href: category
|
||||
},
|
||||
required: true
|
||||
}, {
|
||||
model: SavedBlogs,
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
required: false
|
||||
}, {
|
||||
model: Comments,
|
||||
include: User
|
||||
}, User]
|
||||
}, User],
|
||||
limit: 20,
|
||||
order: [["createdAt", "DESC"]]
|
||||
});
|
||||
|
||||
const result = await editedListPosts(blogs, reblogs);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
// CATE
|
||||
exports.getCategoryWithParams = async function({categoryId, categoryTitle}){
|
||||
|
||||
@ -6,5 +6,10 @@ module.exports = Database.define("categories", {
|
||||
type: DataTypes.CHAR(25),
|
||||
unique: true,
|
||||
allowNull: false
|
||||
},
|
||||
href: {
|
||||
type: DataTypes.CHAR(25),
|
||||
unique: true,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
5
modules/blogs/models/ReBlogs.js
Normal file
5
modules/blogs/models/ReBlogs.js
Normal file
@ -0,0 +1,5 @@
|
||||
const Database = require("../../../database/db")
|
||||
|
||||
const ReBlog = Database.define("reblogs", {});
|
||||
|
||||
module.exports = {ReBlog};
|
||||
@ -1,33 +1,85 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { getBlogs, getBlogsWithUsername, getBlogsWithCategory } = require("../middlewares/query");
|
||||
const { getBlogs, getBlogsWithUsername, getBlogsWithCategory, getBlogsWithFollows, getBlogsForDiscover, getBlogsForDiscoverWithCategory, getBlogsForFollowsWithCategory, getBlog, getBlogsWithUserId } = require("../middlewares/query");
|
||||
const Categories = require("../models/Categories");
|
||||
const { getUserWithUsername } = require("../../users/middlewares/query");
|
||||
const router = express();
|
||||
|
||||
router.get("/get/blogs/all", auth, async function (req, res) {
|
||||
res.json(await getBlogs({myUserId: req.session.user.id}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/follows", auth, async function(req, res){
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
res.json(await getBlogsWithFollows({
|
||||
userId: req.session.user.id,
|
||||
blogIds: blogIds,
|
||||
endDate: req.query.endDate
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/discover", auth, async function(req, res){
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
res.json(await getBlogsForDiscover({
|
||||
userId: req.session.user.id,
|
||||
blogIds: blogIds,
|
||||
endDate: req.query.endDate
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/discover/:category", auth, async function(req, res){
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
res.json(await getBlogsForDiscoverWithCategory({
|
||||
userId: req.session.user.id,
|
||||
category: req.params.category,
|
||||
blogIds: blogIds,
|
||||
endDate: req.query.endDate
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/:cate", auth, async function(req, res) {
|
||||
res.json(await getBlogsWithCategory({categoryId: req.params.cate, myUserId: req.session.user.id}));
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
|
||||
res.json(await getBlogsForFollowsWithCategory({
|
||||
category: req.params.cate,
|
||||
userId: req.session.user.id,
|
||||
blogIds: blogIds,
|
||||
endDate: req.query.endDate
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/user/:username", auth, async function (req, res) {
|
||||
res.json(await getBlogsWithUsername({
|
||||
username: req.params.username,
|
||||
myUserId: req.session.user.id
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
|
||||
res.json(await getBlogsWithUserId({
|
||||
userId: await getUserWithUsername({username: req.params.username}).then(get => get.id),
|
||||
myUserId: req.session.user.id,
|
||||
endDate: (req.query.endDate) ?? false,
|
||||
blogIds: blogIds
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/user/:username/:category", auth, async function (req, res) {
|
||||
res.json(await getBlogsWithUsername({
|
||||
username: req.params.username,
|
||||
const blogIds = (req.query.blogIds) && req.query.blogIds.split(",");
|
||||
|
||||
res.json(await getBlogsWithUserId({
|
||||
userId: await getUserWithUsername({username: req.params.username}).then(get => get.id),
|
||||
category: req.params.category,
|
||||
myUserId: req.session.user.id
|
||||
myUserId: req.session.user.id,
|
||||
endDate: (req.query.endDate) ?? false,
|
||||
blogIds: blogIds
|
||||
}));
|
||||
});
|
||||
|
||||
router.get("/get/blogs/cate/all", async function(req, res) {
|
||||
res.json(await Categories.findAll());
|
||||
});
|
||||
|
||||
router.get("/get/blog/:blogId", auth, async function(req, res){
|
||||
res.json(await getBlog({
|
||||
blogId: req.params.blogId,
|
||||
myUserId: req.session.user.id
|
||||
}));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@ -1,6 +1,6 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { createBlog, createSaved } = require("../middlewares/post");
|
||||
const { createBlog, createSaved, createReBlog } = require("../middlewares/post");
|
||||
const { getSaved } = require("../middlewares/query");
|
||||
const router = express();
|
||||
|
||||
@ -10,10 +10,10 @@ router.post("/post/blogs/create", auth, async function(req, res) {
|
||||
if(result){
|
||||
return res.json({Status: "Success", Message: "Başarıyla paylaşıldı.", Ico: "/icons/success.svg"});
|
||||
}else{
|
||||
return res.json({Status: "Failed", Message: "Bir hatadan dolayı paylaşılamadı", Ico: "/icons/failed.svg"});
|
||||
return res.json({Status: "Failed", Message: "Bir hatadan dolayı paylaşılamadı - 1", Ico: "/icons/failed.svg"});
|
||||
}
|
||||
} catch (error) {
|
||||
return res.json({Status: "Failed", Message: "Bir hatadan dolayı paylaşılamadı", Ico: "/icons/failed.svg"});
|
||||
return res.json({Status: "Failed", Message: "Bir hatadan dolayı paylaşılamadı - 2", Ico: "/icons/failed.svg"});
|
||||
};
|
||||
});
|
||||
|
||||
@ -22,4 +22,9 @@ router.post("/post/blogs/save", auth, async function(req, res) {
|
||||
return res.json(result);
|
||||
});
|
||||
|
||||
router.post("/post/blogs/reblog", auth, async function(req, res){
|
||||
const result = await createReBlog(req.body.blogId, req.session.user.id);
|
||||
return res.json(result);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
10
modules/comments/app.js
Normal file
10
modules/comments/app.js
Normal file
@ -0,0 +1,10 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
// ROUTES
|
||||
const routePost = require("./routes/post");
|
||||
|
||||
// APPS
|
||||
app.use(routePost);
|
||||
|
||||
module.exports = app;
|
||||
24
modules/comments/middlewares/post.js
Normal file
24
modules/comments/middlewares/post.js
Normal file
@ -0,0 +1,24 @@
|
||||
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;
|
||||
};
|
||||
});
|
||||
};
|
||||
12
modules/comments/models/Comments.js
Normal file
12
modules/comments/models/Comments.js
Normal file
@ -0,0 +1,12 @@
|
||||
const { DataTypes } = require("sequelize");
|
||||
const Database = require("../../../database/db");
|
||||
|
||||
const Comments = Database.define("comments", {
|
||||
text: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {Comments};
|
||||
19
modules/comments/routes/post.js
Normal file
19
modules/comments/routes/post.js
Normal file
@ -0,0 +1,19 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { createComments } = require("../middlewares/post");
|
||||
const router = express();
|
||||
|
||||
router.post("/post/comments/create", auth, async function(req, res){
|
||||
const result = await createComments({
|
||||
text: req.body.text,
|
||||
blogId: req.body.blogId,
|
||||
userId: req.session.user.id
|
||||
});
|
||||
if(result){
|
||||
res.json({Status: "Success"});
|
||||
}else{
|
||||
res.json({Status: "Failed"});
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@ -1,3 +1,5 @@
|
||||
const Blogs = require("../../blogs/models/Blogs");
|
||||
const { CustomSettings } = require("../../settings/models/Settings");
|
||||
const { User } = require("../../users/models/user");
|
||||
const { Follow } = require("../models");
|
||||
const { followButton } = require("./process");
|
||||
@ -42,6 +44,7 @@ exports.getFollowers = async function({userId, statu = true, myUserId = null}){
|
||||
},
|
||||
include: {
|
||||
model: User,
|
||||
include: [Blogs, CustomSettings],
|
||||
as: "follower"
|
||||
}
|
||||
});
|
||||
@ -54,7 +57,7 @@ exports.getFollowers = async function({userId, statu = true, myUserId = null}){
|
||||
await followButton({
|
||||
data: element,
|
||||
myUserId: myUserId
|
||||
})
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@ -73,6 +76,7 @@ exports.getFollowings = async function({userId, statu = true, myUserId = null}){
|
||||
},
|
||||
include: {
|
||||
model: User,
|
||||
include: [Blogs, CustomSettings],
|
||||
as: "following"
|
||||
}
|
||||
});
|
||||
@ -94,4 +98,13 @@ exports.getFollowings = async function({userId, statu = true, myUserId = null}){
|
||||
isNull: !isLen,
|
||||
data: result
|
||||
};
|
||||
};
|
||||
|
||||
exports.getFollowingsForIds = async function({userId}) {
|
||||
const result = await Follow.findAll({
|
||||
where: {
|
||||
user: userId
|
||||
}
|
||||
});
|
||||
return result.map(res => res.target_user);
|
||||
};
|
||||
@ -25,22 +25,28 @@ router.get("/get/follow/followers/:username", auth, async function(req, res){
|
||||
});
|
||||
|
||||
router.get("/get/follow/followings/:username", auth, async function(req, res){
|
||||
const data = new Object();
|
||||
|
||||
const userId = (req.params.username === req.session.user.username) ?
|
||||
req.session.user.id
|
||||
:
|
||||
await getUserWithUsername({username: req.params.username})
|
||||
.then(get => {return get.id});
|
||||
|
||||
const followings = await getFollowings({userId: userId, myUserId: req.session.user.id});
|
||||
const followingsReq = await getFollowings({userId: userId, myUserId: req.session.user.id, statu: false});
|
||||
data.current = await getFollowings({userId: userId, myUserId: req.session.user.id});
|
||||
if(req.params.username === req.session.user.username){
|
||||
data.requests = await getFollowings({userId: userId, myUserId: req.session.user.id, statu: false});
|
||||
}
|
||||
|
||||
console.log(data.current.data);
|
||||
|
||||
res.json({
|
||||
Status: "Success",
|
||||
data: {
|
||||
current: followings.data,
|
||||
requests: followingsReq.data
|
||||
current: data.current?.data,
|
||||
requests: data.requests?.data
|
||||
},
|
||||
isNull: followings.isNull && followingsReq.isNull
|
||||
isNull: data.current?.isNull && data.requests?.isNull
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
10
modules/notifications/app.js
Normal file
10
modules/notifications/app.js
Normal file
@ -0,0 +1,10 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
// ROUTER
|
||||
const routerGet = require("./routes/get");
|
||||
|
||||
// USES
|
||||
app.use(routerGet);
|
||||
|
||||
module.exports = app;
|
||||
22
modules/notifications/middlewares/proccess.js
Normal file
22
modules/notifications/middlewares/proccess.js
Normal file
@ -0,0 +1,22 @@
|
||||
const { Notifications } = require("../models/Notifications");
|
||||
|
||||
exports.createNotification = async function({data, userId, notificationCodeId}) {
|
||||
// console.log(userId, notificationDraftId, data);
|
||||
return await Notifications.create({
|
||||
data: data,
|
||||
userId: userId,
|
||||
notificationCodeId: notificationCodeId
|
||||
});
|
||||
};
|
||||
|
||||
exports.readedNotification = async function({notificationId}){
|
||||
return await Notifications.update(
|
||||
{read: true},
|
||||
{
|
||||
where:{
|
||||
id: notificationId,
|
||||
read: false
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
34
modules/notifications/middlewares/query.js
Normal file
34
modules/notifications/middlewares/query.js
Normal file
@ -0,0 +1,34 @@
|
||||
const { Notifications, NotificationCodes } = require("../models/Notifications");
|
||||
const { repairNotifications } = require("./queryProccess");
|
||||
|
||||
exports.getNotifications = async function({userId}){
|
||||
return await Notifications.findAll({
|
||||
where: {
|
||||
userId: userId
|
||||
},
|
||||
include: {
|
||||
model: NotificationCodes,
|
||||
attributes: ["code"]
|
||||
},
|
||||
order: [["createdAt", "DESC"]],
|
||||
limit: 7
|
||||
});
|
||||
};
|
||||
|
||||
exports.getNotificationUnread = async function({userId}){
|
||||
return await Notifications.findAll({
|
||||
where: {
|
||||
userId: userId,
|
||||
read: false
|
||||
},
|
||||
include: NotificationCodes
|
||||
});
|
||||
};
|
||||
|
||||
exports.getNotificationCode = async function({draftCode}){
|
||||
return await NotificationCodes.findOne({
|
||||
where: {
|
||||
code: draftCode
|
||||
}
|
||||
});
|
||||
};
|
||||
46
modules/notifications/middlewares/queryProccess.js
Normal file
46
modules/notifications/middlewares/queryProccess.js
Normal file
@ -0,0 +1,46 @@
|
||||
const { buildDatetime } = require("../../../middlewares/general/datatime");
|
||||
const { getBlog } = require("../../blogs/middlewares/query");
|
||||
const { getUserWithId } = require("../../users/middlewares/query");
|
||||
|
||||
exports.repairNotifications = async function(data){
|
||||
const result = new Array();
|
||||
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
const notification = data[index];
|
||||
const datas = JSON.parse(notification.data);
|
||||
const rslt = new Object({
|
||||
id: data[index].id,
|
||||
read: data[index].read,
|
||||
code: notification.notificationCode.code,
|
||||
datetime: new Object()
|
||||
});
|
||||
|
||||
rslt.blog = await getBlog({blogId: datas.blog}).then(res => {
|
||||
if(res){
|
||||
return {
|
||||
href: `/blog/${res.id}`
|
||||
};
|
||||
}else {
|
||||
return {
|
||||
href: `/blog/deleted`
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
console.log(56);
|
||||
|
||||
rslt.user = await getUserWithId({userId: datas.user}).then(res => {
|
||||
return {
|
||||
name: `${res.first_name} ${res.second_name}`,
|
||||
username: res.username,
|
||||
href: `/profile/${res.username}`
|
||||
};
|
||||
});
|
||||
|
||||
rslt.datetime.createdAt = buildDatetime({date: notification.createdAt});
|
||||
|
||||
result.push(rslt);
|
||||
};
|
||||
|
||||
return result;
|
||||
};
|
||||
26
modules/notifications/models/Notifications.js
Normal file
26
modules/notifications/models/Notifications.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { DataTypes } = require("sequelize");
|
||||
const Database = require("../../../database/db");
|
||||
|
||||
const Notifications = Database.define("notifications", {
|
||||
data: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
unique: false
|
||||
},
|
||||
read: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
unique: false,
|
||||
defaultValue: false
|
||||
}
|
||||
});
|
||||
|
||||
const NotificationCodes = Database.define("notificationCodes", {
|
||||
code: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: false,
|
||||
unique: true
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {Notifications, NotificationCodes};
|
||||
31
modules/notifications/routes/get.js
Normal file
31
modules/notifications/routes/get.js
Normal file
@ -0,0 +1,31 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { getNotifications, getNotificationUnread } = require("../middlewares/query");
|
||||
const { repairNotifications } = require("../middlewares/queryProccess");
|
||||
const { readedNotification } = require("../middlewares/proccess");
|
||||
const router = express();
|
||||
|
||||
router.get("/get/notification/all", auth, async function(req, res){
|
||||
const notifications = await getNotifications({userId: req.session.user.id});
|
||||
res.json(await repairNotifications(notifications));
|
||||
});
|
||||
|
||||
router.get("/get/notification/unread", auth, async function(req, res){
|
||||
const unread = await getNotificationUnread({userId: req.session.user.id});
|
||||
res.json({
|
||||
notifications: unread,
|
||||
count: unread.length
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/post/notification/readed/:notificationId", auth, async function(req, res){
|
||||
const result = await readedNotification({notificationId: req.params.notificationId});
|
||||
res.json({
|
||||
Status: "Success",
|
||||
data: {
|
||||
status: (result[0]) ? true : false
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
28
modules/settings/middlewares/post.js
Normal file
28
modules/settings/middlewares/post.js
Normal file
@ -0,0 +1,28 @@
|
||||
const { CustomSettings } = require("../models/Settings")
|
||||
|
||||
exports.updateCustomSetting = async function({id, key, value}){
|
||||
return await CustomSettings.update(
|
||||
{key: key, value: value},
|
||||
{
|
||||
where:{
|
||||
id: id
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
exports.createCustomSetting = async function({key, value, userId}){
|
||||
return await CustomSettings.create({
|
||||
key: key,
|
||||
value: value,
|
||||
userId: userId
|
||||
});
|
||||
};
|
||||
|
||||
exports.destroyCustomSetting = async function({id}){
|
||||
return await CustomSettings.destroy({
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
});
|
||||
};
|
||||
9
modules/settings/middlewares/query.js
Normal file
9
modules/settings/middlewares/query.js
Normal file
@ -0,0 +1,9 @@
|
||||
const { CustomSettings } = require("../models/Settings");
|
||||
|
||||
exports.getCustomSettings = async function({userId}) {
|
||||
return await CustomSettings.findAll({
|
||||
where: {
|
||||
userId: userId
|
||||
}
|
||||
});
|
||||
};
|
||||
17
modules/settings/models/Settings.js
Normal file
17
modules/settings/models/Settings.js
Normal file
@ -0,0 +1,17 @@
|
||||
const { DataTypes } = require("sequelize");
|
||||
const Database = require("../../../database/db");
|
||||
|
||||
const CustomSettings = Database.define("customSettings", {
|
||||
key: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: false,
|
||||
unique: false
|
||||
},
|
||||
value: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: false,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {CustomSettings};
|
||||
4
modules/settings/routes/home.js
Normal file
4
modules/settings/routes/home.js
Normal file
@ -0,0 +1,4 @@
|
||||
const express = require("express");
|
||||
const router = express();
|
||||
|
||||
router.get("", auth)
|
||||
@ -1,4 +1,5 @@
|
||||
const { User } = require("../models/user");
|
||||
const { returnData } = require("./checkProccess");
|
||||
const { getDatabaseColumns } = require("./proccess");
|
||||
|
||||
exports.postSettings = async function({data, userId}){
|
||||
@ -7,74 +8,32 @@ exports.postSettings = async function({data, userId}){
|
||||
console.log(data, 54)
|
||||
|
||||
const dataset = {
|
||||
name: {
|
||||
title: "first_name",
|
||||
isNull: false
|
||||
},
|
||||
surname: {
|
||||
title: "second_name",
|
||||
isNull: false
|
||||
},
|
||||
username: {
|
||||
title: "username",
|
||||
isNull: false
|
||||
},
|
||||
about: {
|
||||
title: "about",
|
||||
isNull: true
|
||||
},
|
||||
private: {title: "private", isNull: false},
|
||||
relation: {title: "relation", isNull: true},
|
||||
education: {title: "educationId", isNull: true},
|
||||
gender: {title: "genderId", isNull: true},
|
||||
language: {title: "locale", isNull: true}
|
||||
name: {title: "first_name", isNull: false, type: "select"},
|
||||
surname: {title: "second_name", isNull: false, type: "select"},
|
||||
username: {title: "username", isNull: false, type: "select"},
|
||||
about: {title: "about", isNull: true, type: "input"},
|
||||
private: {title: "private", isNull: false, type: "select"},
|
||||
relation: {title: "relation", isNull: true, type: "select"},
|
||||
education: {title: "educationId", isNull: true, type: "select"},
|
||||
gender: {title: "genderId", isNull: true, type: "select"},
|
||||
language: {title: "locale", isNull: true, type: "select"},
|
||||
hometown: {title: "hometown", isNull: true, type: "input"},
|
||||
profession: {title: "profession", isNull: true, type: "input"},
|
||||
birthday: {title: "birthday", isNull: true, type: "input"},
|
||||
customSettings: {type: "array"}
|
||||
};
|
||||
|
||||
const returnData = new Object();
|
||||
const dataForReturn = new Object();
|
||||
|
||||
Object.keys(dataset).forEach(get => {
|
||||
if(Object.keys(data).includes(get)){
|
||||
returnData[get] = false;
|
||||
dataForReturn[get] = false;
|
||||
}else{
|
||||
returnData[get] = true;
|
||||
dataForReturn[get] = true;
|
||||
};
|
||||
});
|
||||
|
||||
await returnData({data: data, dataset: dataset, user: user, dataForReturn: dataForReturn});
|
||||
|
||||
for (let key in data){
|
||||
const value = (data[key]).trim();
|
||||
|
||||
const databaseKey = dataset[key].title;
|
||||
const databaseVal = user[databaseKey];
|
||||
|
||||
console.log(key)
|
||||
if(databaseVal != value){
|
||||
if(
|
||||
(dataset[key].isNull === true && [null, undefined, ""].includes(value)) ||
|
||||
(![null, undefined, ""].includes(value))
|
||||
){
|
||||
try {
|
||||
console.log(key)
|
||||
await User.update(
|
||||
{[databaseKey]: value},
|
||||
{
|
||||
where:{
|
||||
id: userId
|
||||
}
|
||||
}
|
||||
).then(res => {
|
||||
if(res){
|
||||
returnData[key] = true;
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(54)
|
||||
returnData[key] = false;
|
||||
};
|
||||
}
|
||||
console.log(databaseVal, value, databaseKey)
|
||||
}else{
|
||||
returnData[key] = true;
|
||||
};
|
||||
};
|
||||
return returnData;
|
||||
return dataForReturn;
|
||||
};
|
||||
85
modules/users/middlewares/checkProccess.js
Normal file
85
modules/users/middlewares/checkProccess.js
Normal file
@ -0,0 +1,85 @@
|
||||
const { isEmptyForString } = require("../../../middlewares/general/checks");
|
||||
const { createCustomSetting, updateCustomSetting, destroyCustomSetting } = require("../../settings/middlewares/post");
|
||||
const { getCustomSettings } = require("../../settings/middlewares/query");
|
||||
const { User } = require("../models/user");
|
||||
|
||||
exports.returnData = async function({data, dataset, user, dataForReturn}){
|
||||
const returnData = dataForReturn;
|
||||
|
||||
for (let key in data){
|
||||
const databaseKey = dataset[key].title;
|
||||
const datasetType = dataset[key].type || "input";
|
||||
const databaseVal = user[databaseKey];
|
||||
|
||||
|
||||
if(["input", "select"].includes(datasetType)){
|
||||
const value = (data[key]).trim();
|
||||
if(databaseVal != value){
|
||||
if(
|
||||
(dataset[key].isNull === true && [null, undefined, ""].includes(value)) ||
|
||||
(![null, undefined, ""].includes(value))
|
||||
){
|
||||
try {
|
||||
await User.update(
|
||||
{[databaseKey]: value},
|
||||
{
|
||||
where:{
|
||||
id: user.id
|
||||
}
|
||||
}
|
||||
).then(res => {
|
||||
if(res){
|
||||
returnData[key] = true;
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
returnData[key] = false;
|
||||
};
|
||||
}
|
||||
}else{
|
||||
returnData[key] = true;
|
||||
};
|
||||
}else if(["array"].includes(datasetType)){
|
||||
const datas = data[key];
|
||||
const query = await getCustomSettings({userId: user.id});
|
||||
console.log(datas.length, query.length, 9854894);
|
||||
if(query.length < 5){
|
||||
datas.map(async (get) => {
|
||||
const key = !isEmptyForString(get.key);
|
||||
const value = !isEmptyForString(get.value);
|
||||
if(!(key && value)){
|
||||
if(query.length === 0){
|
||||
await createCustomSetting({
|
||||
key: get.key,
|
||||
value: get.value,
|
||||
userId: user.id
|
||||
});
|
||||
}else{
|
||||
const isAvailable = await query.filter(q => (
|
||||
get.key === q.key &&
|
||||
get.value === q.value
|
||||
));
|
||||
|
||||
const isID = await query.filter(q => get.id === q.id);
|
||||
|
||||
if(isAvailable.length === 0 && isID.length === 0){
|
||||
await createCustomSetting({
|
||||
key: get.key,
|
||||
value: get.value,
|
||||
userId: user.id
|
||||
});
|
||||
}else if(isAvailable.length === 0 && isID.length > 0){
|
||||
await updateCustomSetting({
|
||||
id: get.id,
|
||||
key: get.key,
|
||||
value: get.value
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
return returnData;
|
||||
};
|
||||
@ -2,6 +2,8 @@ const { Follow } = require("../../follows/models");
|
||||
const { Gender, Education } = require("../models/user");
|
||||
const { followButton } = require("../../follows/middlewares/process");
|
||||
const { getFollowers, getFollowings } = require("../../follows/middlewares/query");
|
||||
const { Op } = require("sequelize");
|
||||
const { CustomSettings } = require("../../settings/models/Settings");
|
||||
|
||||
const User = require("../models/user").User;
|
||||
|
||||
@ -14,7 +16,7 @@ exports.getUserWithId = async function({userId}) {
|
||||
where:{
|
||||
id: userId
|
||||
},
|
||||
include: [Gender, Education]
|
||||
include: [Gender, Education, CustomSettings]
|
||||
});
|
||||
}
|
||||
|
||||
@ -52,4 +54,17 @@ exports.getUserWithUsername = async function({username, myUserId=null}){
|
||||
};
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.getUsersDiscover = async function({userId}) {
|
||||
return User.findAll({
|
||||
include: {
|
||||
model: Follow,
|
||||
where: {
|
||||
[Op.not]: {
|
||||
user: userId
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -39,6 +39,21 @@ const User = Database.define("users", {
|
||||
allowNull: false,
|
||||
unique: false,
|
||||
defaultValue: 'tr'
|
||||
},
|
||||
hometown: {
|
||||
type: DataTypes.CHAR(50),
|
||||
allowNull: true,
|
||||
unique: false
|
||||
},
|
||||
profession: {
|
||||
type: DataTypes.CHAR(50),
|
||||
allowNull: true,
|
||||
unique: false
|
||||
},
|
||||
birthday: {
|
||||
type: DataTypes.CHAR(50),
|
||||
allowNull: true,
|
||||
unique: false
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
const express = require("express");
|
||||
const auth = require("../../logins/middlewares/auth");
|
||||
const { getUsers, getUserWithUsername, getUserWithId } = require("../middlewares/query");
|
||||
const { getUsers, getUserWithUsername, getUserWithId, getUsersDiscover } = require("../middlewares/query");
|
||||
const { followButton } = require("../../follows/middlewares/process");
|
||||
const { getNotifications } = require("../../notifications/middlewares/query");
|
||||
const router = express();
|
||||
|
||||
router.get("/get/peoples", auth, async (req, res) => {
|
||||
@ -18,9 +19,15 @@ router.get("/get/user/my", auth, async (req, res) => {
|
||||
});
|
||||
|
||||
router.get("/get/user/my/get/locale", auth, async function(req, res){
|
||||
res.json({
|
||||
locale: (await getUserWithId({userId: req.session.user.id})).locale
|
||||
});
|
||||
if(req.session.user){
|
||||
res.json({
|
||||
locale: (await getUserWithId({userId: req.session.user.id})).locale
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/get/users/discover", auth, async function(req, res) {
|
||||
res.json(await getUsersDiscover({userId: req.session.user.id}));
|
||||
});
|
||||
|
||||
router.get("/get/user/:username", async (req, res) => {
|
||||
|
||||
@ -6,15 +6,18 @@ const fs = require('fs');
|
||||
router.get("/locales/:locale", async function(req, res){
|
||||
try {
|
||||
const locale = req.params.locale;
|
||||
const filePath = path.join(__dirname, `../../../locales/${locale}.json`);
|
||||
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if(err){
|
||||
res.status(404).send({ message: 'Dosya bulunamadı' });
|
||||
} else {
|
||||
res.json(JSON.parse(data));
|
||||
const defaultLocaleFile = JSON.parse((fs.readFileSync((path.join(__dirname, `../../../locales/en.json`)))));
|
||||
const currentLocaleFile = JSON.parse((fs.readFileSync((path.join(__dirname, `../../../locales/${locale}.json`)))));
|
||||
|
||||
Object.keys(defaultLocaleFile).filter(x => {
|
||||
if(!(x in currentLocaleFile)){
|
||||
currentLocaleFile[x] = defaultLocaleFile[x]
|
||||
};
|
||||
});
|
||||
|
||||
res.json(currentLocaleFile);
|
||||
|
||||
} catch (error) {
|
||||
res.json({
|
||||
Statu: "Failed"
|
||||
|
||||
@ -4,6 +4,7 @@ const { Education, Gender } = require("../models/user");
|
||||
const { getUserWithId } = require("../middlewares/query");
|
||||
const { postSettings } = require("../middlewares/check");
|
||||
const { locales } = require("../../../modulesData/locales");
|
||||
const { destroyCustomSetting } = require("../../settings/middlewares/post");
|
||||
const router = express();
|
||||
|
||||
router.get("/profile/settings/profile", auth, async function(req, res) {
|
||||
@ -18,6 +19,13 @@ router.get("/profile/settings/profile", auth, async function(req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/profile/settings/customsetting/destroy/:id", auth, async function(req, res) {
|
||||
res.json({
|
||||
data: await destroyCustomSetting({ id: req.params.id }),
|
||||
Status: "Success"
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/profile/settings", auth, async function(req, res) {
|
||||
res.json({
|
||||
data: postSettings({data: req.body, userId: req.session.user.id}),
|
||||
@ -25,4 +33,5 @@ router.post("/profile/settings", auth, async function(req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
Loading…
Reference in New Issue
Block a user