Delete Appointment works
This commit is contained in:
@@ -1,11 +1,28 @@
|
||||
import React from 'react';
|
||||
import { useMutation, gql } from '@apollo/client';
|
||||
|
||||
const DELETE_APPOINTMENT_MUTATION = gql`
|
||||
mutation DeleteAppointmentMutation($_id: ID!) {
|
||||
deleteAppointment(_id: $_id){
|
||||
_id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
const Appointment = (props) => {
|
||||
const { appointment } = props;
|
||||
|
||||
const [deleteAppointment] = useMutation(DELETE_APPOINTMENT_MUTATION, {
|
||||
variables: { _id: appointment._id }
|
||||
})
|
||||
|
||||
console.log(appointment._id);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<b>{appointment.title}</b> starts at {appointment.start}, ends at {appointment.end}. It is described as "{appointment.description}"
|
||||
<b><div className="ml1 gray f11" style={{ cursor: 'pointer' }} onClick={deleteAppointment}>[X]</div>{appointment.title}</b> starts at {appointment.start}, ends at {appointment.end}. It is described as "{appointment.description}"
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useQuery, gql } from '@apollo/client';
|
||||
export const APPOINTMENTS_QUERY = gql`
|
||||
{
|
||||
allAppointments{
|
||||
_id
|
||||
title
|
||||
description
|
||||
start
|
||||
@@ -18,12 +19,11 @@ const AppointmentList = () => {
|
||||
const { data } = useQuery(APPOINTMENTS_QUERY);
|
||||
|
||||
if (data !== undefined) {
|
||||
console.log(data.allAppointments);
|
||||
return (
|
||||
<div>
|
||||
{
|
||||
data.allAppointments.map((appointment) => (
|
||||
<Appointment key={appointment.id} appointment={appointment} />
|
||||
<Appointment key={appointment._id} appointment={appointment} />
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"graphql-compose": "^7.23.0",
|
||||
"graphql-compose-connection": "^8.0.1",
|
||||
"graphql-compose-mongoose": "^9.0.0",
|
||||
"graphql-depth-limit": "^1.1.0",
|
||||
"graphql-middleware": "^6.0.0",
|
||||
"graphql-tools": "^7.0.2",
|
||||
"jsonwebtoken": "8.5.1",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import express from 'express';
|
||||
import dotenv from 'dotenv';
|
||||
import { graphqlHTTP } from 'express-graphql';
|
||||
import depthLimit from 'graphql-depth-limit'
|
||||
import { ApolloServer, PubSub } from 'apollo-server-express';
|
||||
import mongoose from 'mongoose';
|
||||
import schema from './schema.js';
|
||||
@@ -26,6 +27,7 @@ app.use(cors());
|
||||
|
||||
app.use('/djhb58fytkh476dk45yh49', graphqlHTTP({
|
||||
schema: schema,
|
||||
validationRules: [depthLimit(3)],
|
||||
graphiql: true
|
||||
}));
|
||||
|
||||
|
||||
@@ -66,55 +66,22 @@ export const resolvers = {
|
||||
};
|
||||
},
|
||||
|
||||
// async login(parent, args, context, info) {
|
||||
// console.log(args);
|
||||
// const user = await User.findOne({
|
||||
// email: args.email
|
||||
// });
|
||||
|
||||
// if (!user) {
|
||||
// throw new Error('No such user found');
|
||||
// }
|
||||
|
||||
// const pwd = await bcrypt.hash(args.password, 10);
|
||||
// console.log(pwd);
|
||||
// console.log(args.password)
|
||||
// console.log(user.password);
|
||||
|
||||
// const valid = await bcrypt.compare(
|
||||
// args.password,
|
||||
// user.password
|
||||
// );
|
||||
// if (!valid) {
|
||||
// throw new Error('Invalid password');
|
||||
// }
|
||||
|
||||
// const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET);
|
||||
|
||||
// return {
|
||||
// token,
|
||||
// user
|
||||
// };
|
||||
// },
|
||||
|
||||
async createAppointment(parent, args, context, info) {
|
||||
return await Appointment.create(args);
|
||||
},
|
||||
async updateAppointment(root, {
|
||||
_id,
|
||||
input
|
||||
}) {
|
||||
async updateAppointment(parent, args, context, info) {
|
||||
return await Appointment.findOneAndUpdate({
|
||||
_id
|
||||
}, input, {
|
||||
args
|
||||
}, args, {
|
||||
new: true
|
||||
})
|
||||
},
|
||||
async deleteAppointment(root, {
|
||||
_id
|
||||
}) {
|
||||
return await Product.findOneAndRemove({
|
||||
_id
|
||||
async deleteAppointment(parent, args, context, info) {
|
||||
console.log(args);
|
||||
return await Appointment.deleteOne({ _id: args._id }).then(function () {
|
||||
console.log("Data deleted"); // Success
|
||||
}).catch(function (error) {
|
||||
console.log(error); // Failure
|
||||
});
|
||||
},
|
||||
async createProduct(root, {
|
||||
|
||||
@@ -24,11 +24,12 @@ type Mutation {
|
||||
description: String!
|
||||
start: String!
|
||||
end: String!
|
||||
# input: AppointmentInput
|
||||
): Appointment!
|
||||
updateAppointment(
|
||||
_id: ID!,
|
||||
input: AppointmentInput
|
||||
title: String!
|
||||
description: String!
|
||||
start: String!
|
||||
): Appointment
|
||||
deleteAppointment(
|
||||
_id: ID!
|
||||
|
||||
Reference in New Issue
Block a user