<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cory Allen</title>
    <description>The latest articles on DEV Community by Cory Allen (@constmedic).</description>
    <link>https://dev.to/constmedic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F918097%2F6a9bba14-06a4-4ced-a609-37d3f923b306.png</url>
      <title>DEV Community: Cory Allen</title>
      <link>https://dev.to/constmedic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/constmedic"/>
    <language>en</language>
    <item>
      <title>How to handle a Sequelize promise within a for loop?</title>
      <dc:creator>Cory Allen</dc:creator>
      <pubDate>Sat, 17 Sep 2022 01:48:30 +0000</pubDate>
      <link>https://dev.to/constmedic/how-to-handle-a-sequelize-promise-within-a-for-loop-4h4l</link>
      <guid>https://dev.to/constmedic/how-to-handle-a-sequelize-promise-within-a-for-loop-4h4l</guid>
      <description>&lt;p&gt;I am having trouble querying within Express with Sequelize. I am first querying all QuizAttempts by a user, and then I am querying Articles to refrence the article name to match it to the quiz attempt. (Joins are way over my head). My problem is, I am getting "null" returned when I console.log "Article Data".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.home = async (req, res) =&amp;gt; {

    const quizAttempts = await QuizAttempts.findAll({
        raw: true,
        where: {
            user_id: req.user.id
        }
    }).then(async (data) =&amp;gt; {
        for (let i = 0; i &amp;lt; data.length; i++) {
            const queryName = await Articles.findOne({
                raw: true,
                where: {
                    id: data[i].article_id
                }
            }).then((articleData) =&amp;gt; {
                console.log(articleData);
            })
        }
    })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I've been told to use &lt;code&gt;Promise.all()&lt;/code&gt; in this particular case but I am not fully understanding how I would do so while still retaining the value of &lt;code&gt;i&lt;/code&gt;. Any help is appreciated!&lt;/p&gt;

</description>
      <category>express</category>
      <category>sequelize</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Quick logic question... Express, Sequelize, &amp; Handlebars</title>
      <dc:creator>Cory Allen</dc:creator>
      <pubDate>Wed, 14 Sep 2022 23:07:24 +0000</pubDate>
      <link>https://dev.to/constmedic/quick-logic-question-express-sequelize-handlebars-55j6</link>
      <guid>https://dev.to/constmedic/quick-logic-question-express-sequelize-handlebars-55j6</guid>
      <description>&lt;p&gt;Having a tough time working out some logic. I don't know if it's because my brain is fried or what, but here is what I'm trying to do.&lt;/p&gt;

&lt;p&gt;I have a table named "Questions", this table contains questions over an article. Fields are as follows: id, article_is, questions, answer1, answer2, answer3, answer4, correct_answer, explanations.&lt;/p&gt;

&lt;p&gt;I would like to query 5 questions for the article and display them on the page obviously (this i can do). However, I am having "Writers block" persay with how to handle the form information with the Sequelize query. My query in my controller looks as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.article_review = (req, res) =&amp;gt; {
    Questions.findAll({
        limit: 5,
        where: {
            article_id: req.params.id
        },
        raw: true
    }).then(function(data) {

            res.render('article-review', {
                title: "Test your knowledge",
                questions: data,
                id: req.params.id
            })
    })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the life of me I cannot think of a way to appropriately process the form, compare each answer to each question to correct_answer, and display the results on the page. Any input would be great! Also, I'm sure the answer is simple, I've just been elbows deep in this project for 12+ hours a day for the last week.&lt;/p&gt;

</description>
      <category>nodej</category>
      <category>handlebarsjs</category>
      <category>sequelize</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Sequelize, Express.js, &amp; Handlebars.js being turds?</title>
      <dc:creator>Cory Allen</dc:creator>
      <pubDate>Tue, 13 Sep 2022 14:45:01 +0000</pubDate>
      <link>https://dev.to/constmedic/sequelize-expressjs-handlebarsjs-being-turds-20on</link>
      <guid>https://dev.to/constmedic/sequelize-expressjs-handlebarsjs-being-turds-20on</guid>
      <description>&lt;p&gt;My brain is sizzling, either I am overlooking a tiny detail or this is supposed to work and doesn't for whatever reason. Just trying to render by findAll() query to the page using handlebars. Here's what I have.&lt;/p&gt;

&lt;p&gt;Controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const library = require('../models/Library');
exports.manage_library = (req, res) =&amp;gt; {
    Library.findAll()
        .then(function(data) {
            res.render('manage-library', {
                title: "Manage Website",
                user: req.user,
                data: data
            })
        });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    {{#each data}}
                        &amp;lt;div class="list-group-item d-flex justify-content-between"&amp;gt;
                        &amp;lt;div&amp;gt;&amp;lt;strong&amp;gt;{{this.name}}&amp;lt;/strong&amp;gt;&amp;lt;/div&amp;gt;
                        &amp;lt;div&amp;gt;
                            &amp;lt;a href="/edit-category/{{this.id}}" class="btn btn-sm btn-warning"&amp;gt;&amp;lt;i class="bi bi-pencil"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/a&amp;gt;
                            &amp;lt;a href="/delete-category/{{this.id}}" class="btn btn-sm btn-danger"&amp;gt;&amp;lt;i class="bi bi-trash3"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/a&amp;gt;
                        &amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;
                    {{/each}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am new to Node &amp;amp; Express, this is my first serious project so forgive me if I am overlooking something minor. Basically, the above code renders the appripriate amount of &lt;code&gt;list-group-item&lt;/code&gt; but I cannot display actual data within the &lt;code&gt;list-group-item&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What the glorp am I doing wrong?! 👽&lt;/p&gt;

</description>
      <category>expresjs</category>
      <category>javascript</category>
      <category>question</category>
      <category>handlebarsjs</category>
    </item>
  </channel>
</rss>
