Commit 078418bb authored by Hasitha Samarasekara's avatar Hasitha Samarasekara

Filter add for rating and reviews. both backend and frontend done for above filters.

parent 6e5c87ee
......@@ -3,8 +3,8 @@ const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const TutorRatingSchema = new Schema({
tutor_id:{type:mongoose.Schema.Types.ObjectId,ref: 'Post'},
student_id:{type:mongoose.Schema.Types.ObjectId,ref: 'Post'},
tutor_id:{type:mongoose.Schema.Types.ObjectId,ref: 'tutor'},
student_id:{type:mongoose.Schema.Types.ObjectId,ref: 'student'},
rating: {type:String},
review:{type:String},
version:{type:String},
......
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const CreateClassSchema = new Schema({
tutor_id:{type:mongoose.Schema.Types.ObjectId,ref: 'tutor'},
class_method:{type:String},
class_type: {type:String},
institute_id:{type:mongoose.Schema.Types.ObjectId,ref: 'institute'},
batch_no : {type:String},
class_startingDate:{type:Date},
subject:{type:String},
class_fee:{type:String},
student_list:[{type:mongoose.Schema.Types.ObjectId,ref: 'student'}],
isActiveClass: {
type: Boolean,
default: true
},
isActiveForStudent: {
type: Boolean,
default: true
}
});
const Classes = mongoose.model('Classes',CreateClassSchema);
module.exports = Classes;
\ No newline at end of file
......@@ -85,6 +85,14 @@
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
"dev": true
},
"axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"requires": {
"follow-redirects": "^1.14.0"
}
},
"bcrypt-pbkdf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
......@@ -335,6 +343,11 @@
"unpipe": "~1.0.0"
}
},
"follow-redirects": {
"version": "1.14.4",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g=="
},
"forever-agent": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
......
......@@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.4",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
......
const router = require('express').Router();
let classes = require('../models/createClass.model');
const mongoose = require("mongoose");
router.route('/add').post(async(req,res) =>{
console.log("Inside Create Class")
console.log(res.body)
if(req.body.institute_id !== ""){
const tutor_id = mongoose.Types.ObjectId(req.body.tutor_id);
const class_method = req.body.class_method;
const class_type = req.body.class_type;
const institute_id = mongoose.Types.ObjectId(req.body.institute_id);
const batch_no = req.body.batch_no;
const class_startingDate = req.body.class_startingDate;
const subject = req.body.subject;
const class_fee = req.body.class_fee;
const isActiveClass = req.body.isActiveClass;
const isActiveForStudent = req.body.isActiveForStudent;
const newClass = new classes({
tutor_id,
class_method,
class_type,
batch_no,
class_startingDate,
subject,
class_fee,
isActiveClass,
isActiveForStudent,
institute_id
});
console.log(newClass)
newClass.save().then(()=>{
res.json('Class Created!');
}).catch(err =>res.status(400).json('Error: '+err));
}
else {
const tutor_id = mongoose.Types.ObjectId(req.body.tutor_id);
const class_method = req.body.class_method;
const class_type = req.body.class_type;
const batch_no = req.body.batch_no;
const class_startingDate = req.body.class_startingDate;
const subject = req.body.subject;
const class_fee = req.body.class_fee;
const isActiveClass = req.body.isActiveClass;
const isActiveForStudent = req.body.isActiveForStudent;
const newClass = new classes({
tutor_id,
class_method,
class_type,
batch_no,
class_startingDate,
subject,
class_fee,
isActiveClass,
isActiveForStudent,
});
console.log(newClass)
newClass.save().then(()=>{
res.json('Class Created!');
}).catch(err =>res.status(400).json('Error: '+err));
}
});
module.exports = router;
\ No newline at end of file
const router = require('express').Router();
let tutor = require('../models/tutor.user.model');
let tutorRating = require('../models/TutorRatingAndReviews.model');
const axios = require('axios');
const request = require('request');
router.route('/getFilteredList').post((req, res) => {
let teacherReviewList = [];
let reviewListWithScore = [];
tutor.find({
"tutor_Stream": {'$regex': req.body.selectedStream, '$options': 'i'},
"tutor_subjects": {'$regex': req.body.selectedSubject, '$options': 'i'},
"tutor_main_district": {'$regex': req.body.selectedDistrict, '$options': 'i'},
"tutor_main_city": {'$regex': req.body.selectedCity, '$options': 'i'},
"tutor_medium": {'$regex': req.body.selectedLanguage, '$options': 'i'},
"tutor_class_type": {'$regex': req.body.selectedClassType, '$options': 'i'},
})
.then(tutors => {
//console.log(tutors);
tutors.reduce(async (promise, tutor, idx) => {
await promise;
await tutorRating.find({"tutor_id": tutor._id}).then((reviews) => {
//console.log("i : " + JSON.stringify(reviews));
console.log("idx : " + idx);
// console.log("tutor : " + tutors);
const teacherReview = {
"teacher": tutor._id,
"tutor_name": tutor.tutor_name,
"tutor_nic": tutor.tutor_nic,
"tutor_email": tutor.tutor_email,
"tutor_phone": tutor.tutor_phone,
"tutor_address": tutor.tutor_address,
"tutor_password": tutor.tutor_password,
"tutor_gender": tutor.tutor_gender,
"tutor_status": tutor.tutor_status,
"tutor_image": tutor.tutor_image,
"tutor_Stream": tutor.tutor_Stream,
"tutor_subjects": tutor.tutor_subjects,
"tutor_class_type": tutor.tutor_class_type,
"tutor_main_district": tutor.tutor_main_district,
"tutor_main_city": tutor.tutor_main_city,
"tutor_medium": tutor.tutor_medium,
"tutor_qualification": tutor.tutor_qualification,
"review": reviews.map(review => review.review),
"ratings": reviews.map(review => review.rating)
}
//teacherReviewList.indexOf(teacherReview) === -1 ? teacherReviewList.push(teacherReview) : null;
let index = teacherReviewList.findIndex(x => x.teacher === tutor._id);
if (index === -1) {
teacherReviewList.push(teacherReview);
}
if (idx === tutors.length - 1) {
//console.log(teacherReviewList);
teacherReviewList.reduce(async (promise, teacherReview, idx, teacherReviewList) => {
await promise;
console.log("length" + teacherReview.review.length);
if (teacherReview.review.length > 0) {
let options = {
uri: 'http://localhost:5000/review_prediction_for_tutor',
body: JSON.stringify(teacherReview.review),
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}
let response = await axios.post(options.uri, options.body);
let TotalRating = 0;
teacherReview.ratings.map(rate =>{
TotalRating = TotalRating + Number(rate)
})
const temp = {
"teacher": teacherReview.teacher,
"tutor_name": teacherReview.tutor_name,
"tutor_nic": teacherReview.tutor_nic,
"tutor_email": teacherReview.tutor_email,
"tutor_phone": teacherReview.tutor_phone,
"tutor_address": teacherReview.tutor_address,
"tutor_password": teacherReview.tutor_password,
"tutor_gender": teacherReview.tutor_gender,
"tutor_status": teacherReview.tutor_status,
"tutor_image": teacherReview.tutor_image,
"tutor_Stream": teacherReview.tutor_Stream,
"tutor_subjects": teacherReview.tutor_subjects,
"tutor_class_type": teacherReview.tutor_class_type,
"tutor_main_district": teacherReview.tutor_main_district,
"tutor_main_city": teacherReview.tutor_main_city,
"tutor_medium": teacherReview.tutor_medium,
"tutor_qualification": teacherReview.tutor_qualification,
"tutor_reviewValue": response.data.result,
"tutor_avg_rating" : Number(TotalRating/teacherReview.ratings.length)
}
let index = await reviewListWithScore.findIndex(x => x.teacher === teacherReview.teacher);
if (index === -1) {
reviewListWithScore.push(temp);
}
console.log(response.data.result);
} else {
const temp = {
"teacher": teacherReview.teacher,
"tutor_name": teacherReview.tutor_name,
"tutor_nic": teacherReview.tutor_nic,
"tutor_email": teacherReview.tutor_email,
"tutor_phone": teacherReview.tutor_phone,
"tutor_address": teacherReview.tutor_address,
"tutor_password": teacherReview.tutor_password,
"tutor_gender": teacherReview.tutor_gender,
"tutor_status": teacherReview.tutor_status,
"tutor_image": teacherReview.tutor_image,
"tutor_Stream": teacherReview.tutor_Stream,
"tutor_subjects": teacherReview.tutor_subjects,
"tutor_class_type": teacherReview.tutor_class_type,
"tutor_main_district": teacherReview.tutor_main_district,
"tutor_main_city": teacherReview.tutor_main_city,
"tutor_medium": teacherReview.tutor_medium,
"tutor_qualification": teacherReview.tutor_qualification,
"tutor_reviewValue": 0,
"tutor_avg_rating" : 0
}
//reviewListWithScore.push(temp);
//reviewListWithScore.indexOf(temp) === -1 ? reviewListWithScore.push(temp) : null;
let index = reviewListWithScore.findIndex(x => x.teacher === teacherReview.teacher);
if (index === -1) {
reviewListWithScore.push(temp);
}
}
if (idx === teacherReviewList.length - 1) {
res.json(reviewListWithScore)
// console.log(reviewListWithScore);
}
}, Promise.resolve())
}
});
}, Promise.resolve())
//console.log("Return from here");
})
.catch(err => res.status(400).json('Error: ' + err));
});
module.exports = router;
\ No newline at end of file
......@@ -40,9 +40,9 @@ router.route('/').get((req,res) =>{
router.route('/:id').get(function (req, res) {
let id = req.params.id;
console.log("TutorId : " + id)
//console.log("TutorId : " + id)
tutor.findById(id).populate(['tutor_instituteIDList']).then(tutor => {
console.log(tutor);
///console.log(tutor);
res.json(tutor);
}).catch(err => res.status(400).json('Eroor: '+ err));
});
......
......@@ -30,7 +30,8 @@ const questionManage = require('./routes/question.route');
const financeRouter = require('./routes/finance.route');
const studentResult = require('./routes/studentALResult.route');
const tutorRating = require('./routes/tutorRatings.route');
const filteredList = require('./routes/filteredList.route');
const filteredList = require('./routes/filteredListNew.route');
const createClassRoute = require('./routes/createClass.route');
app.use('/studentSingUp',studentRouter);
app.use('/tutorSingUp',tutorRouter);
......@@ -41,6 +42,7 @@ app.use('/admin/finance', financeRouter);
app.use('/studentResults', studentResult);
app.use('/tutorRatings', tutorRating);
app.use('/filteredList', filteredList);
app.use('/createClass', createClassRoute);
app.listen(port, () => {
console.log(`Server is running on Port: ${port}`);
......
......@@ -12344,6 +12344,14 @@
"whatwg-fetch": "^3.4.1"
}
},
"react-bootstrap-icons": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/react-bootstrap-icons/-/react-bootstrap-icons-1.5.0.tgz",
"integrity": "sha512-QC5q4meHQG0cO9RJzeDLSqZ1gbVa9jxFCpONCE3GYl2FkbAKSyJAEsONlzTApbZ8/oG87gPWq0xAyn5SZ/Jafw==",
"requires": {
"prop-types": "^15.7.2"
}
},
"react-dev-utils": {
"version": "11.0.4",
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-11.0.4.tgz",
......
......@@ -8,6 +8,7 @@
"@testing-library/user-event": "^12.8.3",
"bootstrap": "^4.6.0",
"react": "^17.0.2",
"react-bootstrap-icons": "^1.5.0",
"react-dom": "^17.0.2",
"react-dropdown": "^1.9.2",
"react-icons": "^4.2.0",
......
......@@ -25,7 +25,7 @@ export default class Dashboard extends Component {
<div className="logo-src"/>
<div className="header__pane ml-auto">
<div>
<button type="button" className="hamburger close-sidebar-btn hamburger--elastic"data-class="closed-sidebar">
<button type="button" className="hamburger close-sidebar-btn hamburger--elastic" data-class="closed-sidebar">
<span className="hamburger-box">
<span className="hamburger-inner"/>
</span>
......
......@@ -23,7 +23,7 @@ export default class TutorCard extends Component{
<img src={TestTeacher} style={{width:'90px', height:'80px'}}/>
<div className="row" style={{width:'80%',background:'#216E9B',
marginLeft:'10px',marginTop:'5px',justifyContent:'center'}}>
<h5 style={{color:'white',float:'center',marginBottom:'10px',marginTop:'5px'}}>98.5%</h5>
<h5 style={{color:'white',float:'center',marginBottom:'10px',marginTop:'5px'}}><span>{this.props.data.tutor_finalScore.toFixed(2)} %</span></h5>
</div>
</div>
<div className="col-6" style={{margin:'0px'}}>
......
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