Prepare for DPDK 19.08 support
[samplevnf.git] / VNF_Catalogue / routes / search_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 /* Post Controller for Tag autocomplete form */
14 router.get('/', function(req, res) {
15     tag_partial = req.param('key');
16     db_pool.getConnection(function(err, connection) {
17
18         sql_query = 'select tag_name from tag where tag_name like "%'+ tag_partial + '%" and is_vnf_name = false limit 5';
19         // TODO find why it works and not above
20         console.log(sql_query);
21         connection.query(sql_query, function (error, results, fields) {
22             console.log(results);
23
24             if(results == null) {
25                 connection.release();
26                 res.end(JSON.stringify({}));
27             } else {
28                 var data=[];
29                 for(i = 0; i < results.length; i++) {
30                     data.push(results[i].tag_name.replace(/\r?\n|\r/g, ''));
31                 }
32                 console.log(results);
33                 connection.release();
34                 res.end(JSON.stringify(results));
35             }
36             //if (error) throw error;
37         });
38     });
39 });
40
41 module.exports = router;