fac-17 / week-6-glan

PostgreSQL
https://week-6-glan.herokuapp.com/
0 stars 4 forks source link

Glash of the Glans


Team


User Journey

A brave warrior enters their name and some personality traits and is returned the name of the glan they belong to. Glans are calculated based upon personality and each has a unique character.

The user feels a sense of accomplishment being grouped with others into a glanourous glan! Hoorah!


Things We Learnt

![](https://i.imgur.com/ptPwdaX.jpg =300x360)



const getSum = cb => {
  databaseConnection.query(
    `SELECT glans.glan_name, total.warrior_name FROM glans INNER JOIN (SELECT warrior_name, (warrior_c1 + warrior_c2 + warrior_c3 + 1) AS warrior_total FROM warriors) AS total ON glans.glan_id = total.warrior_total;`
  ),



![](https://i.imgur.com/vct9VDR.jpg =600x400)


Code Snippets


Splitter:


Handle database queries loop

public/fetch.js

let getGlan = document.getElementById("getGlan");
getGlan.onclick = function() {
  domRequest("/getGlan");
};

src/router.js

} else if(endpoint.startsWith("/getGlan")) {
    getGlan(req, res);

src/handler.js

let getGlan = (req, res) => {
  getData.getSum((error, result) => {
    if (error) {
      console.log("500, Get data error", error);
      res.writeHead(500, "Content-Type:text/html");
      res.end("<h1>Sorry, there was a problem getting the users<h1>");
    } else {
      res.writeHead(200, { "Content-Type": "application:json" });
      res.end(JSON.stringify(result));
    }
  });
};

queries/getData.js

const getSum = cb => {
  databaseConnection.query(`SELECT glans.glan_name, total.warrior_name 
FROM glans 
INNER JOIN (SELECT warrior_name, (warrior_c1 + warrior_c2 + warrior_c3 + 1) 
AS warrior_total FROM warriors) 
AS total ON glans.glan_id = total.warrior_total;`, (err, res) => {
    if (err) return cb(err);
    cb(null, res.rows);
  });
};




Problems We Had


Communication