262 lines
5.8 KiB
JavaScript
262 lines
5.8 KiB
JavaScript
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, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: true
|
||
}
|
||
});
|
||
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,
|
||
unique: false
|
||
}
|
||
});
|
||
Blogs.belongsTo(User.User);
|
||
|
||
Categories.hasMany(Blogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
Blogs.belongsTo(Categories);
|
||
|
||
Blogs.hasMany(SavedBlogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
SavedBlogs.belongsTo(Blogs);
|
||
|
||
User.User.hasMany(SavedBlogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
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,
|
||
unique: false
|
||
}
|
||
});
|
||
User.User.belongsTo(User.Education);
|
||
|
||
User.Gender.hasMany(User.User, {
|
||
foreignKey:{
|
||
allowNull: true,
|
||
unique: false
|
||
}
|
||
});
|
||
User.User.belongsTo(User.Gender);
|
||
|
||
User.User.hasMany(Follow, {
|
||
foreignKey: 'user', onDelete: 'CASCADE'
|
||
});
|
||
User.User.hasMany(Follow, {
|
||
foreignKey: 'target_user', onDelete: 'CASCADE'
|
||
});
|
||
|
||
User.User.hasMany(Follow, { foreignKey: 'user', as: 'follower' });
|
||
Follow.belongsTo(User.User, { foreignKey: 'user', as: 'follower' });
|
||
|
||
User.User.hasMany(Follow, { foreignKey: 'target_user', as: 'following' });
|
||
Follow.belongsTo(User.User, { foreignKey: 'target_user', as: 'following' });
|
||
|
||
|
||
exports.createTesting = async function(){
|
||
const resultLogins = await Login.findAll();
|
||
if(resultLogins.length == 0){
|
||
|
||
await User.Education.bulkCreate([{
|
||
id: 1,
|
||
title: "İlkokul"
|
||
},{
|
||
id: 2,
|
||
title: "Ortaokul"
|
||
},{
|
||
id: 3,
|
||
title: "Lise"
|
||
},{
|
||
id: 4,
|
||
title: "Önlisans"
|
||
},{
|
||
id: 5,
|
||
title: "Lisans"
|
||
}]);
|
||
|
||
await User.Gender.bulkCreate([{
|
||
id: 1,
|
||
title: "Erkek"
|
||
},{
|
||
id: 2,
|
||
title: "Kadın"
|
||
}])
|
||
|
||
await User.User.bulkCreate([{
|
||
id: 1,
|
||
first_name: "Batuhan",
|
||
second_name: "Coşkun",
|
||
username: "batuhancoskun"
|
||
},{
|
||
id: 2,
|
||
first_name: "Bedirhan",
|
||
second_name: "Coşkun",
|
||
username: "bedirhan"
|
||
},{
|
||
id: 3,
|
||
first_name: "Berkant",
|
||
second_name: "Erenuluğ",
|
||
username: "berkant"
|
||
},{
|
||
id: 4,
|
||
first_name: "Buğra Osman",
|
||
second_name: "Coşkun",
|
||
username: "osman"
|
||
}]);
|
||
|
||
await Login.bulkCreate([{
|
||
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",
|
||
href: "profile"
|
||
},{
|
||
id: 2,
|
||
title: "Teknoloji",
|
||
href: "technology"
|
||
},{
|
||
id: 3,
|
||
title: "Siyaset",
|
||
href: "politics"
|
||
},{
|
||
id: 4,
|
||
title: "Sağlık",
|
||
href: "health"
|
||
},{
|
||
id: 5,
|
||
title: "Felsefe",
|
||
href: "philosophy"
|
||
},{
|
||
id: 6,
|
||
title: "Doğa",
|
||
href: "nature"
|
||
},{
|
||
id: 7,
|
||
title: "Gıda",
|
||
href: "food"
|
||
}]);
|
||
|
||
await Blogs.bulkCreate([{
|
||
id: 1,
|
||
title: "",
|
||
text: "Gönderi - 1.",
|
||
userId: 1,
|
||
categoryId: 1
|
||
},{
|
||
id: 2,
|
||
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"
|
||
}]);
|
||
};
|
||
}; |