Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions graphQl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
mutation loginUser{
userLogin(email:"[email protected]",password:"[email protected]")
}

mutation createUser{
userCreate(input:{name:"jo",email:"[email protected]",password:"[email protected]"}){
name
}
}

query getOnePost{
getOnePost(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e7849dbeadae4714950386"){
title
content
comments{
content
}
}
}

mutation createPost{
postCreate(title:"post created",content:"post created suceffully",token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE")
}

mutation updatePost{
updatePost(postId:"63e7849dbeadae4714950386",token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",title:"youssef saeed",content:"jo update post")
}

mutation deletePost{
deletePost(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e784a1beadae471495038c")
}

mutation createComment{
createComment(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e7849dbeadae4714950386",content:"try add comment")
}

query getOneComment{
getComment(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e7849dbeadae4714950386",commentId:"63e79fb808d94a4949ca0387"){
content,
postId{
title,
content
},
userId{
name
}
}
}

query getAllComment{
getAllComments(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e7849dbeadae4714950386"){
content,
postId{
title,
content
},
userId{
name
}
}
}

mutation upadateComment{
updateComment(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e7849dbeadae4714950386",commentId:"63e79d867c4f4614d165f8f5",content:"update comment youssef")
}

mutation deleteComment{
deleteComment(token:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2M2U3N2Q5N2Q0NmUxOWEzOTQ3ZWU4MzMiLCJpYXQiOjE2NzYxMTUzOTd9.e_afD0Z0ouEOrSqTk-7e20Fuh6Ig67A2b4bJ6LtZHVE",postId:"63e7849dbeadae4714950386",commentId:"63e7a29c1d5e81a507537cae")
}
36 changes: 17 additions & 19 deletions models/Comment.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
const mongoose = require('mongoose');

const mongoose = require("mongoose");

const { Schema } = mongoose;

const commentSchema = new Schema({
consent:{
type:String,
require:true
},
userId:{
type:Schema.Types.ObjectId,
ref:'User',
require:true
},
postId:{
type:Schema.Types.ObjectId,
ref:'Post',
require:true
}

content: {
type: String,
require: true,
},
userId: {
type: Schema.Types.ObjectId,
ref: "User",
require: true,
},
postId: {
type: Schema.Types.ObjectId,
ref: "Post",
require: true,
},
});
const Comment = mongoose.model('Comment',commentSchema);
module.exports = Comment;

module.exports = mongoose.model("Comment", commentSchema);
47 changes: 29 additions & 18 deletions models/Post.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
const mongoose = require('mongoose');

const mongoose = require("mongoose");

const { Schema } = mongoose;

const postSchema = new Schema({
title:{
type:String,
require:true
},
content:{
type:String,
require:true
},
userId:{
type:Schema.Types.ObjectId,
ref:'User'
}

const postSchema = new Schema(
{
title: {
type: String,
require: true,
},
content: {
type: String,
require: true,
},
userId: {
type: Schema.Types.ObjectId,
ref: "User",
},
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true },
}
);

postSchema.virtual("comments", {
ref: "Comment",
foreignField: "postId",
localField: "_id",
});
const Post = mongoose.model('Post',postSchema);
module.exports = Post;

const Post = mongoose.model("Post", postSchema);
module.exports = Post;
Loading