Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

Weird If/Else Problem with Javascript & Express

I'm having a problem checking if a object is undefined or not. Weirdly, this error doesn't occur in Mac OSX but on Windows I get a "cannot read property of to_char" error. Hoping you folks can help me!

Here is the code:

let accountInfo = {};
let recentForms = {}

  db.tx(async (t) => {
    accountInfo = await t.one(
      "SELECT * from useraccount INNER JOIN company on useraccount.company_id = company.id WHERE username = $1",
    recentForms = await t.any(
      "SELECT f.form_id, TO_CHAR(f.date_submitted :: DATE,'yyyy-mm-dd'), f2.form_name from formresponse f INNER JOIN forms f2 on f.form_id = f2.form_id WHERE f.company_id = $1",
    return accountInfo, recentForms;
    .then((data) => {
      // We need to compare the form submitted date to our date today to determine if completed.
      // First we need to see if to_char exists and then decalre the forms date as a date variable
      if (recentForms[0].to_char !== undefined){
        formDate = new Date(recentForms[0].to_char);
        formDate = '2120-01-12' 

Basically, if pg-promise returns something for recentForms[0].to_char, i want to turn it into a javascript date variable. If there's nothing, I want to set formDate as a far in the future variable. I can't get the program to execute that if statement though, atleast on Windows.

Appreciate any help!

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share