This commit is contained in:
Riccardo
2021-08-16 11:06:02 +02:00
parent 78db95aa5f
commit 2f119e43bd
12 changed files with 68 additions and 101 deletions

View File

@@ -5,6 +5,7 @@ import AppointmentList from './appointment/AppointmentList';
import CreateAppointment from './appointment/CreateAppointment'; import CreateAppointment from './appointment/CreateAppointment';
import UpdateAppointemnt from './appointment/UpdateAppointment'; import UpdateAppointemnt from './appointment/UpdateAppointment';
import Calendar from './Calendar'; import Calendar from './Calendar';
import Search from './Search';
import { Switch, Route } from 'react-router-dom'; import { Switch, Route } from 'react-router-dom';
const App = () => { const App = () => {
@@ -18,6 +19,7 @@ const App = () => {
<Route exact path="/update/:_id" component={UpdateAppointemnt} /> <Route exact path="/update/:_id" component={UpdateAppointemnt} />
<Route exact path="/login" component={Login} /> <Route exact path="/login" component={Login} />
<Route exact path="/calendar" component={Calendar} /> <Route exact path="/calendar" component={Calendar} />
<Route exact path="/search" component={Search} />
</Switch> </Switch>
</div> </div>
</div> </div>

View File

@@ -1,29 +1,16 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useMutation } from '@apollo/client';
import { useLazyQuery } from '@apollo/client'; import { useLazyQuery } from '@apollo/client';
import gql from 'graphql-tag'; import gql from 'graphql-tag';
import Appointment from './Appointment'; import Appointment from './appointment/Appointment';
import { Link } from 'react-router-dom';
const FEED_SEARCH_QUERY = gql` const FEED_SEARCH_QUERY = gql`
query FeedSearchQuery($filter: String!) { query FeedSearchQuery($filter: String!) {
feed(filter: $filter) { feed(filter: $filter) {
id id
links { appointments {
id _id
title title
description description
type
createdBy {
id
username
}
# follows {
# id
# user {
# id
# }
# }
} }
} }
} }
@@ -38,24 +25,13 @@ const Search = () => {
<> <>
<div> <div>
Search Search
<input <input type="text" onChange={(e) => setSearchFilter(e.target.value)}/>
type="text" <button onClick={() => executeSearch({ variables: { filter: searchFilter } })}>OK</button>
onChange={(e) => setSearchFilter(e.target.value)}
/>
<button
onClick={() =>
executeSearch({
variables: { filter: searchFilter }
})
}
>
OK
</button>
</div> </div>
{/* {data && {data &&
data.feed.appointments.map((appointment, index) => ( data.feed.appointments.map((appointment, index) => (
<Link key={appointment.id} link={appointment} index={index} /> <Appointment key={appointment.id} appointment={appointment} index={index} />
))} */} ))}
</> </>
); );
}; };

View File

@@ -21,10 +21,10 @@ const Appointment = (props) => {
onCompleted: () => history.push('/') onCompleted: () => history.push('/')
}) })
// const updateAppointment = () => { const updateAppointment = () => {
// let path = `/update/${appointment._id}`; let path = `/update/${appointment._id}`;
// history.push(path); history.push(path);
// } }
return ( return (
<div> <div>

View File

@@ -1,8 +1,8 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import { useMutation, gql, useQuery } from '@apollo/client'; import { useMutation, gql, useQuery } from '@apollo/client';
import { APPOINTMENTS_PER_PAGE } from '../../constants'; // import { APPOINTMENTS_PER_PAGE } from '../../constants';
import { APPOINTMENTS_QUERY } from './AppointmentList'; // import { APPOINTMENTS_QUERY } from './AppointmentList';
import Datetime from 'react-datetime'; import Datetime from 'react-datetime';
import "react-datetime/css/react-datetime.css"; import "react-datetime/css/react-datetime.css";

View File

@@ -1,6 +1,6 @@
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 } from 'react-router-dom';
// import { AUTH_TOKEN } from '../../constants'; // import { AUTH_TOKEN } from '../../constants';
const Header = () => { const Header = () => {
@@ -17,6 +17,9 @@ 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">
<Link to="/search" className="ml1 no-underline black">Search</Link>
</div> */}
{/* <div className="flex flex-fixed"> {/* <div className="flex flex-fixed">
{authToken ? ( {authToken ? (
<div className="ml1 pointer black" <div className="ml1 pointer black"

View File

@@ -10,8 +10,8 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
import cors from 'cors'; import cors from 'cors';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
const { APP_SECRET } = require('../utils');
const APP_SECRET = 'GraphQL-is-aw3some';
const moduleURL = new URL(import.meta.url); const moduleURL = new URL(import.meta.url);
const __dirname = path.dirname(moduleURL.pathname); const __dirname = path.dirname(moduleURL.pathname);
const app = express(); const app = express();
@@ -76,7 +76,7 @@ const server = new ApolloServer({
req && req.headers.authorization req && req.headers.authorization
? getUserId(req) ? getUserId(req)
: null : null
} };
}, },
// subscriptions: { // subscriptions: {
// onConnect: (connectionParams) => { // onConnect: (connectionParams) => {

View File

@@ -24,6 +24,11 @@ const AppointmentSchema = new Schema({
deleted: { deleted: {
type: Boolean, type: Boolean,
required: false required: false
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "user",
required: false
} }
}); });
export default mongoose.model('appointment', AppointmentSchema); export default mongoose.model('appointment', AppointmentSchema);

View File

@@ -1,5 +1,5 @@
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 jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
export const resolvers = { export const resolvers = {

View File

@@ -2,7 +2,7 @@ const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const { APP_SECRET } = require('../utils'); const { APP_SECRET } = require('../utils');
function createAppointment(parent, args, context, info) { function createAppointment(parent, args, context) {
const { userId } = context; const { userId } = context;
const newAppointment = context.mongo.appointment.create({ const newAppointment = context.mongo.appointment.create({
@@ -16,7 +16,7 @@ function createAppointment(parent, args, context, info) {
return newAppointment; return newAppointment;
} }
async function signup(parent, args, context, info) { async function signup(parent, args, context) {
const password = await bcrypt.hash(args.password, 10); const password = await bcrypt.hash(args.password, 10);
const user = await context.mongo.user.create({ const user = await context.mongo.user.create({
data: { ...args, password } 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({ const user = await context.mongo.user.findUnique({
where: { email: args.email } 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 { userId } = context;
const follow = await context.mongo.follow.findUnique({ const follow = await context.mongo.follow.findUnique({
where: { where: {
linkId_userId: { linkId_userId: {
linkId: Number(args.linkId), linkId: Number(args.linkId),
userId: userId userId
} }
} }
}); });
if (Boolean(follow)) { if (follow) {
throw new Error( throw new Error(
`Already followed the appointment: ${args.linkId}` `Already followed the appointment: ${args.linkId}`
); );

View File

@@ -1,4 +1,4 @@
async function feed(parent, args, context, info) { async function feed(parent, args, context) {
const where = args.filter const where = args.filter
? { ? {

View File

@@ -1,26 +1,22 @@
function newLinkSubscribe(parent, args, context, info) { function newAppointmentSubscribe(parent, args, context) {
return context.pubsub.asyncIterator("NEW_LINK") return context.pubsub.asyncIterator("NEW_APPOINTMENT");
} }
const newAppointment = { const newAppointment = {
subscribe: newLinkSubscribe, subscribe: newAppointmentSubscribe,
resolve: payload => { resolve: payload => payload,
return payload };
},
}
function newFollowSubscribe(parent, args, context, info) { function newFollowSubscribe(parent, args, context) {
return context.pubsub.asyncIterator("NEW_FOLLOW") return context.pubsub.asyncIterator("NEW_FOLLOW");
} }
const newFollow = { const newFollow = {
subscribe: newFollowSubscribe, subscribe: newFollowSubscribe,
resolve: payload => { resolve: payload => payload,
return payload };
},
}
module.exports = { module.exports = {
newAppointment, newAppointment,
newFollow newFollow
} };

View File

@@ -7,9 +7,7 @@ type Query {
orderBy: AppointmentOrderByInput orderBy: AppointmentOrderByInput
): Feed! ): Feed!
allAppointments: [Appointment] allAppointments: [Appointment]
oneAppointment( oneAppointment(_id: ID!): Appointment
_id: ID!
): Appointment
allUsers: [User] allUsers: [User]
users: [User!]! users: [User!]!
} }
@@ -30,7 +28,7 @@ type Mutation {
deleted: Boolean deleted: Boolean
): Appointment! ): Appointment!
updateAppointment( updateAppointment(
_id: ID!, _id: ID!
title: String! title: String!
description: String description: String
type: String! type: String!
@@ -38,21 +36,10 @@ type Mutation {
end: DateTime! end: DateTime!
deleted: Boolean deleted: Boolean
): Appointment ): Appointment
deleteAppointment( deleteAppointment(_id: ID!): Appointment
_id: ID! signup(email: String!, password: String!, username: String!): AuthPayload
) : Appointment login(email: String!, password: String!): AuthPayload
signup( follow(appointmentId: ID!): Follow
email: String!
password: String!
username: String!
): AuthPayload
login(
email: String!,
password: String!
): AuthPayload
follow(
appointmentId: ID!
): Follow
} }
type Subscription { type Subscription {
@@ -66,13 +53,13 @@ type User {
username: String! username: String!
email: String! email: String!
password: String! password: String!
# appointments: [Appointment!]! appointments: [Appointment!]!
} }
input UserInput { input UserInput {
username: String! username: String!
email: String! email: String!
password: String! password: String!
# appointments: [Appointment!]! appointments: [Appointment!]!
} }
type AuthPayload { type AuthPayload {
token: String token: String
@@ -88,9 +75,8 @@ type Appointment {
start: DateTime! start: DateTime!
end: DateTime! end: DateTime!
deleted: Boolean deleted: Boolean
createdBy: User user: User
# follows: [Follow!]! # follows: [Follow!]!
# createdAt: DateTime!
} }
input AppointmentInput { input AppointmentInput {
title: String! title: String!
@@ -103,7 +89,6 @@ input AppointmentInput {
input AppointmentOrderByInput { input AppointmentOrderByInput {
title: Sort title: Sort
desc: Sort desc: Sort
# createdAt: Sort
} }
# Follow schemas # Follow schemas