Node/database/dump.js

157 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.User.hasMany(Login, {
foreignKey:{
allowNull: false,
unique: true
}
});
Login.belongsTo(User.User);
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.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);
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
}]);
await Categories.bulkCreate([{
id: 1,
title: "Profil"
},{
id: 2,
title: "Teknoloji"
},{
id: 3,
title: "Siyaset"
},{
id: 4,
title: "Sağlık"
},{
id: 5,
title: "Felsefe"
},{
id: 6,
title: "Doğa"
},{
id: 7,
title: "Gıda"
}]);
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
}]);
};
};