# Santa Claus's Little Helpers <font size="5"> * Alex * Ayub * Pat * Roshan ![](https://media.giphy.com/media/l0IypZQvIY9xkaLSw/giphy.gif) --- ## Project requirements * Build an app using the Express framework. * Use a PostgreSQL database to store and retrieve your data. * Use the retrieved data to populate a Handlebars template for server-side rendering to be displayed on the front-end. Stretch Goals * Authorisation (editing to header partial for when logged in vs not) * Animated svg --- ![](https://i.imgur.com/IAIcKvs.jpg =700x) --- ![](https://i.imgur.com/HhMLUbG.jpg) --- ## File structure - MVC Model ![](https://i.imgur.com/UUoUrgN.png) --- ## Mobbed the creation of files ![](https://i.imgur.com/SjnvlVV.png) --- ## Accessibility ![](https://i.imgur.com/lggdreB.png) --- ## Tests ![](https://i.imgur.com/eJCa2Jw.png) --- ## Helper functions ```javascript= //goodBad.js module.exports = array => { const totalGoodPoints = array.reduce((acc, currNum) => { return acc + parseInt(currNum); }, 0); return totalGoodPoints; }; ``` --- ## Using helpers and handlebars to display our database ```javascript= {{#each users}} <tr> <td> {{capitaliseFirstLetter name}} </td> <td> {{gift}} </td> <td> {{goodBad behaviour}} </td> <td><a href="/delete-user/{{name}}"><button id="delete-button">X</button></a></td> </tr> {{/each}} ``` --- ## Delete user ```javascript= const deleteUserData = require("../model/queries/deleteData"); exports.deleteUser = (req, res) => { const nameUser = req.params.name; deleteUserData(nameUser) .then(() => { res.redirect("/presents"); }) .catch(err => { console.log("this is err", err.message); throw err; }); }; ``` --- ## Error handling ```javascript= exports.client = (req, res) => { res.status(404).render("error", { layout: "error", statusCode: 404, errorMessage: "Page not found :(", imageUrl: "https://gph.is/2ify9JA" }); }; ``` --- ## Use of promises ```javascript= postData({ name: req.body.username, behaviour: goodOrBad, category: req.body.category }) .then(() => { res.redirect("/presents"); }) .catch(error => { throw error; }); ``` --- ## Issues with data base integration ### Banging our heads for hours ![](https://media.giphy.com/media/l0MYOUI5XfRk4LLWM/giphy.gif) ___ ```javascript= <label class="dropdown" for='category' name='category'> <p class="searchBy">Search by category </p> <select class="category" name="category" required> <option value="Sports"> Sports </option> <option value="Food"> Food </option> <option value="Technology"> Technology </option> <option value="Education"> Education </option> </select> </label> ``` --- ![](https://i.imgur.com/jbcJihK.png) --- ## Pat brought the Christmas magic ![](https://media.giphy.com/media/d4aTLaZv6yeFPfgI/giphy.gif)
{"metaMigratedAt":"2023-06-15T02:43:41.667Z","metaMigratedFrom":"Content","title":"Santa Claus's Little Helpers","breaks":true,"contributors":"[{\"id\":\"75028714-a786-4451-b613-55feb28170a6\",\"add\":544,\"del\":37},{\"id\":\"8df6977e-0462-4cc9-98d6-4750e77012fd\",\"add\":614,\"del\":14},{\"id\":\"8ebbe70b-8a0b-4727-a673-12c5162b1542\",\"add\":1197,\"del\":48},{\"id\":\"7a8e5efa-23d6-4b8f-8e21-d8d2bcafea85\",\"add\":790,\"del\":74}]"}
    204 views
   Owned this note