Skip to content

Commit

Permalink
Added 2nd commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RamakrushnaBiswal committed Aug 31, 2024
1 parent e429859 commit 0834afc
Show file tree
Hide file tree
Showing 9 changed files with 1,420 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.env
7 changes: 7 additions & 0 deletions connection/dbConn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import mongoose from "mongoose";

const dbConn=async()=>{
await mongoose.connect("mongodb://localhost:27017/ticketChatbot");
}

export default dbConn;
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import express from "express";
import path from 'path'
const app=express();


const port=3000
import dbConn from './connection/dbConn.js'
dbConn().then(()=>{
console.log("Connected to the database");
}).catch((err)=>{
console.log("Error connecting to the database",err);
});

//Schema for the database
// import User from './models/user.js'
import bookingSchema from './models/Bookings.js'


app.use(express.static('public'))
app.set('view engine', 'ejs');
app.set('views', path.join('views'))
app.use(express.urlencoded({ extended: true}))


app.get('/',(req,res)=>{
res.render('index')
})

app.get('/thank',(req,res)=>{
res.render('thank')
})
app.post('/submit',(req,res)=>{
const data=req.body;
const booking=new bookingSchema(data);
booking.save().then(()=>{
console.log("Data saved");
}).catch((err)=>{
console.log("Error saving data",err);
})
res.redirect('/thank')
console.log(data);
})

app.listen(port,()=>{
console.log("Server running in port",port);
})
28 changes: 28 additions & 0 deletions models/Bookings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import mongoose from "mongoose";

const bookingSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
date: {
type: Date,
required: true
},
time: {
type: String,
required: true
},
ticket: {
type: Number,
required: true
},
createdAt: {
type:Date,
default:Date.now
}
});

const Bookings = mongoose.model('Booking', bookingSchema);

export default Bookings;
28 changes: 28 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import mongoose from 'mongoose';

const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
trim: true
},
password: {
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true,
match: [/.+\@.+\..+/, 'Please fill a valid email address']
},
createdAt: {
type: Date,
default: Date.now
}
});

const User = mongoose.model('User', userSchema);

export default User;
Loading

0 comments on commit 0834afc

Please sign in to comment.