codeforsanjose / project-happening-atm

Agenda notifications for local government meetings
GNU General Public License v3.0
14 stars 15 forks source link

`createMeeting` is storing wrong created_timestamp and created_timestamp timestamps in database #144

Closed sent-hil closed 3 years ago

sent-hil commented 3 years ago

I think it's a problem converting from JS time to Postgres time type.

Call this from ui

mutation {
  createMeeting(
    meeting_start_timestamp: "1616820800000",
    meeting_type: "test",
    status: "PENDING",
    virtual_meeting_url: "https://sanjoseca.zoom.us/j/91325378626"
  ){
    id,
    status,
    meeting_start_timestamp,
  }
}

And Then:

{
  getAllMeetings {
    id
    created_timestamp
    updated_timestamp
  }
}

created_timestamp and updated_timestamp should return time from few seconds ago, but will return wrong dasta.

anna-kartynnik commented 3 years ago

I've checked the code that inserts a meeting to the db, in particular https://github.com/codeforsanjose/gov-agenda-notifier/blob/71685429c028585727398025fcdf1dc594111507/backend/graphql_api/lambda/db/dbClient.js#L48-L58

Here we use Date.now() which returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. But PG function to_timestamp expects seconds, it seems. Quote from the docs:

A single-argument to_timestamp function is also available; it accepts a double precision argument and converts from Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp with time zone. (Integer Unix epochs are implicitly cast to double precision.)

sent-hil commented 3 years ago

@anna-kartynnik so that must be the problem! I will fix it when I get a chance or since you already did most of the work feel free to change it as part of your PR.