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
DB: remove locations and add coresponding fields to Venues and Chapters
  • Loading branch information
Zeko369 committed Aug 2, 2020
commit 00f4c1b33c1289e47294e4e946a4418ff58721d0
14 changes: 6 additions & 8 deletions db/generator/factories/chapters.factory.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { company, lorem } from 'faker';
import { Location, Chapter, User } from '../../../server/models';
import { randomItem } from '../lib/random';
import { company, lorem, address } from 'faker';
import { Chapter, User } from '../../../server/models';

const createChapters = async (
locations: Location[],
user: User,
): Promise<Chapter[]> => {
const createChapters = async (user: User): Promise<Chapter[]> => {
const chapters: Chapter[] = [];

for (let i = 0; i < 4; i++) {
Expand All @@ -20,7 +16,9 @@ const createChapters = async (
category,
details: 'random',
creator: user,
location: randomItem(locations),
country: address.country(),
city: address.city(),
region: address.state(),
});

chapters.push(chapter);
Expand Down
29 changes: 0 additions & 29 deletions db/generator/factories/locations.factory.ts

This file was deleted.

13 changes: 8 additions & 5 deletions db/generator/factories/venues.factory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { company } from 'faker';
import { Location, Venue } from '../../../server/models';
import { randomItem } from '../lib/random';
import { company, address } from 'faker';
import { Venue } from '../../../server/models';

const createVenues = async (locations: Location[]): Promise<Venue[]> => {
const createVenues = async (): Promise<Venue[]> => {
const venues: Venue[] = [];

for (let i = 0; i < 4; i++) {
const venue = new Venue({
name: company.companyName(),
location: randomItem(locations),
city: address.city(),
region: address.state(),
postal_code: address.zipCode(),
country: address.country(),
street_address: Math.random() > 0.5 ? address.streetAddress() : undefined,
});

venues.push(venue);
Expand Down
6 changes: 2 additions & 4 deletions db/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'reflect-metadata';
import { createConnection } from 'typeorm';

import createUsers from './factories/user.factory';
import createLocations from './factories/locations.factory';
import createChapters from './factories/chapters.factory';
import createVenues from './factories/venues.factory';
import createEvents from './factories/events.factory';
Expand All @@ -14,11 +13,10 @@ import setupRoles from './setupRoles';
const connection = await createConnection();

const [user, users] = await createUsers();
const locations = await createLocations();
const sponsors = await createSponsors();

const chapters = await createChapters(locations, user);
const venues = await createVenues(locations);
const chapters = await createChapters(user);
const venues = await createVenues();

const events = await createEvents(chapters, venues, sponsors);

Expand Down
24 changes: 0 additions & 24 deletions db/migrations/1575816827867-Location.ts

This file was deleted.

3 changes: 0 additions & 3 deletions db/migrations/1575816971375-Venue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ export class Venue1575816971375 implements MigrationInterface {
`CREATE TABLE "venues" (
"id" SERIAL NOT NULL,
"name" character varying NOT NULL,
"location_id" integer,
"created_at" TIMESTAMP NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "PK_cb0f885278d12384eb7a81818be" PRIMARY KEY ("id"))`,
undefined,
);
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`, undefined);
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "venues" DROP CONSTRAINT "FK_937d4cf54512864b1a842482c13"`, undefined);
await queryRunner.query(`DROP TABLE "venues"`, undefined);
}
}
3 changes: 0 additions & 3 deletions db/migrations/1575817780949-Chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ export class Chapter1575817780949 implements MigrationInterface {
"description" character varying NOT NULL,
"category" character varying NOT NULL,
"details" json NOT NULL,
"location_id" integer,
"creator_id" integer,
"created_at" TIMESTAMP NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "PK_a2bbdbb4bdc786fe0cb0fcfc4a0" PRIMARY KEY ("id"))`,
undefined,
);
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`, undefined);
await queryRunner.query(`ALTER TABLE "chapters" ADD CONSTRAINT "FK_60315cd6f39d467818aa7c60505" FOREIGN KEY ("creator_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, undefined);
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "chapters" DROP CONSTRAINT "FK_60315cd6f39d467818aa7c60505"`, undefined);
await queryRunner.query(`ALTER TABLE "chapters" DROP CONSTRAINT "FK_95d978cb93804fa26283d6741cf"`, undefined);
await queryRunner.query(`DROP TABLE "chapters"`, undefined);
}
}
13 changes: 0 additions & 13 deletions db/migrations/1581805112048-AddAddressToLocation.ts

This file was deleted.

17 changes: 0 additions & 17 deletions db/migrations/1584278611086-AddNotNullToVenuesLocationId.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

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 "street_address" character varying`);
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 "postal_code" character varying 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`);
Expand All @@ -22,18 +17,6 @@ export class RemoveLocations1596397477642 implements MigrationInterface {
}

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"`);
Expand All @@ -44,9 +27,5 @@ export class RemoveLocations1596397477642 implements MigrationInterface {
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`);
}
}
16 changes: 8 additions & 8 deletions server/models/Venue.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Column, Entity, OneToMany } from 'typeorm';
import { BaseModel } from './BaseModel';
import { Event } from './Event';
import { Field, ObjectType, Float, Int } from 'type-graphql';
import { Field, ObjectType, Float } from 'type-graphql';

interface IVenueProps {
name: string;
events?: Event[];
street_address: string;
street_address?: string;
city: string;
postal_code: number;
postal_code: string;
region: string;
country: string;
latitude?: number;
Expand All @@ -29,17 +29,17 @@ export class Venue extends BaseModel {
)
events!: Event[];

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

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

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

@Field(() => String)
@Column()
Expand Down