fastify / point-of-view

Template rendering plugin for Fastify
MIT License
335 stars 86 forks source link

Postgresql's like operator not works on return reply.view #399

Closed bashgaa closed 8 months ago

bashgaa commented 8 months ago

Prerequisites

Fastify version

4.24.3

Plugin version

No response

Node.js version

20.3

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

Windows 10

Description

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

maybe like operator not pass to template file.

authors not answered my question. They just closed issue. I don't understand. Why they ignored my request of issue. This is my most important project

Steps to Reproduce

i uploaded to github and respository is

https://github.com/bashgaa/example_like_operator

Expected Behavior

No response

Eomm commented 8 months ago

Closing as duplicate:

As said: more copy-paste issues = less answers

Consider to debug your issue: https://github.com/fastify/point-of-view/issues/397#issuecomment-1785190701