Commit cbb339e0 authored by Navodya Pasqual's avatar Navodya Pasqual

Merge branch 'master' into IT19408316

parents a32a848c 77870571
This diff is collapsed.
const express = require('express');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const cors = require('cors');
const bodyParser = require('body-parser');
//Importing chatbot api
const chatbotAPI = require('./src/routes/chatbot/dialogFlow');
dotenv.config();
const app = express();
app.use(cors());
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
const PORT = process.env.PORT || 8081;
/**
* Get MONGODB_URI from .env
*/
const MONGODB_URI = process.env.MONGODB_URI;
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}, (error) => {
if (error) {
console.log('Database Error:', error.message);
console.log('######################################################');
}
});
mongoose.connection.once('open', () => {
console.log('Database Connected...');
initial();
console.log('######################################################');
});
app.route('/').get((req, res) => {
res.send('Research Project');
});
require('./src/routes/auth.routes')(app);
require('./src/routes/user.routes')(app);
app.use('/api/dialogflow', chatbotAPI);
app.listen(PORT, () => {
console.log('######################################################');
console.log(`Server is ON and running on PORT : ${PORT}`);
console.log('...Wait DB connecting...');
});
const db = require("./src/modules");
const Role = db.role;
function initial() {
Role.estimatedDocumentCount((err, count) => {
if (!err && count === 0) {
new Role({
name: "user"
}).save(err => {
if (err) {
console.log("error", err);
}
console.log("added 'user' to roles collection");
});
new Role({
name: "manager"
}).save(err => {
if (err) {
console.log("error", err);
}
console.log("added 'manager' to roles collection");
});
new Role({
name: "student"
}).save(err => {
if (err) {
console.log("error", err);
}
console.log("added 'student' to roles collection");
});
new Role({
name: "admin"
}).save(err => {
if (err) {
console.log("error", err);
}
console.log("added 'admin' to roles collection");
console.log('######################################################');
});
}
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment