Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

like operator not works on return view #952

Closed
bashgaa opened this issue Oct 24, 2023 · 8 comments
Closed

like operator not works on return view #952

bashgaa opened this issue Oct 24, 2023 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@bashgaa
Copy link

bashgaa commented Oct 24, 2023

my login.ejs has

  <% license_users.forEach((user2) => { %>
<%= user2.license_key %>
  <% }) %>
    <script>
      $("#addUser_license").blur(function () {
        var myTxt = $(this).val();
        var formData = {
          "license_key": myTxt,
        };
        $.ajax({
          type: "POST",
          dataType: "JSON",
          url: "/license",
          data: formData,
        })
          .done(function (response) {
            console.log("Success: " + response.msg);
          })
          .fail(function (ts) {
            alert(ts.responseStatus);
          });
      });
    </script>

and my app.js has post method

fastify.post("/license", async (request, reply) => {
  const client = await fastify.pg.connect();
  const { license_key } = request.body;
  try {
    const result = await client.query(
      "SELECT * FROM license WHERE license_key LIKE $1",
      [license_key]
    );
    console.log(result.rows);
    console.log({ license_key });
    // Pass the search results to the EJS template
    return reply.view("/login.ejs", { license_users: result.rows });
  } catch (err) {
    console.error(err);
    return reply.view("error.ejs");
  } finally {
    client.release();
  }
});

when i write "good" on input form then in terminal window console.log(result.rows);
console.log({ license_key }); result is [ { id: 28, license_key: 'good' } ]
{ license_key: 'good' } but nothing to show in console window only "Error: undefined" occured in browser console window
i think return reply.view("/login.ejs", { license_users: result.rows }); not works. Input data not pass to login.ejs code

<% license_users.forEach((user2) => { %>
     <li><%= user2.license_key %></li>
     <% }) %>

maybe like operator not pass to template file.

@bashgaa bashgaa added the help wanted Extra attention is needed label Oct 24, 2023
@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@bashgaa
Copy link
Author

bashgaa commented Oct 25, 2023 via email

@bashgaa
Copy link
Author

bashgaa commented Nov 10, 2023

Any update of my project issue? Do you checked my github project?

@Uzlopak
Copy link

Uzlopak commented Nov 10, 2023

Your github repo was not useful. I would need to setup a postgresql server. So I stopped there.

@bashgaa
Copy link
Author

bashgaa commented Nov 10, 2023

If i use my database to supabase then no need install postgresql server. can you check my github repo if i setup supabase?

@Eomm
Copy link
Member

Eomm commented Nov 12, 2023

This is not minimal:

image

https://github.com/bashgaa/example_like_operator/blob/main/package.json#L21-L36
You are asking to debug your code.

We request minimal code because developers often identify the issue by replicating the code themselves. The most effective approach is to follow the "divide and conquer" strategy, where you break down the code into smaller pieces and examine them one by one until you locate the problem.
For example, if you remove the query and the server returns static data, does it work?
If it works, the issue is on the SQL query.
etc..

I would suggest starting from this comment: #952 (comment)
Did you ignore it?

That example in the readme works.
Then add postgres
Then add helmet
Then add ... you get the point...

@simoneb
Copy link

simoneb commented Jun 4, 2024

This issue can probably be closed

@jsumners jsumners closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants