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();
12 var async = require('async');
14 var renderer = function(res, err, results) {
16 res.render('index', { title: 'Express', json: results });
19 var get_images = function(result, callback) {
20 db_pool.getConnection(function(err, connection) {
21 sql_query = 'select photo_url from photo where photo_id = ' + result['photo_id'];
22 // TODO find why it works here and not when declared outside the method
23 console.log(sql_query);
24 connection.query(sql_query, function (error, results, fields) {
25 console.log(results[0].photo_url);
26 //result['photo_url'] = results[0].photo_url;
29 result['photo_url'] = false;
32 result['photo_url'] = results[0].photo_url;
34 callback(null, result);
35 //if (error) throw error;
40 /* GET VNF_Catalogue Home Page. */
41 router.get('/', function(req, res) {
42 db_pool.getConnection(function(err, connection) {
43 sql_query = 'select * from vnf order by lines_of_code desc limit 8';
44 // TODO find why it works and not above
45 connection.query(sql_query, function (error, results, fields) {
46 //console.log(results);
49 res.render('index', { title: 'Express', json: false});
51 async.map(results, get_images, renderer.bind(null, res));
52 //res.render('index', { title: 'Express', json: results});
58 module.exports = router;