Miah Elizabeth Bates
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Be-Kind Re-Mind ![](https://i.imgur.com/qAMt8nQ.png) --- #### Planning - First we listed out the user stories for our project on our project board - We categorised each of the user stories into big issues where we split the task of into front-end and back-end - We also had smaller issues for researching new technologies and smaller tasks --- ![](https://i.imgur.com/vql9krl.png) --- - We planned to create the front-end first so we had a visual understanding of where data will be retrieved and sent to and later on it will help with what we would also add to the database that we wouldn't have intially known if we hadn't created the front-end --- - we created all of the core pages such as the homepage and medication page, later on added the add medication form - Since we had the front end set up we decided to then go on to work onto user authentication/ creating db queries add/delete medication --- #### DB Schema :elephant: - Hosted on elephant SQL - 4 tables to store users, sessions, user record and medications --- ![](https://i.imgur.com/5S4faCw.png) --- #### Add Medication :heavy_plus_sign: - Medication page in next which includes a component which submits a form containing the users information about their medication. - The forms submits to an api end point "update-medlist". - This performs a SQL query in the model file which adds the information into the elephant SQL DB and re-directs to the medication page. --- - Then we use server side props on the medication page to do another SQL query to get all medications from the DB and pass these down as props to insert the information into the components via a map to create `li`. - Learning: Keeping the form on one page to keep track of information, unsure about issue with crashing? :exploding_head: --- #### Delete Medication :negative_squared_cross_mark: - Inside of the mapped `li` we created a form ``` <form method="POST" action="/api/delete-med"> <input type="hidden" id="deleteInput" name="id" value={medication.id} /> <button type="submit">Delete Medication</button> ``` --- #### Continued... - send information to api end point. - calls SQL query in the model file to delete medication from the table and the page will re-render going through the same process as before with the removed medication. Issues: `error: update or delete on table "medications" violates foreign key constraint "record_med_id_fkey" on table "record"` --- #### Fix :sparkles: ![](https://i.imgur.com/Ao6pi5n.png) --- #### ON DELETE SET NULL * NO ACTION is assigned by default, PostgreSQL issues a constraint violation because the referencing rows of the customer id 1 still exist in the contacts table. * The `SET NULL` automatically sets NULL to the foreign key columns in the referencing rows of the child table when the referenced rows in the parent table are deleted.This is actioned on the `ON DELETE` clause: --- ### Auth 🔐 --- ### Goals 🎯 + Sign up - Add user to user table, hash password and issue sid cookie + Log in - issue sid cookie + Log out - delete session from db + Middleware - verify users and check for unauthenticated users + getUserInfo = use the cookie sid to look up the user_id and identify user + handling sign up and login errors --- #### Issues 🚨 + comparing hashed passwords directly in postgres 🙈 (bcrypt.compare() is the tool for the job!) + duplication of sid cookies occurred on failure to logout properly + --- #### Code example: cookies 🍪 We had cookie setting problems: ```js res.setHeader("set-cookie", `sid=${sid}; ${cookie_options}`); ``` Workaround was to use 'cookies' npm package: ``` npm install cookies import Cookies from "cookies"; const cookies = new Cookies(req, res); cookies.set("sid", ${sid}, { httpOnly: true, // true by default maxAge: cookie_options.maxAge,}); ``` --- #### Todo + Client side validation on form on login and sign-in inputs --- #### Heatmap plans :fire: - Record table will store a history of when meds were or weren't taken: `taken: true` - Shift from calendar :calendar: to heatmap :fire: - Clickable tiles :crossed_fingers: - Research spike planned as part of next sprint for node modules :thinking_face: --- #### In-app Notification and unfinished business... - Aim: render notification which lists that day's medication not yet taken - Set up db query to return records and converted SQL date into JS date ``` cleanRecord[ { id: 2, date: "Wed Mar 02", user_id: 1, med_id: 2, taken: false }, { id: 3, date: "Wed Mar 02", user_id: 1, med_id: 3, taken: false }, { id: 4, date: "Wed Mar 02", user_id: 1, med_id: 1, taken: false } ]; ``` --- - Once users record is returned need to use the `med_id` of each record to access the full medication details and render info on page - Initial approach promises and maps :dizzy_face: - Tried to map over array of cleanRecord and run db query for each `med_id` --- - Does not work as map is a synchronous, higher order function so does not wait for the db query to return, instead returns an empty array ``` javascript //cleanRecord is the array of records with the date cleaned const fullMedDetails = cleanRecord.map((record) => { const fullMedDetailsArray = []; //uses medication id to query db and return the full details for that med retrieveMedDetails(record.med_id).then((result) => { let medDetails = result; fullMedDetailsArray.push(medDetails); //51 logs the array with all the details successfully pushed console.log("51 full med details array", fullMedDetailsArray); }); //line 53 console log returning BEFORE line 51 console.log("53 full med details array", fullMedDetailsArray); return fullMedDetailsArray; }); ``` --- - Not yet resolved :thumbsdown: - refactoring and trying a new approach next week :thinking_face: - Possible approaches: - exploring async await with map - nested SQL queries *__To be continued....__* --- #### Group learnings :seedling: * Using elephant SQL, important to let your team know if your re-populating. * Never under-estimate authentication, and sometimes having a break of this is not a bad idea! --- * expected 18 * actual 18 --- ### DEMO https://be-kind-re-mind-ten.vercel.app/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully