frankcollins3 / mine-nugget-ts

gold mine themed cannabis strain API (fixing deployment)
https://mine-nugget.vercel.app
2 stars 0 forks source link

data call works in prod but retrieves 4/7 strain data. env.dev same func retrieves all 7/7 data from db [12:17pm] #138

Open frankcollins3 opened 1 year ago

frankcollins3 commented 1 year ago

i show the terminal to show [npm run build && npm run start] is the code on localhost:3000:

                _in google chrome dev tools:_

1) localhost:3000: fetchstrains->getdata-> all 7 strains from database as objects in array 2) https://mine-nugget.vercel.app/ ^ same object endpoint path ^ 4/7 data strain objects from database.

https://user-images.githubusercontent.com/73137934/223182575-5f02759b-9c4b-41ed-98da-fc02eafef9c3.mp4

proposed solution: committ method invoking and route hitting ES6 function to have logs for the POST route to see if the discrepancy can be traced back to axios.POST and the ES6 class that invokes it

frankcollins3 commented 1 year ago
const createMany = await prisma.user.createMany({
  data: [
    { name: 'Bob', email: 'bob@prisma.io' },
    { name: 'Bobo', email: 'bob@prisma.io' }, // Duplicate unique key!
    { name: 'Yewande', email: 'yewande@prisma.io' },
    { name: 'Angelique', email: 'angelique@prisma.io' },
  ],
  skipDuplicates: true, // Skip 'Bobo'
})

This route is pretty much perfect example of why I wanted to structure the data in this app with: 1) api (that doesn't have int values like id or strainId) 2) data that does have those ints but doesn't have a few columns like: [ strain.taste | strain.smell ]

I did so strictly for the fun of it and to accept it as a little challenge.

For whatever reason, upon deployment, the post route is creating only 4 pieces of data: white widow, gorillaglue, wedding cake, and a duplicate white widow.

what I did to test if I could influence the data that appeared on the container was change: if (dbstrainlist < 3) --------> if (dbstrainlist < 7) I changed the limit in the loop from 3 to 7 which appended the same strains but with duplicates of everything

dbstrainlist = prisma.strains.findMany()

const createStrains = async () => {
          console.log('firing the createStrains function')
          **if (dbstrainlist.length < 7) {**                
          // if (dbstrainlist.length < 3) {                
          allstrainspost.map( (mapitem:any, index:number) => {
            let strainId:number = index + 1
            let strain:string = mapitem.strain
            let dominant:string = mapitem.dominant
            let parents:string = mapitem.parents
            let funfact:string = mapitem.funfact

           // checking dummy data first
            strains.create({
              data: {
                strainId: strainId,
                strain: strain,
                dominant: dominant,
                parents: parents,
                funfact: funfact
              }
            }).then( (createdstrains:any) => {                      
              res.json( { successObject: dbstrainlist, length: dbstrainlist.length})                   

part of this problem is that I had to get rid of doing data calls in Nexts native pre-build data functionality serversideProps I solved this problem by creating state that had dummy data in it, so that the child component that was waiting on the actual data from the data call could have some dummy data so there could be no definition errors from map trying to iiterate over something that had no values.

I also changed the strainnames to '-------' but this didn't change anything about how: gorilla glue, wedding cake, and whitewidow x 2 are created incorrectly but consistently.