-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e429859
commit 0834afc
Showing
9 changed files
with
1,420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.