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 locations table
  • Loading branch information
Zeko369 committed Aug 2, 2020
commit 03835fdb4f55c49fe7144bccc393af8698378b70
52 changes: 52 additions & 0 deletions db/migrations/1596397477642-RemoveLocations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class RemoveLocations1596397477642 implements MigrationInterface {
name = 'RemoveLocations1596397477642';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "locations"`);
await queryRunner.query(`ALTER TABLE "venues" DROP CONSTRAINT "FK_937d4cf54512864b1a842482c13"`);
await queryRunner.query(`ALTER TABLE "chapters" DROP CONSTRAINT "FK_95d978cb93804fa26283d6741cf"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "location_id"`);
await queryRunner.query(`ALTER TABLE "chapters" DROP COLUMN "location_id"`);
await queryRunner.query(`ALTER TABLE "venues" ADD "street_address" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "venues" ADD "city" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "venues" ADD "postal_code" integer NOT NULL`);
await queryRunner.query(`ALTER TABLE "venues" ADD "region" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "venues" ADD "country" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "venues" ADD "latitude" double precision`);
await queryRunner.query(`ALTER TABLE "venues" ADD "longitude" double precision`);
await queryRunner.query(`ALTER TABLE "chapters" ADD "city" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "chapters" ADD "region" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "chapters" ADD "country" character varying NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "locations" (
"id" SERIAL NOT NULL,
"country_code" character varying NOT NULL,
"city" character varying NOT NULL,
"region" character varying NOT NULL,
"postal_code" character varying NOT NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "PK_7cc1c9e3853b94816c094825e74" PRIMARY KEY ("id"))`,
undefined,
);
await queryRunner.query(`ALTER TABLE "chapters" DROP COLUMN "country"`);
await queryRunner.query(`ALTER TABLE "chapters" DROP COLUMN "region"`);
await queryRunner.query(`ALTER TABLE "chapters" DROP COLUMN "city"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "longitude"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "latitude"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "country"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "region"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "postal_code"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "city"`);
await queryRunner.query(`ALTER TABLE "venues" DROP COLUMN "street_address"`);
await queryRunner.query(`ALTER TABLE "chapters" ADD "location_id" integer`);
await queryRunner.query(`ALTER TABLE "venues" ADD "location_id" integer NOT NULL`);
await queryRunner.query(`ALTER TABLE "chapters" ADD CONSTRAINT "FK_95d978cb93804fa26283d6741cf" FOREIGN KEY ("location_id") REFERENCES "locations"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "venues" ADD CONSTRAINT "FK_937d4cf54512864b1a842482c13" FOREIGN KEY ("location_id") REFERENCES "locations"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}
44 changes: 22 additions & 22 deletions server/models/Chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Column, Entity, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { ObjectType, Field } from 'type-graphql';
import { BaseModel } from './BaseModel';
import { Event } from './Event';
import { Location } from './Location';
import { User } from './User';
import { UserChapterRole } from './UserChapterRole';
import { UserBan } from './UserBan';
Expand All @@ -27,21 +26,25 @@ export class Chapter extends BaseModel {
@Column({ type: 'json' })
details!: any;

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

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

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

@Field(() => [Event])
@OneToMany(
_type => Event,
event => event.chapter,
)
events!: Event[];

@Field(() => Location)
@ManyToOne(
_type => Location,
location => location.chapters,
)
@JoinColumn({ name: 'location_id' })
location!: Location;

@Field(() => User)
@ManyToOne(
_type => User,
Expand Down Expand Up @@ -69,25 +72,22 @@ export class Chapter extends BaseModel {
description: string;
category: string;
// details: any;
location?: Location;
city: string;
region: string;
country: string;
creator?: User;
}) {
super();
if (params) {
const {
name,
description,
category,
// details,
location,
creator,
} = params;
const { creator } = params;

this.name = name;
this.description = description;
this.category = category;
this.name = params.name;
this.description = params.description;
this.category = params.category;
// this.details = details;
location && (this.location = location);
this.city = params.city;
this.region = params.region;
this.country = params.country;
creator && (this.creator = creator);
}
}
Expand Down
62 changes: 0 additions & 62 deletions server/models/Location.ts

This file was deleted.

67 changes: 52 additions & 15 deletions server/models/Venue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { Column, Entity, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { Column, Entity, OneToMany } from 'typeorm';
import { BaseModel } from './BaseModel';
import { Event } from './Event';
import { Location } from './Location';
import { Field, ObjectType } from 'type-graphql';
import { Field, ObjectType, Float, Int } from 'type-graphql';

interface IVenueProps {
name: string;
events?: Event[];
street_address: string;
city: string;
postal_code: number;
region: string;
country: string;
latitude?: number;
longitude?: number;
}

@ObjectType()
@Entity({ name: 'venues' })
Expand All @@ -18,21 +29,47 @@ export class Venue extends BaseModel {
)
events!: Event[];

@Field(() => Location)
@ManyToOne(
_type => Location,
location => location.venues,
{ nullable: false },
)
@JoinColumn({ name: 'location_id' })
location!: Location;
@Field(() => String)
@Column()
street_address: string;

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

@Field(() => Int)
@Column()
postal_code: number;

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

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

@Field(() => Float, { nullable: true })
@Column({ type: 'float', nullable: true })
latitude?: number;

@Field(() => Float, { nullable: true })
@Column({ type: 'float', nullable: true })
longitude?: number;

constructor(params: { name: string; location: Location }) {
constructor(params: IVenueProps) {
super();
if (params) {
const { name, location } = params;
this.name = name;
this.location = location;
this.name = params.name;
this.name = params.name;
this.events = params.events || [];
this.street_address = params.street_address;
this.city = params.city;
this.postal_code = params.postal_code;
this.region = params.region;
this.country = params.country;
this.latitude = params.latitude;
this.longitude = params.longitude;
}
}
}
1 change: 0 additions & 1 deletion server/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './BaseModel';
export * from './Chapter';
export * from './Event';
export * from './EventSponsor';
export * from './Location';
export * from './Rsvp';
export * from './Sponsor';
export * from './Tag';
Expand Down