107 lines
2.4 KiB
JavaScript
107 lines
2.4 KiB
JavaScript
const Blogs = require("../modules/blogs/models/Blogs");
|
||
const Categories = require("../modules/blogs/models/Categories");
|
||
const SavedBlogs = require("../modules/blogs/models/SavedBlogs");
|
||
const Login = require("../modules/logins/models/login");
|
||
const User = require("../modules/users/models/user");
|
||
|
||
User.hasMany(Login, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: true
|
||
}
|
||
});
|
||
Login.belongsTo(User);
|
||
|
||
User.hasMany(Blogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
Blogs.belongsTo(User);
|
||
|
||
Categories.hasMany(Blogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
Blogs.belongsTo(Categories);
|
||
|
||
Blogs.hasMany(SavedBlogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
SavedBlogs.belongsTo(Blogs);
|
||
|
||
User.hasMany(SavedBlogs, {
|
||
foreignKey:{
|
||
allowNull: false,
|
||
unique: false
|
||
}
|
||
});
|
||
SavedBlogs.belongsTo(User);
|
||
|
||
exports.createTesting = async function(){
|
||
const resultLogins = await Login.findAll();
|
||
if(resultLogins.length == 0){
|
||
|
||
await 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
|
||
}]);
|
||
|
||
await Categories.bulkCreate([{
|
||
id: 1,
|
||
title: "Teknoloji"
|
||
},{
|
||
id: 2,
|
||
title: "Siyaset"
|
||
},{
|
||
id: 3,
|
||
title: "Sağlık"
|
||
},{
|
||
id: 4,
|
||
title: "Felsefe"
|
||
}]);
|
||
|
||
await Blogs.bulkCreate([{
|
||
id: 1,
|
||
title: "Bu Bir Başlıktır",
|
||
text: "Merhaba, bu benim yazımdır.",
|
||
userId: 1,
|
||
categoryId: 1
|
||
},{
|
||
id: 2,
|
||
text: "Merhaba, bu benim yazımdır.",
|
||
userId: 2,
|
||
categoryId: 4
|
||
}]);
|
||
|
||
};
|
||
}; |