frankcollins3 / fill_container

codecamp team project updated with new icon screen menu + puppeteer icon search, GraphQL, redux, relational psql !mongo, and accuweatherAPI
1 stars 0 forks source link

9 || '9', doesnt register as the id when before it has been [2:02pm] #255

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: nothing, installed webpack. now intending to make database tables worked as they did before.

error: data. has been uploading Screen Shot 2023-07-01 at 2 00 14 PM

proposed approach: something wrong obv. might restart tables

the big problem is everything this functionality is trying to do has been providing daily data with which to work.

GraphQL query hardcoding a 9 which is the next ID also confirmed by psql shell isnt working. this query has been working

  getDailyData: {
    type: DataType,
    description: 'Daily Data for Water Intake',
    args: {
      users_id: { type: GraphQLInt },
    },
    resolve: async (parent, args) => {
    // let predata = await fetch(`http://localhost:5000/fill_cont?query={getDailyData(users_id:3){google_id,date,progress,weekday,status,users_id}}`)
        const { users_id } = args
        const allusers = await allusersDB()
        const alldata = await alldataDB()
        const dataLength = alldata.length
        let me = allusers.filter(users => users.id === users_id)
        const date = new Date()
        const dayName = date.toLocaleDateString('en-US', { weekday: 'long' } )
        const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`        
        const dateAndUserCheck = alldata.find(data => data.date === dateString && data.users_id === users_id)
        if (dateAndUserCheck) {
          // Data already exists for the given date and user
          return dateAndUserCheck;
        }

        if (!me) return
        return newDailyDate = prisma.data.create({
          data: {
            id: dataLength + 1,
            google_id: me.google_id || 'no google-id',
            date: dateString,
            progress: 0,
            weekday: dayName,
            status: [],
            users_id: users_id
          }
        }).then( (newdate) => {
          let d = newdate;
          return { id: d.id, google_id: d.google_id, date: d.date, progress: d.progress, weekday: d.weekday, status: d.status, users_id: d.users_id }
          // return { id, google_id, date, progress, weekday, status, users_id}
        })
    }
  },

actual psql shell data from the app. id | google_id | date | progress | weekday | status | users_id ----+--------------+---------------------+----------+-----------+-----------------------------------+---------- 4 | no google-id | 2023-6-20 | 100 | Tuesday | {"check,check,check,check,check"} | 3 5 | no google-id | 2023-6-21 | 0 | Wednesday | {} | 3 3 | no google-id | 2023-6-19 | 100 | Monday | {"check,check,check,check,check"} | 3 6 | no google-id | 2023-6-28 | 0 | Wednesday | {} | 3 7 | no google-id | 2023-6-29 | 0 | Thursday | {} | 3 8 | no google-id | 2023-6-30 | 0 | Friday | {} | 3 1 | | 2023-01-25 00:00:00 | 10 | thursday | {nope,nope,nope,nope,nope} | 1 2 | | 2023-04-01 00:00:00 | 10 | monday | {"nope,nope,nope,nope,check"} | 2

frankcollins3 commented 1 year ago

the issue can be more clearly seen here: fill_cont=# INSERT INTO data (id, google_id, date, progress, weekday, status, users_id) fill_cont-# VALUES (9, 'no google-id', '2023-7-01', 0, 'Saturday', '{}', 3); ERROR: insert or update on table "data" violates foreign key constraint "data_id_fkey" DETAIL: Key (id)=(9) is not present in table "users". fill_cont=#

compiler && db is expecting the link to be between data.users_id and users.id but it is set up to be: data.id === users.id (which we don't want)

/prisma/prisma.schema model data { id Int @id @default(autoincrement()) users users @relation(fields: [id], references: [id]) google_id String? date String? progress Int weekday String? status String[] users_id Int }

model users { id Int @id @default(autoincrement()) google_id String? icon String? username String? email String? password String? age Int? settings settings[] data data[] }

users users @relation(fields: [id], references: [id])

frankcollins3 commented 1 year ago

parcel > webpack for now [2:12pm]