'VueJS / Express with PRISMA ORM app based | Problem encountered while trying to post on VueJS side
i'm following a Web Developer formation and i would like to understand how to fix my actual problem. I'm creating a kind of social media where you can create your account and post publications with VueJS and Express (PRISMA ORM).
My schema.prisma file looks like this (database model) :
model users {
user_id Int @id @default(autoincrement()) @db.UnsignedInt
firstName String @db.VarChar(255)
lastName String @db.VarChar(255)
email String @unique(map: "email") @db.VarChar(255)
password String @db.VarChar(255)
createdAt DateTime @default(now())
isAdmin Boolean @default(false)
post post[]
comments comments[]
}
model post {
post_id Int @id @default(autoincrement()) @db.UnsignedInt
title String @db.VarChar(50)
content String @db.Text
author_id Int @db.UnsignedInt
users users @relation(fields: [author_id], references: [user_id])
comments comments[]
@@index([author_id], name: "FK1_AUTHORID")
}
And my error comes out while i run this in my VueJS view, i put in localStorage my token so i have every informations about the current user connected :
<script>
import axios from 'axios';
export default {
name: 'publish',
data: function () {
return {
title: '',
content: '',
users: {},
};
},
mounted() {
axios
.get("http://localhost:3000/auth/me", {
headers: {
Authorization: "Bearer " + localStorage.getItem('token')
}
})
.then(res => {
this.users = res.data;
console.log(res);
})
.catch(e => console.log(e));
},
methods: {
createPublication() {
axios
.post("http://localhost:3000/main", {
headers: {
Authorization: "Bearer " + localStorage.getItem('token')
},
title: this.title,
content: this.content,
})
.then(res => {
console.log(res);
this.$router.push('/groupomania');
})
.catch(err => {
console.log(err);
})
}
}
}
</script>
But when i try to run this post route with the current code, i come out with this error :
Argument users for data.users is missing.
Note: Lines with + are required, lines with ? are optional.
I'm not sure how to fix that anyone has an idea ?
Thanks a lot, have a great day
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
