Node/database/dump.js
2025-02-20 18:21:37 +03:00

50 lines
1.1 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 Login = require("../modules/logins/models/login");
const User = require("../modules/logins/models/user");
User.hasMany(Login, {
foreignKey:{
allowNull: false,
unique: true
}
});
Login.belongsTo(User);
User.hasMany(Blogs, {
foreignKey:{
allowNull: false,
unique: false
}
});
Blogs.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"
}]);
await Login.bulkCreate([{
email: "batuhancoskun@yaani.com",
password: "Yaren2010",
userId: 1
}]);
await Blogs.bulkCreate([{
id: 1,
title: "Bu Bir Başlıktır",
text: "Merhaba, bu benim yazımdır.",
userId: 1
},{
id: 2,
text: "Merhaba, bu benim yazımdır.",
userId: 1
}])
};
};