|
1 | 1 | const user = require('../schema/user.js'); |
2 | 2 | const proj = require('../schema/project.js'); |
3 | | - |
| 3 | +const expressValidator = require('express-validator'); |
| 4 | +const { check, validationResult } = require('express-validator/check'); |
| 5 | +// var multer = require('multer'); |
| 6 | +// var storage = multer.diskStorage({ |
| 7 | +// destination: (req, file, cb) => { |
| 8 | +// cb(null, 'public/images/uploads') |
| 9 | +// }, |
| 10 | +// filename: (req, file, cb) => { |
| 11 | +// cb(null, file.fieldname + '-' + Date.now()) |
| 12 | +// } |
| 13 | +// }); |
| 14 | +// var upload = multer({storage: storage}); |
4 | 15 | module.exports = { |
5 | 16 | SubmitprojectForm:function(req,res){ |
6 | 17 | res.render('projectForm') |
@@ -33,28 +44,47 @@ module.exports = { |
33 | 44 | ]).sort({createdAt:-1}).then((da)=>{ |
34 | 45 | console.log(req.user); |
35 | 46 | user.findOne({ Eid: req.params.sd }).then(function (use) { |
| 47 | + console.log(da) |
36 | 48 | res.render('other-landing', { use: use, ques: da, sign: req.user}); |
37 | 49 | }) |
38 | 50 | }) |
39 | 51 | }, |
40 | 52 | publish: function(req, res) { |
41 | | - var lan=req.body.genre.split(','); |
42 | | - new proj({ |
43 | | - createdAt:Date.now(), |
44 | | - pname: req.body.contentname, |
45 | | - pid: req.user.Eid, |
46 | | - github: req.body.git, |
47 | | - Lang:lan, |
48 | | - content: req.body.cont, |
49 | | - upvote: '', |
50 | | - downvote: '', |
51 | | - proid: Math.floor(Math.random() * 100000) |
52 | | - }) |
53 | | - .save() |
54 | | - .then(function() { |
55 | | - res.redirect('/profile/profileview/' + req.user.Eid); |
56 | | - }); |
57 | | - }, |
| 53 | + var lan=req.body.genre.split(','); |
| 54 | + req.check('contentname','Project name is required !!').notEmpty(); |
| 55 | + req.check('git','Github url is required !!').isURL(); |
| 56 | + req.check('cont','Description is required !!').notEmpty(); |
| 57 | + req.check('genre','Language used is required !!').notEmpty(); |
| 58 | + req.getValidationResult(req) |
| 59 | + .then((result)=>{ |
| 60 | + if(result.isEmpty() === false){ |
| 61 | + result.array().forEach((error)=>{ |
| 62 | + console.log(error.msg); |
| 63 | + res.redirect('/profile/submitProject'); |
| 64 | + }); |
| 65 | + } else { |
| 66 | + new proj({ |
| 67 | + createdAt:Date.now(), |
| 68 | + pname: req.body.contentname, |
| 69 | + pid: req.user.Eid, |
| 70 | + github: req.body.git, |
| 71 | + Lang:lan, |
| 72 | + content: req.body.cont, |
| 73 | + upvote: '', |
| 74 | + downvote: '', |
| 75 | + proid: Math.floor(Math.random() * 100000), |
| 76 | + image:'/images/uploads/'+req.file.filename |
| 77 | + }) |
| 78 | + .save() |
| 79 | + .then(function() { |
| 80 | + res.redirect('/profile/profileview/' + req.user.Eid); |
| 81 | + }); |
| 82 | + } |
| 83 | + }) |
| 84 | + .catch((err)=>{ |
| 85 | + console.log(`${err}`); |
| 86 | + }); |
| 87 | +}, |
58 | 88 | upDownVote: function (req,res) { |
59 | 89 | proj.findOne({proid: req.body.project}).then((pro)=>{ |
60 | 90 | if(pro.upDownVote.get(req.body.client)){ |
@@ -90,19 +120,48 @@ module.exports = { |
90 | 120 | updateDetails: function(req, res) { |
91 | 121 | user.findOne({ Eid: req.user.Eid }).then(function(data) { |
92 | 122 | // prettier-ignore |
93 | | - (data.fname = req.body.fname), |
94 | | - (data.lname = req.body.lname), |
95 | | - (data.bio = req.body.bio), |
96 | | - (data.college = req.body.college), |
97 | | - (data.email = req.body.email), |
98 | | - (data.github = req.body.githubUrl), |
99 | | - (data.linkedin = req.body.linkedinUrl), |
100 | | - (data.city = req.body.city), |
101 | | - (data.country = req.body.country), |
102 | | - (data.lang = req.body.languages), |
103 | | - (data.facebook = req.body.facebookUrl); |
104 | | - data.save(); |
105 | | - res.send('success'); |
| 123 | + req.check('fname','First name is required !').notEmpty(); |
| 124 | + req.check('lname','Last name is required !').notEmpty(); |
| 125 | + req.check('bio','Bio is required !').notEmpty(); |
| 126 | + req.check('college','College name is required !').notEmpty(); |
| 127 | + req.check('email','Email is required !').isEmail(); |
| 128 | + req.check('githubUrl','Github url is required !').isURL(); |
| 129 | + req.check('linkedinUrl','Linkedin url is required !').isURL(); |
| 130 | + req.check('facebookUrl','Facebook url is required !').isURL(); |
| 131 | + req.check('city','City name is required !').notEmpty(); |
| 132 | + req.check('country','Country name is required !').notEmpty(); |
| 133 | + req.check('languages','Language is required !').notEmpty(); |
| 134 | + req.getValidationResult(req) |
| 135 | + .then((result)=>{ |
| 136 | + if(result.isEmpty() === true){ |
| 137 | + result.array().forEach((error)=>{ |
| 138 | + console.log(error.msg); |
| 139 | + res.redirect('/profile/setting'); |
| 140 | + }); |
| 141 | + } |
| 142 | + }) |
| 143 | + .catch((err)=>{ |
| 144 | + console.log(`${err}`); |
| 145 | + }); |
| 146 | + (data.fname = req.body.fname), |
| 147 | + (data.lname = req.body.lname), |
| 148 | + (data.bio = req.body.bio), |
| 149 | + (data.college = req.body.college), |
| 150 | + (data.email = req.body.email), |
| 151 | + (data.github = req.body.githubUrl), |
| 152 | + (data.linkedin = req.body.linkedinUrl), |
| 153 | + (data.city = req.body.city), |
| 154 | + (data.country = req.body.country), |
| 155 | + (data.lang = req.body.languages), |
| 156 | + (data.facebook = req.body.facebookUrl); |
| 157 | + data.save() |
| 158 | + .then(()=>{ |
| 159 | + console.log('profile updated !'); |
| 160 | + // res.send('success'); |
| 161 | + }) |
| 162 | + .catch((err)=>{ |
| 163 | + console.log(`${err}`); |
| 164 | + }); |
106 | 165 | }); |
107 | 166 | }, |
108 | 167 | getDetails: function(req, res) { |
|
0 commit comments