Changes
This commit is contained in:
@@ -5,6 +5,7 @@ import AppointmentList from './appointment/AppointmentList';
|
||||
import CreateAppointment from './appointment/CreateAppointment';
|
||||
import UpdateAppointemnt from './appointment/UpdateAppointment';
|
||||
import Calendar from './Calendar';
|
||||
import Search from './Search';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
|
||||
const App = () => {
|
||||
@@ -18,6 +19,7 @@ const App = () => {
|
||||
<Route exact path="/update/:_id" component={UpdateAppointemnt} />
|
||||
<Route exact path="/login" component={Login} />
|
||||
<Route exact path="/calendar" component={Calendar} />
|
||||
<Route exact path="/search" component={Search} />
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,63 +1,39 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useMutation } from '@apollo/client';
|
||||
import { useLazyQuery } from '@apollo/client';
|
||||
import gql from 'graphql-tag';
|
||||
import Appointment from './Appointment';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Appointment from './appointment/Appointment';
|
||||
|
||||
const FEED_SEARCH_QUERY = gql`
|
||||
query FeedSearchQuery($filter: String!) {
|
||||
feed(filter: $filter) {
|
||||
id
|
||||
links {
|
||||
id
|
||||
appointments {
|
||||
_id
|
||||
title
|
||||
description
|
||||
type
|
||||
createdBy {
|
||||
id
|
||||
username
|
||||
}
|
||||
# follows {
|
||||
# id
|
||||
# user {
|
||||
# id
|
||||
# }
|
||||
# }
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const Search = () => {
|
||||
const [searchFilter, setSearchFilter] = useState('');
|
||||
const [executeSearch, { data }] = useLazyQuery(
|
||||
FEED_SEARCH_QUERY
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
Search
|
||||
<input
|
||||
type="text"
|
||||
onChange={(e) => setSearchFilter(e.target.value)}
|
||||
/>
|
||||
<button
|
||||
onClick={() =>
|
||||
executeSearch({
|
||||
variables: { filter: searchFilter }
|
||||
})
|
||||
}
|
||||
>
|
||||
OK
|
||||
</button>
|
||||
</div>
|
||||
{/* {data &&
|
||||
data.feed.appointments.map((appointment, index) => (
|
||||
<Link key={appointment.id} link={appointment} index={index} />
|
||||
))} */}
|
||||
</>
|
||||
);
|
||||
const [searchFilter, setSearchFilter] = useState('');
|
||||
const [executeSearch, { data }] = useLazyQuery(
|
||||
FEED_SEARCH_QUERY
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
Search
|
||||
<input type="text" onChange={(e) => setSearchFilter(e.target.value)}/>
|
||||
<button onClick={() => executeSearch({ variables: { filter: searchFilter } })}>OK</button>
|
||||
</div>
|
||||
{data &&
|
||||
data.feed.appointments.map((appointment, index) => (
|
||||
<Appointment key={appointment.id} appointment={appointment} index={index} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Search;
|
||||
@@ -21,10 +21,10 @@ const Appointment = (props) => {
|
||||
onCompleted: () => history.push('/')
|
||||
})
|
||||
|
||||
// const updateAppointment = () => {
|
||||
// let path = `/update/${appointment._id}`;
|
||||
// history.push(path);
|
||||
// }
|
||||
const updateAppointment = () => {
|
||||
let path = `/update/${appointment._id}`;
|
||||
history.push(path);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useHistory } from 'react-router';
|
||||
import { useMutation, gql, useQuery } from '@apollo/client';
|
||||
import { APPOINTMENTS_PER_PAGE } from '../../constants';
|
||||
import { APPOINTMENTS_QUERY } from './AppointmentList';
|
||||
// import { APPOINTMENTS_PER_PAGE } from '../../constants';
|
||||
// import { APPOINTMENTS_QUERY } from './AppointmentList';
|
||||
import Datetime from 'react-datetime';
|
||||
import "react-datetime/css/react-datetime.css";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
// import { useHistory } from 'react-router';
|
||||
import { Link, withRouter } from 'react-router-dom';
|
||||
import { Link } from 'react-router-dom';
|
||||
// import { AUTH_TOKEN } from '../../constants';
|
||||
|
||||
const Header = () => {
|
||||
@@ -17,6 +17,9 @@ const Header = () => {
|
||||
<div className="flex flex-fixed">
|
||||
<Link to="/create" className="ml1 no-underline black">New</Link>
|
||||
</div>
|
||||
{/* <div className="flex flex-fixed">
|
||||
<Link to="/search" className="ml1 no-underline black">Search</Link>
|
||||
</div> */}
|
||||
{/* <div className="flex flex-fixed">
|
||||
{authToken ? (
|
||||
<div className="ml1 pointer black"
|
||||
|
||||
@@ -10,8 +10,8 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import cors from 'cors';
|
||||
import jwt from 'jsonwebtoken';
|
||||
const { APP_SECRET } = require('../utils');
|
||||
|
||||
const APP_SECRET = 'GraphQL-is-aw3some';
|
||||
const moduleURL = new URL(import.meta.url);
|
||||
const __dirname = path.dirname(moduleURL.pathname);
|
||||
const app = express();
|
||||
@@ -76,7 +76,7 @@ const server = new ApolloServer({
|
||||
req && req.headers.authorization
|
||||
? getUserId(req)
|
||||
: null
|
||||
}
|
||||
};
|
||||
},
|
||||
// subscriptions: {
|
||||
// onConnect: (connectionParams) => {
|
||||
|
||||
@@ -24,6 +24,11 @@ const AppointmentSchema = new Schema({
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
},
|
||||
user: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: "user",
|
||||
required: false
|
||||
}
|
||||
});
|
||||
export default mongoose.model('appointment', AppointmentSchema);
|
||||
@@ -1,5 +1,5 @@
|
||||
import Appointment from './models/appointment.js';
|
||||
import User from './models/user.js'
|
||||
import User from './models/user.js';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
export const resolvers = {
|
||||
|
||||
@@ -2,7 +2,7 @@ const bcrypt = require('bcryptjs');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { APP_SECRET } = require('../utils');
|
||||
|
||||
function createAppointment(parent, args, context, info) {
|
||||
function createAppointment(parent, args, context) {
|
||||
const { userId } = context;
|
||||
|
||||
const newAppointment = context.mongo.appointment.create({
|
||||
@@ -16,7 +16,7 @@ function createAppointment(parent, args, context, info) {
|
||||
return newAppointment;
|
||||
}
|
||||
|
||||
async function signup(parent, args, context, info) {
|
||||
async function signup(parent, args, context) {
|
||||
const password = await bcrypt.hash(args.password, 10);
|
||||
const user = await context.mongo.user.create({
|
||||
data: { ...args, password }
|
||||
@@ -30,7 +30,7 @@ async function signup(parent, args, context, info) {
|
||||
};
|
||||
}
|
||||
|
||||
async function login(parent, args, context, info) {
|
||||
async function login(parent, args, context) {
|
||||
const user = await context.mongo.user.findUnique({
|
||||
where: { email: args.email }
|
||||
});
|
||||
@@ -54,18 +54,18 @@ async function login(parent, args, context, info) {
|
||||
};
|
||||
}
|
||||
|
||||
async function follow(parent, args, context, info) {
|
||||
async function follow(parent, args, context) {
|
||||
const { userId } = context;
|
||||
const follow = await context.mongo.follow.findUnique({
|
||||
where: {
|
||||
linkId_userId: {
|
||||
linkId: Number(args.linkId),
|
||||
userId: userId
|
||||
userId
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (Boolean(follow)) {
|
||||
if (follow) {
|
||||
throw new Error(
|
||||
`Already followed the appointment: ${args.linkId}`
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
async function feed(parent, args, context, info) {
|
||||
async function feed(parent, args, context) {
|
||||
|
||||
const where = args.filter
|
||||
? {
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
function newLinkSubscribe(parent, args, context, info) {
|
||||
return context.pubsub.asyncIterator("NEW_LINK")
|
||||
function newAppointmentSubscribe(parent, args, context) {
|
||||
return context.pubsub.asyncIterator("NEW_APPOINTMENT");
|
||||
}
|
||||
|
||||
const newAppointment = {
|
||||
subscribe: newLinkSubscribe,
|
||||
resolve: payload => {
|
||||
return payload
|
||||
},
|
||||
}
|
||||
subscribe: newAppointmentSubscribe,
|
||||
resolve: payload => payload,
|
||||
};
|
||||
|
||||
function newFollowSubscribe(parent, args, context, info) {
|
||||
return context.pubsub.asyncIterator("NEW_FOLLOW")
|
||||
function newFollowSubscribe(parent, args, context) {
|
||||
return context.pubsub.asyncIterator("NEW_FOLLOW");
|
||||
}
|
||||
|
||||
const newFollow = {
|
||||
subscribe: newFollowSubscribe,
|
||||
resolve: payload => {
|
||||
return payload
|
||||
},
|
||||
}
|
||||
resolve: payload => payload,
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
newAppointment,
|
||||
newFollow
|
||||
}
|
||||
};
|
||||
@@ -7,9 +7,7 @@ type Query {
|
||||
orderBy: AppointmentOrderByInput
|
||||
): Feed!
|
||||
allAppointments: [Appointment]
|
||||
oneAppointment(
|
||||
_id: ID!
|
||||
): Appointment
|
||||
oneAppointment(_id: ID!): Appointment
|
||||
allUsers: [User]
|
||||
users: [User!]!
|
||||
}
|
||||
@@ -30,7 +28,7 @@ type Mutation {
|
||||
deleted: Boolean
|
||||
): Appointment!
|
||||
updateAppointment(
|
||||
_id: ID!,
|
||||
_id: ID!
|
||||
title: String!
|
||||
description: String
|
||||
type: String!
|
||||
@@ -38,21 +36,10 @@ type Mutation {
|
||||
end: DateTime!
|
||||
deleted: Boolean
|
||||
): Appointment
|
||||
deleteAppointment(
|
||||
_id: ID!
|
||||
) : Appointment
|
||||
signup(
|
||||
email: String!
|
||||
password: String!
|
||||
username: String!
|
||||
): AuthPayload
|
||||
login(
|
||||
email: String!,
|
||||
password: String!
|
||||
): AuthPayload
|
||||
follow(
|
||||
appointmentId: ID!
|
||||
): Follow
|
||||
deleteAppointment(_id: ID!): Appointment
|
||||
signup(email: String!, password: String!, username: String!): AuthPayload
|
||||
login(email: String!, password: String!): AuthPayload
|
||||
follow(appointmentId: ID!): Follow
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
@@ -66,13 +53,13 @@ type User {
|
||||
username: String!
|
||||
email: String!
|
||||
password: String!
|
||||
# appointments: [Appointment!]!
|
||||
appointments: [Appointment!]!
|
||||
}
|
||||
input UserInput{
|
||||
input UserInput {
|
||||
username: String!
|
||||
email: String!
|
||||
password: String!
|
||||
# appointments: [Appointment!]!
|
||||
appointments: [Appointment!]!
|
||||
}
|
||||
type AuthPayload {
|
||||
token: String
|
||||
@@ -88,9 +75,8 @@ type Appointment {
|
||||
start: DateTime!
|
||||
end: DateTime!
|
||||
deleted: Boolean
|
||||
createdBy: User
|
||||
user: User
|
||||
# follows: [Follow!]!
|
||||
# createdAt: DateTime!
|
||||
}
|
||||
input AppointmentInput {
|
||||
title: String!
|
||||
@@ -99,11 +85,10 @@ input AppointmentInput {
|
||||
start: DateTime!
|
||||
end: DateTime!
|
||||
deleted: Boolean
|
||||
}
|
||||
}
|
||||
input AppointmentOrderByInput {
|
||||
title: Sort
|
||||
desc: Sort
|
||||
# createdAt: Sort
|
||||
}
|
||||
|
||||
# Follow schemas
|
||||
|
||||
Reference in New Issue
Block a user