fastify / point-of-view

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

Like operator not works on return reply.view #397

Closed bashgaa closed 9 months ago

bashgaa commented 9 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

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

maybe like operator not pass to template file.

Steps to Reproduce

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.

Expected Behavior

No response

Uzlopak commented 9 months ago

Closing this because I moved the other issue in fastify core to fastify/help.

Also an issue in fastify/core was already closed by @jsumners

bashgaa commented 9 months ago

hello sorry again

i uploaded to github and respository is

https://github.com/bashgaa/example_like_operator

bashgaa commented 9 months ago

pls check this my project section

bashgaa commented 9 months ago

hello sorry again

i uploaded to github and respository is

https://github.com/bashgaa/example_like_operator

On Wed, Oct 25, 2023 at 3:36 PM Aras Abbasi @.***> wrote:

Closed #397 https://github.com/fastify/point-of-view/issues/397 as completed.

— Reply to this email directly, view it on GitHub https://github.com/fastify/point-of-view/issues/397#event-10763416503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKJFBLCEK3U5KBOSQOD4AG3YBC6QRAVCNFSM6AAAAAA6OULG2KVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJQG43DGNBRGY2TAMY . You are receiving this because you authored the thread.Message ID: @.***>

bashgaa commented 8 months ago

Anyone authors see my project?

Eomm commented 8 months ago

Don't be pushy This issue duplicates: https://github.com/fastify/help/issues/952

Whenever someone will have time, will take a look. More issue you open, less answers you will get.

Right now I would suggest you to divide your issue in smaller problems:

  1. remove postgres
  2. return static fake data: return reply.view("/login.ejs", { license_users: [STATIC DATA] });
  3. does it work?
  4. if it works the issue is on postgres
  5. otherwise remove another piece of code till you find the issue
  6. etc...
bashgaa commented 8 months ago

return static fake data: return reply.view("/login.ejs", { license_users: [STATIC DATA] }); still get undefined error