Update event update resolver

This commit is contained in:
Amit Jakubowicz 2019-10-03 16:28:32 +02:00
parent fbcea6c592
commit 14476574ca
7 changed files with 288 additions and 1 deletions

245
@types/graphql.d.ts vendored
View File

@ -0,0 +1,245 @@
// tslint:disable
// graphql typescript definitions
declare namespace GQL {
interface IGraphQLResponseRoot {
data?: IQuery | IMutation;
errors?: Array<IGraphQLResponseError>;
}
interface IGraphQLResponseError {
/** Required for all errors */
message: string;
locations?: Array<IGraphQLResponseErrorLocation>;
/** 7.2.2 says 'GraphQL servers may provide additional entries to error' */
[propName: string]: any;
}
interface IGraphQLResponseErrorLocation {
line: number;
column: number;
}
interface IQuery {
__typename: 'Query';
me: IUser | null;
event: ICalendarEvent | null;
events: Array<ICalendarEvent | null> | null;
occurrences: Array<IEventOccurrence | null> | null;
occurrence: IEventOccurrence | null;
}
interface IEventOnQueryArguments {
id: string;
}
interface IEventsOnQueryArguments {
filter: IEventsQueryFilter;
}
interface IOccurrencesOnQueryArguments {
filter: IOccurrencesQueryFilter;
}
interface IOccurrenceOnQueryArguments {
id: string;
}
interface IUser {
__typename: 'User';
name: string;
username: string | null;
email: string;
id: string;
events: Array<ICalendarEvent | null>;
roles: Array<IUserRole> | null;
}
interface ICalendarEvent {
__typename: 'CalendarEvent';
id: string;
owner: IUser;
info: Array<IEventInformation | null>;
time: IEventTime;
status: any;
location: ILocation;
occurrences: Array<IEventOccurrence | null> | null;
meta: IEventMeta | null;
}
interface IEventInformation {
__typename: 'EventInformation';
language: string;
title: string;
description: string | null;
}
interface IEventTime {
__typename: 'EventTime';
timeZone: any | null;
start: any | null;
end: any | null;
recurrence: string | null;
exceptions: string | null;
}
interface ILocation {
__typename: 'Location';
address: string | null;
name: string | null;
}
interface IEventOccurrence {
__typename: 'EventOccurrence';
id: string;
event: ICalendarEvent;
start: string;
end: string;
}
interface IEventMeta {
__typename: 'EventMeta';
tags: Array<string | null>;
}
interface IUserRole {
__typename: 'UserRole';
user: IUser;
type: any;
}
interface IEventsQueryFilter {
owner?: string | null;
limit?: number | null;
from?: any | null;
to?: any | null;
categories?: Array<any | null> | null;
}
interface IOccurrencesQueryFilter {
from?: any | null;
to?: any | null;
timeZone?: any | null;
categories?: Array<any | null> | null;
limit?: number | null;
}
interface IMutation {
__typename: 'Mutation';
signup: Array<IError | null> | null;
signin: IUserSession;
requestInvite: boolean;
grantRole: IUser;
revokeRole: IUser;
createEvent: ICalendarEvent | null;
updateEvent: ICalendarEvent | null;
}
interface ISignupOnMutationArguments {
input: ISignupInput;
}
interface ISigninOnMutationArguments {
input: ISigninInput;
}
interface IRequestInviteOnMutationArguments {
input: IRequestInviteInput;
}
interface IGrantRoleOnMutationArguments {
input: IGrantRoleInput;
}
interface IRevokeRoleOnMutationArguments {
input: IGrantRoleInput;
}
interface ICreateEventOnMutationArguments {
input: ICreateEventInput;
}
interface IUpdateEventOnMutationArguments {
input: IUpdateEventInput;
}
interface ISignupInput {
email: string;
username: string;
name: string;
}
interface IError {
__typename: 'Error';
path: string;
message: string;
}
interface ISigninInput {
hash: string;
}
interface IUserSession {
__typename: 'UserSession';
hash: string;
user: IUser;
ctime: any;
isValid: boolean;
}
interface IRequestInviteInput {
email: string;
}
interface IGrantRoleInput {
userId: string;
roleType: any;
}
interface ICreateEventInput {
time: IEventTimeInput;
info: Array<IEventInformationInput | null>;
location: IEventLocationInput;
meta: IEventMetaInput;
status: string;
}
interface IEventTimeInput {
timeZone: any;
start: any;
end: any;
recurrence?: string | null;
exceptions?: string | null;
}
interface IEventInformationInput {
language: string;
title: string;
description?: string | null;
}
interface IEventLocationInput {
address?: string | null;
name?: string | null;
}
interface IEventMetaInput {
tags: Array<string | null>;
}
interface IUpdateEventInput {
id: string;
time?: IEventTimeInput | null;
info?: Array<IEventInformationInput> | null;
location?: IEventLocationInput | null;
meta?: IEventMetaInput | null;
status?: string | null;
}
interface IRevokeRoleInput {
userId: string;
roleType: any;
}
}
// tslint:enable

View File

@ -1,6 +1,12 @@
# Communal events calendar
This is a weekend project of mine and you can use this code at your own risk as there is no guarantee that this code is secure or complying to any privacy rules.
## DB Extensions:
```
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
```
## Motivation
I often visit a region that I like very much. I like it because it's very rural and has a lot of beautiful nature.
There's also a lot going on, and tons of great people but there is nowhere to get information about all the events

View File

@ -26,8 +26,10 @@
"graphql-tools": "^4.0.5",
"luxon": "^1.17.2",
"mailgun-js": "^0.22.0",
"morgan": "^1.9.1",
"node-pre-gyp": "^0.13.0",
"pg": "^7.12.0",
"ramda": "^0.26.1",
"random-string": "^0.2.0",
"rrule": "^2.6.2",
"typeorm": "^0.2.18",

View File

@ -6,6 +6,7 @@ import {
import { Context, ResolverMap } from "../@types/graphql-utils"
import {GQL} from "../../@types"
import EventsService from './EventsService'
import { equals } from 'ramda'
const eventsService = new EventsService()
@ -111,7 +112,8 @@ const resolvers: ResolverMap = {
if (Object.keys(fields).length === 0) {
throw Error("No change detected")
}
if (input.time) {
if (input.time && !equals(input.time, event.time)) {
console.log(`Event time changed from: ${JSON.stringify(event.time)} to: ${JSON.stringify(input.time)}`)
event.time = input.time
const existingOccurrences = await event.occurrences
await Promise.all(existingOccurrences.map(occ => EventOccurrence.delete(occ.id)))

View File

@ -6,6 +6,7 @@ import * as config from './config'
import express from 'express'
import authHttpHandlers from "./Auth/authHttpHandlers"
import SessionManager from "./Auth/SessionManager"
import morgan from 'morgan'
const start = async () => {
const sessionManager = new SessionManager({
@ -29,6 +30,8 @@ const start = async () => {
const app = express()
app.use(express.json())
app.use(morgan('combined'))
app.post('/api/signup', authHandlers.signupHandler)
app.post('/api/login', authHandlers.loginHandler)
app.post('/api/init-session', authHandlers.initializeSessionHandler)

View File

@ -117,6 +117,7 @@ input EventTimeInput {
start: Timestamp!
end: Timestamp!
recurrence: String
exceptions: String
}
input EventInformationInput {

View File

@ -1120,6 +1120,13 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"
basic-auth@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==
dependencies:
safe-buffer "5.1.2"
bcrypt-pbkdf@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
@ -3660,6 +3667,17 @@ mkdirp@0.x, mkdirp@^0.5.0, mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"
morgan@^1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.9.1.tgz#0a8d16734a1d9afbc824b99df87e738e58e2da59"
integrity sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==
dependencies:
basic-auth "~2.0.0"
debug "2.6.9"
depd "~1.1.2"
on-finished "~2.3.0"
on-headers "~1.0.1"
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@ -3949,6 +3967,11 @@ on-finished@~2.3.0:
dependencies:
ee-first "1.1.1"
on-headers@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f"
integrity sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==
once@^1.3.0, once@^1.3.1, once@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
@ -4407,6 +4430,11 @@ qs@~6.5.2:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
ramda@^0.26.1:
version "0.26.1"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.26.1.tgz#8d41351eb8111c55353617fc3bbffad8e4d35d06"
integrity sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ==
random-string@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/random-string/-/random-string-0.2.0.tgz#a46e4375352beda9a0d7b0d19ed6d321ecd1d82d"