hj yuiyui
12/22/2021, 10:28 AMmodel 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 Argument event_type for data.event_type is missing.
Argument event_value for data.event_value is missing. Any idea why ?Maciek K
12/22/2021, 10:37 AMconsole.log({event_type,event_value}), what does it give you?hj yuiyui
12/22/2021, 10:40 AMhj yuiyui
12/22/2021, 10:43 AMMaciek K
12/22/2021, 10:57 AMMaciek K
12/22/2021, 11:00 AMhj yuiyui
12/22/2021, 11:00 AMMaciek K
12/22/2021, 11:04 AMwebsite website @relation(fields: [website_id], references: [website_id])
Is this ok?
Can you share your website model?Maciek K
12/22/2021, 11:04 AM@id on website model called id or website_id?hj yuiyui
12/22/2021, 11:04 AMmodel 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")
}hj yuiyui
12/22/2021, 11:05 AMMaciek K
12/22/2021, 11:08 AMconst { id, event_type, event_value } = req.query;hj yuiyui
12/22/2021, 11:17 AMhj yuiyui
12/22/2021, 11:21 AMMaciek K
12/22/2021, 11:28 AMcreateEvent ?
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),
}
})
)hj yuiyui
12/22/2021, 11:31 AMexport 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)Maciek K
12/22/2021, 11:34 AMreturn to see how they look like. But if anything the ...data should be inside of data: {}hj yuiyui
12/22/2021, 11:42 AMMaciek K
12/22/2021, 11:46 AMwebsite_id looks like this: {event_value: "test_3", event_type: 'Click'} You should track that downMaciek K
12/22/2021, 11:47 AMconst events =... You're passing there the wrong datahj yuiyui
12/22/2021, 11:48 AMMaciek K
12/22/2021, 11:50 AMMaciek K
12/22/2021, 11:50 AMMaciek K
12/22/2021, 11:51 AMMaciek K
12/22/2021, 11:51 AMMaciek K
12/22/2021, 11:51 AMhj yuiyui
12/22/2021, 12:09 PMhj yuiyui
12/22/2021, 12:13 PMMaciek K
12/22/2021, 12:43 PMhj yuiyui
12/22/2021, 3:33 PM