Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Initial setup apollo on client #393

Merged
merged 16 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove location resolvers
  • Loading branch information
Zeko369 committed Aug 2, 2020
commit d5d8c24e192bd0f6a27c4306f7c11b2ac077db30
36 changes: 26 additions & 10 deletions server/controllers/Chapter/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InputType, Field, Int } from 'type-graphql';
import { InputType, Field } from 'type-graphql';

@InputType()
export class CreateChapterInputs {
Expand All @@ -11,23 +11,39 @@ export class CreateChapterInputs {
@Field(() => String)
category: string;

// details: any;
@Field(() => Int)
locationId: number;
@Field(() => String, { nullable: true })
details?: any;

@Field(() => String)
city: string;

@Field(() => String)
region: string;

@Field(() => String)
country: string;
}

@InputType()
export class UpdateChapterInputs {
@Field(() => String, { nullable: true })
name?: string;
name: string;

@Field(() => String, { nullable: true })
description?: string;
description: string;

@Field(() => String, { nullable: true })
category?: string;
category: string;

@Field(() => String, { nullable: true })
details?: any;

@Field(() => String, { nullable: true })
city: string;

@Field(() => String, { nullable: true })
region: string;

// details: any;
@Field(() => Int, { nullable: true })
locationId?: number;
@Field(() => String, { nullable: true })
country: string;
}
17 changes: 6 additions & 11 deletions server/controllers/Chapter/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Resolver, Query, Arg, Int, Mutation } from 'type-graphql';
import { Chapter, Location, User } from '../../models';
import { Chapter, User } from '../../models';
import { CreateChapterInputs, UpdateChapterInputs } from './inputs';

@Resolver()
Expand All @@ -16,13 +16,10 @@ export class ChapterResolver {

@Mutation(() => Chapter)
async createChapter(@Arg('data') data: CreateChapterInputs) {
const location = await Location.findOne(data.locationId);
if (!location) throw new Error('Cant find location');

// TODO: Use logged in user
const user = await User.findOne();

const chapter = new Chapter({ ...data, location, creator: user });
const chapter = new Chapter({ ...data, creator: user });

return chapter.save();
}
Expand All @@ -36,15 +33,13 @@ export class ChapterResolver {

if (!chapter) throw new Error('Cant find chapter');

if (data.locationId) {
const location = await Location.findOne(data.locationId);
if (!location) throw new Error('Cant find location');
chapter.location = location;
}

chapter.name = data.name ?? chapter.name;
chapter.description = data.description ?? chapter.description;
chapter.category = data.category ?? chapter.category;
chapter.details = data.details ?? chapter.details;
chapter.city = data.city ?? chapter.city;
chapter.region = data.region ?? chapter.region;
chapter.country = data.country ?? chapter.country;

return chapter.save();
}
Expand Down
37 changes: 0 additions & 37 deletions server/controllers/Location/inputs.ts

This file was deleted.

51 changes: 0 additions & 51 deletions server/controllers/Location/resolver.ts

This file was deleted.

48 changes: 42 additions & 6 deletions server/controllers/Venue/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
import { InputType, Field, Int } from 'type-graphql';
import { InputType, Field } from 'type-graphql';

@InputType()
export class CreateVenueInputs {
@Field(() => String)
name: string;

@Field(() => Int)
locationId: number;
@Field(() => String, { nullable: true })
street_address?: string;

@Field(() => String)
city: string;

@Field(() => String)
postal_code: string;

@Field(() => String)
region: string;

@Field(() => String)
country: string;

@Field(() => String, { nullable: true })
latitude?: number;

@Field(() => String, { nullable: true })
longitude?: number;
}

@InputType()
export class UpdateVenueInputs {
@Field(() => String, { nullable: true })
name?: string;
name: string;

@Field(() => Int, { nullable: true })
locationId?: number;
@Field(() => String, { nullable: true })
street_address?: string;

@Field(() => String, { nullable: true })
city: string;

@Field(() => String, { nullable: true })
postal_code: string;

@Field(() => String, { nullable: true })
region: string;

@Field(() => String, { nullable: true })
country: string;

@Field(() => String, { nullable: true })
latitude?: number;

@Field(() => String, { nullable: true })
longitude?: number;
}
21 changes: 9 additions & 12 deletions server/controllers/Venue/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Resolver, Query, Arg, Int, Mutation } from 'type-graphql';
import { Venue, Location } from '../../models';
import { Venue } from '../../models';
import { CreateVenueInputs, UpdateVenueInputs } from './inputs';

@Resolver()
Expand All @@ -16,11 +16,7 @@ export class VenueResolver {

@Mutation(() => Venue)
async createVenue(@Arg('data') data: CreateVenueInputs) {
const location = await Location.findOne(data.locationId);

if (!location) throw new Error('Cant find location');

const venue = new Venue({ name: data.name, location });
const venue = new Venue({ ...data });
return venue.save();
}

Expand All @@ -32,13 +28,14 @@ export class VenueResolver {
const venue = await Venue.findOne(id);
if (!venue) throw new Error('Cant find venue');

if (data.locationId) {
const location = await Location.findOne(data.locationId);
if (!location) throw new Error('Cant find location');
venue.location = location;
}

venue.name = data.name ?? venue.name;
venue.street_address = data.street_address ?? venue.street_address;
venue.city = data.city ?? venue.city;
venue.postal_code = data.postal_code ?? venue.postal_code;
venue.region = data.region ?? venue.region;
venue.country = data.country ?? venue.country;
venue.latitude = data.latitude ?? venue.latitude;
venue.longitude = data.longitude ?? venue.longitude;

return venue.save();
}
Expand Down
3 changes: 1 addition & 2 deletions server/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChapterResolver } from './Chapter/resolver';
import { LocationResolver } from './Location/resolver';
import { VenueResolver } from './Venue/resolver';

const resolvers = [ChapterResolver, LocationResolver, VenueResolver] as const;
const resolvers = [ChapterResolver, VenueResolver] as const;

export { resolvers };