1 /*******************************************************************************
2 * Copyright (c) 2017 Kumar Rishabh and others.
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 *******************************************************************************/
10 var express = require('express');
11 var router = express.Router();
13 /* Post controller for VNF_TAG Association */
14 router.post('/', function(req, res) {
15 req.checkBody("tag_name", "TAG Name must not be empty").notEmpty();
16 req.checkBody("vnf_name", "VNF Name must not be empty").notEmpty();
18 var errors = req.validationErrors();
21 var response = ''; for(var i = 0; i < errors.length; i++) {
22 console.log(errors[i]['msg']);
23 response = response + errors[i]['msg'] + '; ';
26 if(errors) { res.status(500);
27 res.send({'error': response});
31 var tag_name = req.param('tag_name');
32 var vnf_name = req.param('vnf_name');
34 db_pool.getConnection(function(err, connection) {
36 //sql_query = 'INSERT INTO tag SET ?'
37 sql_query = 'insert into vnf_tags(vnf_id, tag_id) values ((select vnf_id from vnf where vnf_name = \'' + vnf_name + '\'), (select tag_id from tag where tag_name = \'' + tag_name + '\'))';
38 console.log(sql_query);
39 connection.query(sql_query, function (error, results, fields) {
40 // And done with the connection.
43 res.end('{"success" : "Updated Successfully", "status" : 200}');
45 // Handle error after the release.
46 if (error) throw error;
47 // Don't use the connection here, it has been returned to the pool.
51 res.end('{"success" : "Updated Successfully", "status" : 200}');
52 //res.render('vnf_tag_association', { title: 'Express' });
55 module.exports = router;