Some cleaning
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useHistory } from 'react-router';
|
// import { useHistory } from 'react-router';
|
||||||
import { Link, withRouter } from 'react-router-dom';
|
import { Link, withRouter } from 'react-router-dom';
|
||||||
import { AUTH_TOKEN } from '../../constants';
|
// import { AUTH_TOKEN } from '../../constants';
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
const history = useHistory();
|
// const history = useHistory();
|
||||||
const authToken = localStorage.getItem(AUTH_TOKEN);
|
// const authToken = localStorage.getItem(AUTH_TOKEN);
|
||||||
return (
|
return (
|
||||||
<div className="flex pa1 justify-between nowrap orange">
|
<div className="flex pa1 justify-between nowrap orange">
|
||||||
<div className="flex flex-fixed black">
|
<div className="flex flex-fixed black">
|
||||||
@@ -17,7 +17,7 @@ const Header = () => {
|
|||||||
<div className="flex flex-fixed">
|
<div className="flex flex-fixed">
|
||||||
<Link to="/create" className="ml1 no-underline black">New</Link>
|
<Link to="/create" className="ml1 no-underline black">New</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-fixed">
|
{/* <div className="flex flex-fixed">
|
||||||
{authToken ? (
|
{authToken ? (
|
||||||
<div className="ml1 pointer black"
|
<div className="ml1 pointer black"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -28,7 +28,7 @@ const Header = () => {
|
|||||||
) : (
|
) : (
|
||||||
<Link to="/login" className="ml1 no-underline black">Login</Link>
|
<Link to="/login" className="ml1 no-underline black">Login</Link>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div> */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from '@apollo/client';
|
} from '@apollo/client';
|
||||||
|
|
||||||
const httpLink = createHttpLink({
|
const httpLink = createHttpLink({
|
||||||
uri: 'http://localhost:4000/djhb58fytkh476dk45yh49'
|
uri: 'http://localhost:4000/graphql'
|
||||||
});
|
});
|
||||||
|
|
||||||
const authLink = setContext((_, { headers }) => {
|
const authLink = setContext((_, { headers }) => {
|
||||||
|
|||||||
@@ -9,11 +9,15 @@ import './utils/db.js';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
// import getUserId from './utils';
|
|
||||||
|
|
||||||
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
const APP_SECRET = 'GraphQL-is-aw3some';
|
const APP_SECRET = 'GraphQL-is-aw3some';
|
||||||
|
const moduleURL = new URL(import.meta.url);
|
||||||
|
const __dirname = path.dirname(moduleURL.pathname);
|
||||||
|
const app = express();
|
||||||
|
const pubsub = new PubSub();
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
function getTokenPayload(token) {
|
function getTokenPayload(token) {
|
||||||
return jwt.verify(token, APP_SECRET);
|
return jwt.verify(token, APP_SECRET);
|
||||||
@@ -38,19 +42,10 @@ function getUserId(req, authToken) {
|
|||||||
throw new Error('Not authenticated');
|
throw new Error('Not authenticated');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const moduleURL = new URL(import.meta.url);
|
|
||||||
const __dirname = path.dirname(moduleURL.pathname);
|
|
||||||
const app = express();
|
|
||||||
const pubsub = new PubSub();
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
app.use('/djhb58fytkh476dk45yh49', graphqlHTTP({
|
app.use('/graphql', graphqlHTTP({
|
||||||
schema: schema,
|
schema,
|
||||||
validationRules: [depthLimit(3)],
|
validationRules: [depthLimit(3)],
|
||||||
graphiql: true
|
graphiql: true
|
||||||
}));
|
}));
|
||||||
@@ -121,8 +116,7 @@ server.applyMiddleware({
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.listen({ port: process.env.PORT }, () => {
|
app.listen({ port: process.env.PORT }, () => {
|
||||||
console.log(`🚀 Server listening on port ${process.env.PORT}`);
|
console.log(`Server listening on port ${process.env.PORT}`);
|
||||||
console.log(`😷 Health checks available at ${process.env.HEALTH_ENDPOINT}`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
// import Appointment from '../../client/src/components/Appointment.js';
|
|
||||||
import Appointment from './models/appointment.js';
|
import Appointment from './models/appointment.js';
|
||||||
import User from './models/user.js'
|
import User from './models/user.js'
|
||||||
// import { createAppointment } from './resolvers/Mutation.js';
|
|
||||||
import bcrypt from 'bcrypt';
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import dotenv from 'dotenv';
|
|
||||||
|
|
||||||
export const resolvers = {
|
export const resolvers = {
|
||||||
Query: {
|
Query: {
|
||||||
async allAppointments() {
|
async allAppointments() {
|
||||||
return await Appointment.find({ deleted: false })
|
return await Appointment.find({ deleted: false });
|
||||||
// return await Appointment.find();
|
|
||||||
},
|
},
|
||||||
async oneAppointment(root, args, context, info) {
|
async oneAppointment(root, args) {
|
||||||
return await Appointment.findOne({
|
return await Appointment.findOne({
|
||||||
_id: args._id
|
_id: args._id
|
||||||
});
|
});
|
||||||
@@ -22,8 +17,8 @@ export const resolvers = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
async signup(root, args, context, info) {
|
async signup(root, args) {
|
||||||
var user = await User.create(args);
|
const user = await User.create(args);
|
||||||
user.password = user.generateHash(args.password);
|
user.password = user.generateHash(args.password);
|
||||||
user.save();
|
user.save();
|
||||||
|
|
||||||
@@ -35,7 +30,7 @@ export const resolvers = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async login(parent, args, context, info) {
|
async login(parent, args, context) {
|
||||||
console.log(context);
|
console.log(context);
|
||||||
const { userId } = context;
|
const { userId } = context;
|
||||||
console.log(userId);
|
console.log(userId);
|
||||||
@@ -59,7 +54,7 @@ export const resolvers = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async createAppointment(parent, args, context, info) {
|
async createAppointment(parent, args, context) {
|
||||||
console.log(context);
|
console.log(context);
|
||||||
const { userId } = context;
|
const { userId } = context;
|
||||||
console.log("userID", userId);
|
console.log("userID", userId);
|
||||||
@@ -67,7 +62,7 @@ export const resolvers = {
|
|||||||
args.createdBy = userId;
|
args.createdBy = userId;
|
||||||
return await Appointment.create(args);
|
return await Appointment.create(args);
|
||||||
},
|
},
|
||||||
async updateAppointment(parent, args, context, info) {
|
async updateAppointment(parent, args) {
|
||||||
console.log(args);
|
console.log(args);
|
||||||
return await Appointment.findOneAndUpdate({
|
return await Appointment.findOneAndUpdate({
|
||||||
args
|
args
|
||||||
|
|||||||
Reference in New Issue
Block a user