Hi guys i have this `model groupevent{` `groupe...
# orm-help
h
Hi guys i have this
model groupevent{
groupevent_id  Int  @id @default(autoincrement())
website_id Int
created_at DateTime? @default(now()) @db.Timestamptz(6)
event_type  String   @db.VarChar(50)
event_value String   @db.VarChar(50)
website     website  @relation(fields: [website_id], references: [website_id])
event event?
}
and this query to create a new record
export async function createEvent(website_id, event_type, event_value) {
return runQuery(
prisma.groupevent.create({
data : {
website:{connect: {website_id: website_id}},
event_type: event_type?.substr(0, 50),
event_value: event_value?.substr(0, 50),
}
})
)
}
and this is my post route if
(req.method === 'POST') {
if (!(await allowQuery(req))) {
return unauthorized(res);
}
const { id, event_type, event_value } = req.query;
const websiteId = +id;
const events = await createEvent(websiteId,event_value, event_type);
return ok(res, events);
}
and this how i call my post route on my front end
const onSubmit = (dataForm: IFormValues) => {
const idStr: string = idWebsite.toString();
const data = {
id: idWebsite,
event_type : dataForm.event_type,
event_value: dataForm.event_value
};
const url: string = window.apiUrl;
`post(
${url}/api/website/${idStr}/events
, data)(didnt paste the following, its useless)` and when i try to post i get this PRISMA error on my server log
Copy code
Argument event_type for data.event_type is missing.
Argument event_value for data.event_value is missing.
Any idea why ?
m
When you
console.log({event_type,event_value})
, what does it give you?
h
Ok i'll check, btw this is my header value when i submit
Oh i rebuild my docker next js server and now i got this
m
So somehow you're not passing those values from the Form or whatever that is. You would need to trace it down. Maybe they're lost in the post request.
That is one thing. The second is you're passing the whole data object (with event_type and event_value) into the website_id. You should fix that also.
h
wdym by "into the website_id" ?
m
website     website  @relation(fields: [website_id], references: [website_id])
Is this ok? Can you share your website model?
Is the
@id
on website model called
id
or
website_id
?
h
model website {
website_id   Int        @id @default(autoincrement())
website_uuid String     @unique @db.Uuid
user_id      Int
name         String     @db.VarChar(100)
domain       String?    @db.VarChar(500)
share_id     String?    @unique @db.VarChar(64)
created_at   DateTime?  @default(now()) @db.Timestamptz(6)
account      account    @relation(fields: [user_id], references: [user_id])
event        event[]
pageview     pageview[]
session      session[]
groupevent  groupevent[]
@@index([user_id], name: "website_user_id_idx")
}
so a website can have multiple groupevent
m
When you console log those desctructed variables from res.query what does it give you?
const { id, event_type, event_value } = req.query;
h
Here, i changed something too
nvm here is the correct version
m
Are you sure you're actually running this query, and maybe by any chance you're running different
createEvent
? Sorry it's very hard to debug this dry. I would console.log those values right before the
return
export async function createEvent(website_id, event_type, event_value) {
return runQuery(
prisma.groupevent.create({
data : {
website:{connect: {website_id: website_id}},
event_type: event_type?.substr(0, 50),
event_value: event_value?.substr(0, 50),
}
})
)
h
I'm running the correct one (there is only one anyway) i changed the query by this maybe its better ?
export async function createEvent(website_id, data) {
 
return runQuery(
   
prisma.groupevent.create({
     
data : {
       
website:{connect: {website_id: website_id}},
     
},
     
...data
   
})
 
)
}
I'll test the old one (one you posted with console.log)
m
Please console.log those values before the
return
to see how they look like. But if anything the
...data
should be inside of
data: {}
h
Got this
m
Do you see now? Somehow your
website_id
looks like this:
{event_value: "test_3", event_type: 'Click'}
You should track that down
probably the call
const events  =...
You're passing there the wrong data
h
Well this my call, how can you say that my website_id looke like {event_value: "test_3", event_type: 'Click'} ? Its normal no ?
m
Thats what your console.log says
Oh sorry
I mean
event_type looks like that
and event_value is undefined
h
I changed the whole thing and this my "final structure"
is it because of my createEvent post request ?
m
I don't know. Console.log them on each step to see where you 'lose' them.
h
Ok fixed my problem it was a retarded one
😄 1