Example #1
0
        return new Promise((resolve) => {

            if (data.length === 2) {
                //Getting the values from the object
                var herokuValue = data[Object.keys(data)[0]];
                var CCIValue = data[Object.keys(data)[1]];
                console.log("Heroku Value:" + herokuValue + "CCI Value:" + CCIValue);

                pool.query('INSERT INTO APPLICATION(heroku_application, cci_level) VALUES($1, $2)', [herokuValue, CCIValue])
                    .then(res => resolve(res));

            } else if (data.length === 3) {
                //Getting the values from the object
                var forceValue = data[Object.keys(data)[0]];
                var herokuValueNew = data[Object.keys(data)[1]];
                var CCIValueNew = data[Object.keys(data)[2]];
                console.log("About to insert:" + forceValue + herokuValueNew + CCIValueNew);

                pool.query('INSERT INTO APPLICATION(heroku_application, force_application, cci_level) VALUES($1, $2, $3)', [herokuValueNew, forceValue, CCIValueNew])
                    .then(res => resolve(res));

            } else {
                console.log("Problem" + data);
            }
        });
Example #2
0
router.get('/criteria', function(req, res) {
  // This is the first route that get called by the Front app to get the structure needed to display stuff.
  pool.query('SELECT * FROM public.criteria', function(err, result) {
    if (err) {return res.json(err);}
    res.json(result.rows);
  });
});
Example #3
0
router.get('/top-failling-img', function(req, res, next) {
    pool.query('SELECT * FROM public.top-failling-img', function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      res.json(result.rows);
    });
});
Example #4
0
function queryAll(queryString, values) {
	return pool.query(queryString, values)
		.then(result => result.rows)
		.catch((err) => {
			throw new PgError(err);
		});
}
Example #5
0
app.post('/login',function(req,res)
{
var username=req.body.username;
   var password=req.body.password;
   console.log(password);
   pool.query('SELECT * FROM "hashingdemo" WHERE username=$1',[username],function(err,result){
       if(err)
       {
           res.status(500).send(err.toString());
       }
       else
       {
           if(result.rows.length===0)
           {
               res.status(403).send('username/password invalid');
           }
           else
           {
               var dbString=result.rows[0].password;
               var salt=dbString.split('$')[2];
               var hashedPassword=hash(password,salt);
               if(hashedPassword===dbString)
               {
                   req.session.auth={userId:result.rows[0].id};
                   res.send('credentials correct');
               }
               else
               {
                   res.status(403).send('uname/pwd invalid');
               }
           }
       }
   });
});
Example #6
0
router.get('/passfailresult', function(req, res, next) {
    pool.query('SELECT * FROM public.passfailresultcount', function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      res.json(result.rows);
    });
});
Example #7
0
app.post('/submit-comment/:articleName', function (req, res) {
   // Check if the user is logged in
    if (req.session && req.session.auth && req.session.auth.userId) {
        // First check if the article exists and get the article-id
        pool.query('SELECT * from article where title = $1', [req.params.articleName], function (err, result) {
            if (err) {
                res.status(500).send(err.toString());
            } else {
                if (result.rows.length === 0) {
                    res.status(400).send('Article not found');
                } else {
                    var articleId = result.rows[0].id;
                    // Now insert the right comment for this article
                    pool.query(
                        "INSERT INTO comment (comment, article_id, user_id) VALUES ($1, $2, $3)",
                        [req.body.comment, articleId, req.session.auth.userId],
                        function (err, result) {
                            if (err) {
                                res.status(500).send(err.toString());
                            } else {
                                res.status(200).send('Comment inserted!')
                            }
                        });
                }
            }
       });     
    } else {
        res.status(403).send('Only logged in users can comment');
    }
});
Example #8
0
app.get('/insert', function(req, res) {
    const text = `INSERT INTO
      reflections(id, success, low_point, take_away, created_date, modified_date)
      VALUES($1, $2, $3, $4, $5, $6)
      returning *`;
    const values = [
      1,
      "sucess1",
      "lo1",
      "take1",
      null,
      null
    ];

      pool.query(text, values)
      .then((res) => {
        pool.end();
        const rows = res.rows;
        return res.status(201).send(rows[0]);
      })
      .catch((err) => {
        pool.end();
        return res.status(400).send(err);
      })
      
});
Example #9
0
router.get('/result-per-dates', function(req, res, next) {
  pool.query('SELECT * FROM public.result-per-dates', function(err, result) {
    // handle an error from the query
    if(err) {return res.json(err);}
    res.json(result.rows);
  });
});
Example #10
0
router.get('/pfgolden', function(req, res, next) {
    pool.query('SELECT * FROM public.goldencount', function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      logger.debug(result.rows);
      res.json(result.rows);
    });
});
Example #11
0
 function logConversation(msgLog) {
   pool.query('insert into conversation (smoochid, received, usermessage, role, message_id, sourcetype, receivedtime, responsemessage, responsetype, responsetime) values ($1,$2, $3, $4, $5,$6, $7, $8, $9, $10);',
     [msgLog.smoochId, msgLog.received, msgLog.usermessage, msgLog.role, msgLog.message_id, msgLog.sourcetype, msgLog.receivedtime, msgLog.responsemessage, msgLog.responsetype, msgLog.responsetime],
     function(err){
       if(err) console.log("|| error in log ",err);
     }
   );
 }
Example #12
0
router.get('/totimgfailratio', function(req, res, next) {
    pool.query('SELECT * FROM public.totimgfailratio', function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      logger.debug(result.rows);
      res.send(result.rows);
    });
});
Example #13
0
router.get('/resultwithcrit', function(req, res, next) {
    pool.query('SELECT * FROM public.result_w_crit', function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      logger.debug(result.rows);
      res.json(result.rows);
    });
});
Example #14
0
router.get('/passfailresult/:username', function(req, res, next) {
  var usernameid = req.params.username;
    pool.query('SELECT * FROM public.passfailresultcount WHERE username = $1', [usernameid], function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      res.json(result.rows);
    });
});
Example #15
0
 return new Promise((resolve, reject) => {
   pool.query(text, params)
   .then((res) => {
     resolve(res);
   })
   .catch((err) => {
     reject(err);
   })
 })
	removeDataByUserId(userid,function(){
		console.log("插入数据");
		for (var i = 0; i < json.data.length; i++) {
			var valArr = [ json.data[i].id, json.data[i].val,json.data[i].userid ];
			pool.query("insert into tbl_todolist(id,val,userId) values($1,$2,$3)",valArr,function(err) {
				if (err){console.log(err); return ;}
			});
		}
	});
Example #17
0
router.get('/randgolden', function(req, res, next) {
  logger.debug("Inside The Golden Request");
    pool.query('SELECT * FROM public.randgolden', function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      logger.debug("randgolden:", result.rows);
      res.json(result.rows);
    });
});
						function() {
                            pgClient.query('SELECT * FROM passwordless WHERE uid=$1',[user], function(err, obj) {
								expect(err).to.not.exist;
								expect(obj).to.exist;
								expect(obj.rows[0].token).to.exist;
								expect(obj.rows[0].token).to.not.equal(hashedToken1);
								done();
							});
						});
			function () {
				pgClient.query('SELECT token FROM passwordless WHERE uid=$1', [user], function (err, obj) {
					expect(err).to.not.exist;
					expect(obj).to.exist;
					expect(obj.rows[0].token).to.exist;
					expect(bcrypt.getRounds(obj.rows[0].token)).to.equal(5);
					done();
				})
			});
Example #20
0
router.get('/totimgfailratio/:username', function(req, res, next) {
  var usernameid = req.params.username;
    pool.query('SELECT * FROM public.totimgfailratio WHERE username = $1', [usernameid], function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      logger.debug(result.rows);
      res.send(result.rows);
    });
});
Example #21
0
router.get('/resultwithcrit/:username', function(req, res, next) {
    var username = req.params.username;
    pool.query('SELECT * FROM public.result_w_crit WHERE username = $1', [username], function(err, result) {
      // handle an error from the query
      if(err) {return res.json(err);}
      logger.debug(result.rows);
      res.json(result.rows);
    });
});
Example #22
0
	var readForecast = function(location_ID) {
		pool.query(
			"SELECT * FROM forecast"+
			" WHERE location_ID=$1", [location_ID], function(error,result) {
				if (error) return console.error(error);
				callback(result);
			}
		);
	}
Example #23
0
 function exec(query, values) {
     return pool.query(query, values).catch(function (err) {
         //add the sql line number to the error output if available
         if (err && err.position) {
             err.sql_line = (query.substring(0, err.position).match(/\n/g) || []).length + 1;
         }
         throw err;
     });
 }
	var readList = function(profile_id,callback) {
		pool.query(
			"SELECT * FROM grocery_list"+
			" WHERE profile_id=$1", [profile_id], function(error,result) {
				if (error) return console.error(error);
				callback(result);
			}
		);
	}
	var createList = function(item,profile_id) {
		pool.query(
			"INSERT INTO grocery_list" +
			" (item, profile_id)" +
			" VALUES ($1, $2);", [item, profile_id], function(error, result) {
				if (error) return console.error(error);
			}
		);
	}
// 保存所有
function saveAllData(json) {
	removeAllData();
	console.log("保存所有数据");
	for (var i = 0; i < json.data.length; i++) {
		var valArr = [ json.data[i].id, json.data[i].val,json.data[i].userId ];
		pool.query("insert into tbl_todolist(id,val,userId) values($1,$2,$3)",valArr,function(err) {
			if (err) {console.log(err); return ;}
		});
	}
}
Example #27
0
	var saveForecast = function(temp_high,temp_low,summary,precip,location_ID) {
		pool.query(
			"INSERT INTO forecast" +
			" (temp_high, temp_low, summary, precip, location_ID)" +
			" VALUES ($1,$2,$3,$4,$5);", [temp_high,temp_low,summary,precip,location_ID], function(error,result) {
				if (error) return console.error(error);
				//console.log(result);
			}
		);
	}
	var updateList = function(item,profile_id) {
		//console.log(item);
		pool.query(
			"UPDATE grocery_list" +
			" SET item = $1" +
			" WHERE profile_id = $2;", [item, profile_id], function(error, result) {
				if (error) return console.error(error);
			}
		);
	}
//根据用户id删除数据
function removeDataByUserId(userid,callback){
	console.log("根据用户id删除数据");
	var sqlStr = 'delete from tbl_todolist where userid = \''+userid+'\'';
	console.log(sqlStr);
	pool.query(sqlStr, function(err) {
		if (err){console.log(err); return ;}
		callback();
	});
	
}
Example #30
0
	var saveLocation = function(latitude,longitude,query_date,callback) {
		pool.query(
			//format query date to fit SQL timestamp format
			"INSERT INTO location" + 
			" (latitude, longitude, query_date)" +
			" VALUES ($1, $2, $3) RETURNING id;", [latitude,longitude,query_date], function(error, result) { //security meausures
				if (error) return console.error(error);
				callback(result.rows[0].id);
			}
		);
	}