Skip to content

Commit

Permalink
new save
Browse files Browse the repository at this point in the history
  • Loading branch information
adityabisht02 committed Oct 20, 2022
2 parents 52b206d + e80f65e commit 3e73437
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 19 deletions.
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## PR Title
<!--- Describe the problems, issues, or needs driving this feature/fix and include links to related issues -->
The purpose of this Pull Request is to fix #<issue-number>


### Postman Screenshots
<!--- Include an short video or screenshot if the change affects the UI. -->


## Checklist
- [ ] I have tested in local Environment.
- [ ] I have made the fix as per issue converstaion
82 changes: 63 additions & 19 deletions initialisedb.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,81 @@
//mysql connector pool
const pool=require("./mysqlconnector");
const pool = require("./mysqlconnector");

<<<<<<< HEAD
function initialiseDB(){
pool.query("CREATE TABLE admin (id int,username varchar(50),password varchar(50),email varchar(50));", (ex, rows) => {
=======
function initialiseDB() {
pool.query(
"CREATE TABLE admin (id int,name varchar(50),email varchar(50));",
(ex, rows) => {
>>>>>>> e80f65e7013512bd9bc61dd922b0d68c99caec74
if (ex) {
console.log(ex);
} else {
console.log("created admin")
console.log("created admin");
}
});

pool.query("CREATE TABLE users (id int AUTO_INCREMENT,name varchar(50),email varchar(50),phone varchar(10),PRIMARY KEY (id));", (ex, rows) => {
}
);

pool.query(
"CREATE TABLE users (id int AUTO_INCREMENT,name varchar(50),email varchar(50),phone varchar(10),PRIMARY KEY (id));",
(ex, rows) => {
if (ex) {
console.log(ex);
} else {
console.log("created users");
}
}
);
pool.query(
"CREATE TABLE menus (day varchar(25) primary key not null, breakfastMenu TEXT, lunchMenu TEXT, dinnerMenu TEXT);",
(ex, rows) => {
if (ex) {
console.log(ex);
} else {
console.log("created users")
console.log("created menu");
}
});
pool.query("CREATE TABLE menus (day varchar(25) primary key not null, breakfastMenu TEXT, lunchMenu TEXT, dinnerMenu TEXT);", (ex, rows)=>{
if(ex){
console.log(ex);
} else{
console.log("created menu");
}
});
}
);

pool.query("CREATE TABLE shuttles (busno int,tripName varchar(50));", (ex, rows) => {
pool.query(
"CREATE TABLE shuttles (busno int,tripName varchar(50));",
(ex, rows) => {
if (ex) {
console.log(ex);
} else {
console.log("created shuttles")
console.log("created shuttles");
}
});
}

}
);

pool.query(
"CREATE TABLE posts (id int AUTO_INCREMENT primary key, name varchar(128), content TEXT, date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
(ex, rows) => {
if (ex) {
console.log(ex);
} else {
console.log("created posts");
}
}
);
pool.query(
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Sunday','omlete','Chowmien','Dosa')",
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Monday','breadjam','Rasam','Appalam')",
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Tuesday','breadjam','Fulka','Rice')",
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Wednesday','breadjam Milk','Rasam','Idli')",
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Thrusday','omlete','Rasam','Peas Masala')",
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Friday','breadjam','Chowmien','Appalam')",
"INSERT into menus (day,breakfastMenu,lunchMenu,dinnerMenu) values ('Saturday','breadjam','Rasam','Appalam')",
(ex, rows) => {
if (ex) {
console.log(ex);
} else {
console.log("Data added to menus");
}
}
);
}

initialiseDB();
16 changes: 16 additions & 0 deletions user/interactsection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ const pool=require("../mysqlconnector");


//make-post
router.post("/make-post",function (req, res){
const { name, postcontent} = req.body

let sql='INSERT INTO posts (name, postcontent) VALUES ( ?, ? );';
pool.query(sql, [name, postcontent], function (error, results, fields) {
if (error) throw error;
res.status(201).json({success: true, results, msg: "Post created successfully"});
});
})



//view-all-posts
router.get("/view-all-posts", function (req, res){
let sql='SELECT * FROM posts';
pool.query(sql, function (error, results, fields) {
if (error) throw error;
res.status(200).json({success: true, results, msg: "All posts retrieved successfully"});
});
})

module.exports=router;

0 comments on commit 3e73437

Please sign in to comment.