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

no corresponding settings but (!mySettings) isn't truthy [1:32am] #209

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago
    userSettings: {
      type: SettingsType,
      description: 'Provide user as args and return corresponding prisma.settings data from psql db',
      args: {
        id: { type: GraphQLInt }
      }, 
      resolve: async ( parent, args ) => {
        // let predata = await fetch(`http://localhost:5000/fill_cont?query={userSettings(id:1){id,weight,height,age,reminder,start_time,end_time,reminder,activity,users_id}}`)
        let { id } = args        
        let allsettings = await prisma.settings.findMany()    
        let settingsLength = allsettings.length + 1
        let allusers = await prisma.users.findMany()
        let me = allusers.filter(us => us.id === id)
        let myage = me[0].age
        let mySettings = allsettings.filter(settings => settings.users_id === id)

          if (!mySettings) {
            return prisma.settings.create({
              data: {
                id: settingsLength,
                weight: 150,
                height: 75,
                age: myage,
                reminder: 4,
                start_time: 9,
                end_time: 5,
                activity: 1,
                users_id: id
              }
            }).then( (data) => {
              return { id, weight, height, age, start_time, end_time, reminder, activity, users_id } = data
            })
          } else {
👎                return { id, weight, height, age, start_time, end_time, reminder, activity, users_id } = mySettings[0]          
          }

      }   
    },

the else block somehow activates for an id of three, of which there is none in the database. 👎 return { id, weight, height, age, start_time, end_time, reminder, activity, users_id } = mySettings[0]

clientside invocation:

Screen Shot 2023-06-13 at 1 46 00 AM

psql table showing there isn't an id of 3 Screen Shot 2023-06-13 at 1 44 14 AM

frankcollins3 commented 1 year ago

👍 if (!mySettings.start_time) { 👍 if (!mySettings)

forgot to access the array index of the filter data let mySettings = allsettings.filter(settings => settings.users_id === id)

thought this worked but would return .create data: not the falsy block data which was the corresponding user data

[1:52am]