Delete Appointment works
This commit is contained in:
@@ -1,11 +1,28 @@
|
|||||||
import React from 'react';
|
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 { appointment } = props;
|
const { appointment } = props;
|
||||||
|
|
||||||
|
const [deleteAppointment] = useMutation(DELETE_APPOINTMENT_MUTATION, {
|
||||||
|
variables: { _id: appointment._id }
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(appointment._id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useQuery, gql } from '@apollo/client';
|
|||||||
export const APPOINTMENTS_QUERY = gql`
|
export const APPOINTMENTS_QUERY = gql`
|
||||||
{
|
{
|
||||||
allAppointments{
|
allAppointments{
|
||||||
|
_id
|
||||||
title
|
title
|
||||||
description
|
description
|
||||||
start
|
start
|
||||||
@@ -18,12 +19,11 @@ const AppointmentList = () => {
|
|||||||
const { data } = useQuery(APPOINTMENTS_QUERY);
|
const { data } = useQuery(APPOINTMENTS_QUERY);
|
||||||
|
|
||||||
if (data !== undefined) {
|
if (data !== undefined) {
|
||||||
console.log(data.allAppointments);
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
data.allAppointments.map((appointment) => (
|
data.allAppointments.map((appointment) => (
|
||||||
<Appointment key={appointment.id} appointment={appointment} />
|
<Appointment key={appointment._id} appointment={appointment} />
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"graphql-compose": "^7.23.0",
|
"graphql-compose": "^7.23.0",
|
||||||
"graphql-compose-connection": "^8.0.1",
|
"graphql-compose-connection": "^8.0.1",
|
||||||
"graphql-compose-mongoose": "^9.0.0",
|
"graphql-compose-mongoose": "^9.0.0",
|
||||||
|
"graphql-depth-limit": "^1.1.0",
|
||||||
"graphql-middleware": "^6.0.0",
|
"graphql-middleware": "^6.0.0",
|
||||||
"graphql-tools": "^7.0.2",
|
"graphql-tools": "^7.0.2",
|
||||||
"jsonwebtoken": "8.5.1",
|
"jsonwebtoken": "8.5.1",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import { graphqlHTTP } from 'express-graphql';
|
import { graphqlHTTP } from 'express-graphql';
|
||||||
|
import depthLimit from 'graphql-depth-limit'
|
||||||
import { ApolloServer, PubSub } from 'apollo-server-express';
|
import { ApolloServer, PubSub } from 'apollo-server-express';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import schema from './schema.js';
|
import schema from './schema.js';
|
||||||
@@ -26,6 +27,7 @@ app.use(cors());
|
|||||||
|
|
||||||
app.use('/djhb58fytkh476dk45yh49', graphqlHTTP({
|
app.use('/djhb58fytkh476dk45yh49', graphqlHTTP({
|
||||||
schema: schema,
|
schema: schema,
|
||||||
|
validationRules: [depthLimit(3)],
|
||||||
graphiql: true
|
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) {
|
async createAppointment(parent, args, context, info) {
|
||||||
return await Appointment.create(args);
|
return await Appointment.create(args);
|
||||||
},
|
},
|
||||||
async updateAppointment(root, {
|
async updateAppointment(parent, args, context, info) {
|
||||||
_id,
|
|
||||||
input
|
|
||||||
}) {
|
|
||||||
return await Appointment.findOneAndUpdate({
|
return await Appointment.findOneAndUpdate({
|
||||||
_id
|
args
|
||||||
}, input, {
|
}, args, {
|
||||||
new: true
|
new: true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async deleteAppointment(root, {
|
async deleteAppointment(parent, args, context, info) {
|
||||||
_id
|
console.log(args);
|
||||||
}) {
|
return await Appointment.deleteOne({ _id: args._id }).then(function () {
|
||||||
return await Product.findOneAndRemove({
|
console.log("Data deleted"); // Success
|
||||||
_id
|
}).catch(function (error) {
|
||||||
|
console.log(error); // Failure
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async createProduct(root, {
|
async createProduct(root, {
|
||||||
|
|||||||
@@ -24,11 +24,12 @@ type Mutation {
|
|||||||
description: String!
|
description: String!
|
||||||
start: String!
|
start: String!
|
||||||
end: String!
|
end: String!
|
||||||
# input: AppointmentInput
|
|
||||||
): Appointment!
|
): Appointment!
|
||||||
updateAppointment(
|
updateAppointment(
|
||||||
_id: ID!,
|
_id: ID!,
|
||||||
input: AppointmentInput
|
title: String!
|
||||||
|
description: String!
|
||||||
|
start: String!
|
||||||
): Appointment
|
): Appointment
|
||||||
deleteAppointment(
|
deleteAppointment(
|
||||||
_id: ID!
|
_id: ID!
|
||||||
|
|||||||
Reference in New Issue
Block a user