511f4ccb0d0998f1472b06c8dfd82f3a248e5cbd
[releng.git] / utils / test / vnfcatalogue / VNF_Catalogue / routes / add_tag.js
1 /*******************************************************************************
2  * Copyright (c) 2017 Kumar Rishabh and others.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Apache License, Version 2.0
6  * which accompanies this distribution, and is available at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *******************************************************************************/
9
10 var express = require('express');
11 var router = express.Router();
12
13 router.post('/', function(req, res) {
14   console.log(req.body);
15   req.checkBody("tag_name", "TAG Name must not be empty").notEmpty();
16
17   var errors = req.validationErrors();
18   console.log(errors);
19
20   var response = '';  for(var i = 0; i < errors.length; i++) {
21     console.log(errors[i]['msg']);
22     response = response + errors[i]['msg'] + '; ';
23   }
24
25   if(errors) {  res.status(500);
26     res.send({'error': response});
27     return;
28   }
29
30   var tag_details = req.body;
31
32   db_pool.getConnection(function(err, connection) {
33     // Use the connection
34     sql_query = 'INSERT INTO tag SET ?'
35     connection.query(sql_query, tag_details, function (error, results, fields) {
36         // And done with the connection.
37       res.end('{"success" : "Updated Successfully", "status" : 200}');
38       return;
39         connection.release();
40         // Handle error after the release.
41         if (error) throw error;
42         // Don't use the connection here, it has been returned to the pool.
43     });
44   });
45
46
47   res.end('{"success" : "Updated Successfully", "status" : 200}');
48   return;
49
50 });
51
52 module.exports = router;