Showing
1 changed file
with
26 additions
and
2 deletions
| ... | @@ -16,6 +16,7 @@ router.get('/', function (req, res) { | ... | @@ -16,6 +16,7 @@ router.get('/', function (req, res) { |
| 16 | 16 | ||
| 17 | router.get('/products', function (req, res) { | 17 | router.get('/products', function (req, res) { |
| 18 | CategoriModel.find(function (err, products) { | 18 | CategoriModel.find(function (err, products) { |
| 19 | + console.log(products); | ||
| 19 | res.render( | 20 | res.render( |
| 20 | 'category/products', | 21 | 'category/products', |
| 21 | { categories: products } | 22 | { categories: products } |
| ... | @@ -33,7 +34,7 @@ router.post('/categories/write', loginRequired, function (req, res) { | ... | @@ -33,7 +34,7 @@ router.post('/categories/write', loginRequired, function (req, res) { |
| 33 | var category = new CategoriModel({ | 34 | var category = new CategoriModel({ |
| 34 | title: req.body.title, | 35 | title: req.body.title, |
| 35 | description: req.body.description, | 36 | description: req.body.description, |
| 36 | - username: req.user.username, | 37 | + username: req.user.displayname, |
| 37 | }); | 38 | }); |
| 38 | // | 39 | // |
| 39 | var validationError = category.validateSync(); | 40 | var validationError = category.validateSync(); |
| ... | @@ -133,6 +134,28 @@ router.get('/products/detail/:id', function (req, res) { | ... | @@ -133,6 +134,28 @@ router.get('/products/detail/:id', function (req, res) { |
| 133 | router.post('/products/detail/:id', loginRequired, function (req, res) { | 134 | router.post('/products/detail/:id', loginRequired, function (req, res) { |
| 134 | var item = []; | 135 | var item = []; |
| 135 | var count = 1; | 136 | var count = 1; |
| 137 | + var temp = ''; | ||
| 138 | + console.log(req.body.videoNum.length); | ||
| 139 | + if (req.body.videoNum.length > 30) { | ||
| 140 | + for (var i in req.body.videoNum) { | ||
| 141 | + temp += req.body.videoNum[i]; | ||
| 142 | + } | ||
| 143 | + item.push(temp.split('///')); | ||
| 144 | + var video = new VideoModel({ | ||
| 145 | + categori: item[0][2], | ||
| 146 | + id: count, | ||
| 147 | + title: item[0][1], | ||
| 148 | + video_id: item[0][3], | ||
| 149 | + urls: item[0][4], | ||
| 150 | + }); | ||
| 151 | + var validationError = video.validateSync(); | ||
| 152 | + if (validationError) { | ||
| 153 | + res.send(validationError); | ||
| 154 | + } else { | ||
| 155 | + video.save(function (err) {}); | ||
| 156 | + } | ||
| 157 | + count++; | ||
| 158 | + } else { | ||
| 136 | for (var i in req.body.videoNum) { | 159 | for (var i in req.body.videoNum) { |
| 137 | item.push(req.body.videoNum[i].split('///')); | 160 | item.push(req.body.videoNum[i].split('///')); |
| 138 | var video = new VideoModel({ | 161 | var video = new VideoModel({ |
| ... | @@ -150,6 +173,7 @@ router.post('/products/detail/:id', loginRequired, function (req, res) { | ... | @@ -150,6 +173,7 @@ router.post('/products/detail/:id', loginRequired, function (req, res) { |
| 150 | } | 173 | } |
| 151 | count++; | 174 | count++; |
| 152 | } | 175 | } |
| 176 | + } | ||
| 153 | res.redirect('/categori/products/detail/' + req.params.id); | 177 | res.redirect('/categori/products/detail/' + req.params.id); |
| 154 | }); | 178 | }); |
| 155 | 179 | ||
| ... | @@ -201,7 +225,7 @@ router.get('/products/delete/:id', function (req, res) { | ... | @@ -201,7 +225,7 @@ router.get('/products/delete/:id', function (req, res) { |
| 201 | router.get('/products/detail/delete/:id', function (req, res) { | 225 | router.get('/products/detail/delete/:id', function (req, res) { |
| 202 | VideoModel.findOne({ _id: req.params.id }, function (err, products) { | 226 | VideoModel.findOne({ _id: req.params.id }, function (err, products) { |
| 203 | VideoModel.deleteMany({ _id: products }, function (err) { | 227 | VideoModel.deleteMany({ _id: products }, function (err) { |
| 204 | - res.redirect('/categori/products/detail/'+ redirectUrls); | 228 | + res.redirect('/categori/products/detail/' + redirectUrls); |
| 205 | }); | 229 | }); |
| 206 | }); | 230 | }); |
| 207 | }); | 231 | }); | ... | ... |
-
Please register or login to post a comment