Currently, I'm adding users and complaints straight to mongoDB collections, but need to make use of Mongoose and the MongoDB models I can create for each of those to actually utilize graphQL.
export const typeDefs = gql`
scalar Date
type User {
id: ID!
displayName: String!
authProvider: String!
email: String!
superuser: Boolean!
}
type Complaint {
userInfo: User! #! unsure about the type here
time: Date!
isAccepted: Boolean!
submissionCode: String!
additioanlNotes: String
title: String
rating: Int!
faultyLines: Array
}
type Query {
getUser: User
getComplaint: Complaint
}
`;
let res = await fetch("/api/complaintHandler", {
method: "POST",
body: JSON.stringify({
userInfo: user,
title: title,
submissionCode: submissionCode,
additionalNotes: additionalNotes,
rating: rating,
faultyLines: faultyLinesSelected,
time: new Date(),
isAccepted: false,
}),
});
After that fetch is called, it simply adds straight to a mongoDB collection like so:
const client = await clientPromise;
const db = client.db("Database");
switch (req.method) {
case "POST":
let bodyObject = JSON.parse(req.body);
let newComplaint = await db
.collection("RequestsAndResponses")
.insertOne(bodyObject);
res.json(newComplaint.ops[0]);