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 router.post('/', function(req, res) {
14 console.log(req.body);
15 req.checkBody("tag_name", "TAG Name must not be empty").notEmpty();
17 var errors = req.validationErrors();
20 var response = ''; for(var i = 0; i < errors.length; i++) {
21 console.log(errors[i]['msg']);
22 response = response + errors[i]['msg'] + '; ';
25 if(errors) { res.status(500);
26 res.send({'error': response});
30 var tag_details = req.body;
32 db_pool.getConnection(function(err, 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}');
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.
47 res.end('{"success" : "Updated Successfully", "status" : 200}');
52 module.exports = router;