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

feat(client, db): event url #423

Merged
merged 6 commits into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 36 additions & 0 deletions client/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "url",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "start_at",
"description": null,
Expand Down Expand Up @@ -2761,6 +2773,20 @@
},
"defaultValue": null
},
{
"name": "url",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "start_at",
"description": null,
Expand Down Expand Up @@ -2862,6 +2888,16 @@
},
"defaultValue": null
},
{
"name": "url",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "start_at",
"description": null,
Expand Down
20 changes: 17 additions & 3 deletions client/src/generated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type Event = {
updated_at: Scalars['DateTime'];
name: Scalars['String'];
description: Scalars['String'];
url?: Maybe<Scalars['String']>;
start_at: Scalars['DateTime'];
ends_at: Scalars['DateTime'];
canceled: Scalars['Boolean'];
Expand Down Expand Up @@ -280,6 +281,7 @@ export type UpdateVenueInputs = {
export type CreateEventInputs = {
name: Scalars['String'];
description: Scalars['String'];
url: Scalars['String'];
start_at: Scalars['DateTime'];
ends_at: Scalars['DateTime'];
capacity: Scalars['Float'];
Expand All @@ -290,6 +292,7 @@ export type CreateEventInputs = {
export type UpdateEventInputs = {
name?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
url?: Maybe<Scalars['String']>;
start_at?: Maybe<Scalars['DateTime']>;
ends_at?: Maybe<Scalars['DateTime']>;
capacity?: Maybe<Scalars['Float']>;
Expand All @@ -302,7 +305,7 @@ export type EventsQuery = { __typename?: 'Query' } & {
events: Array<
{ __typename?: 'Event' } & Pick<
Event,
'id' | 'name' | 'canceled' | 'description' | 'capacity'
'id' | 'name' | 'canceled' | 'description' | 'url' | 'capacity'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have these ordered alphabetically?
(The OCD in me. Would not block a merge IMHO).

> & {
tags?: Maybe<Array<{ __typename?: 'Tag' } & Pick<Tag, 'id' | 'name'>>>;
}
Expand All @@ -320,6 +323,7 @@ export type EventQuery = { __typename?: 'Query' } & {
| 'id'
| 'name'
| 'description'
| 'url'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to sort these alphabetically?
(Not blocking a merge IMHO).

| 'canceled'
| 'capacity'
| 'start_at'
Expand Down Expand Up @@ -356,7 +360,13 @@ export type EventVenuesQuery = { __typename?: 'Query' } & {
event?: Maybe<
{ __typename?: 'Event' } & Pick<
Event,
'id' | 'name' | 'description' | 'capacity' | 'start_at' | 'ends_at'
| 'id'
| 'name'
| 'description'
| 'url'
| 'capacity'
| 'start_at'
| 'ends_at'
> & {
tags?: Maybe<Array<{ __typename?: 'Tag' } & Pick<Tag, 'id' | 'name'>>>;
venue: { __typename?: 'Venue' } & Pick<Venue, 'id'>;
Expand All @@ -372,7 +382,7 @@ export type CreateEventMutationVariables = Exact<{
export type CreateEventMutation = { __typename?: 'Mutation' } & {
createEvent: { __typename?: 'Event' } & Pick<
Event,
'id' | 'name' | 'canceled' | 'description' | 'capacity'
'id' | 'name' | 'canceled' | 'description' | 'url' | 'capacity'
> & {
tags?: Maybe<Array<{ __typename?: 'Tag' } & Pick<Tag, 'id' | 'name'>>>;
};
Expand Down Expand Up @@ -489,6 +499,7 @@ export const EventsDocument = gql`
name
canceled
description
url
capacity
tags {
id
Expand Down Expand Up @@ -547,6 +558,7 @@ export const EventDocument = gql`
id
name
description
url
canceled
capacity
start_at
Expand Down Expand Up @@ -627,6 +639,7 @@ export const EventVenuesDocument = gql`
id
name
description
url
capacity
start_at
ends_at
Expand Down Expand Up @@ -698,6 +711,7 @@ export const CreateEventDocument = gql`
name
canceled
description
url
capacity
tags {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export const fields: IField[] = [
label: 'Description',
placeholder: '',
},
{
key: 'url',
type: 'text',
label: 'url',
placeholder: '',
},
{
key: 'capacity',
type: 'number',
Expand Down Expand Up @@ -52,6 +58,7 @@ export const fields: IField[] = [
export interface IEventFormData {
name: string;
description: string;
url?: string | null;
capacity: number;
tags: string;
start_at: string;
Expand Down
3 changes: 2 additions & 1 deletion client/src/modules/dashboard/Events/components/EventItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Actions from './Actions';
interface IEventItemProps {
event: Pick<
Event,
'id' | 'name' | 'description' | 'capacity' | 'canceled'
'id' | 'name' | 'description' | 'url' | 'capacity' | 'canceled'
> & { tags?: Pick<Tag, 'id' | 'name'>[] | null };
loading: boolean;
}
Expand All @@ -37,6 +37,7 @@ const EventItem: React.FC<IEventItemProps> = ({ loading, event }) => {
<Typography variant="body2" color="textSecondary" component="p">
{event.description}
</Typography>
{event.url && <a href={event.url}>{event.url}</a>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth to wrap in a p, too?

<Typography variant="body2" color="textSecondary" component="p">
{event.capacity}
</Typography>
Expand Down
4 changes: 4 additions & 0 deletions client/src/modules/dashboard/Events/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const EVENTS = gql`
name
canceled
description
url
capacity
tags {
id
Expand All @@ -22,6 +23,7 @@ export const EVENT = gql`
id
name
description
url
canceled
capacity
start_at
Expand Down Expand Up @@ -58,6 +60,7 @@ export const EVENT_WITH_VENU = gql`
id
name
description
url
capacity
start_at
ends_at
Expand All @@ -83,6 +86,7 @@ export const createEvent = gql`
name
canceled
description
url
capacity
tags {
id
Expand Down
3 changes: 2 additions & 1 deletion client/src/modules/dashboard/Events/pages/EventPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const EventPage: NextPage = () => {
{loading
? 'Loading...'
: !error
? 'Cant find event :('
? "Can't find event :("
timmyichen marked this conversation as resolved.
Show resolved Hide resolved
: 'Error...'}
</h1>
</Skeleton>
Expand All @@ -48,6 +48,7 @@ export const EventPage: NextPage = () => {
<Typography variant="body2" color="textSecondary" component="p">
{data.event.description}
</Typography>
<a href={data.event.url}>{data.event.url}</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth to wrap in a <p>, too?

<Typography variant="body2" color="textSecondary" component="p">
{data.event.capacity}
</Typography>
Expand Down
3 changes: 2 additions & 1 deletion db/generator/factories/events.factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { company, lorem } from 'faker';
import { company, lorem, internet } from 'faker';
import {
Event,
Venue,
Expand All @@ -21,6 +21,7 @@ const createEvents = async (
name: company.companyName(),
chapter: randomItem(chapters),
description: lorem.words(),
url: internet.url(),
capacity: random(1000),
venue: randomItem(venues),
canceled: Math.random() > 0.5,
Expand Down
13 changes: 13 additions & 0 deletions db/migrations/1603576293055-AddUrlColumnToEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "events" ADD "url" character varying`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "events" DROP COLUMN "url"`);
}
}
6 changes: 6 additions & 0 deletions server/controllers/Events/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export class CreateEventInputs {
@Field(() => String)
description: string;

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

@Field(() => Date)
start_at: number;

Expand All @@ -32,6 +35,9 @@ export class UpdateEventInputs {
@Field(() => String, { nullable: true })
description: string;

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

@Field(() => Date, { nullable: true })
start_at: number;

Expand Down
2 changes: 1 addition & 1 deletion server/controllers/Events/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class EventResolver {

event.name = data.name ?? event.name;
event.description = data.description ?? event.description;
event.url = data.url ?? event.url;
gh-23378 marked this conversation as resolved.
Show resolved Hide resolved
event.start_at = new Date(data.start_at) ?? event.start_at;
event.ends_at = new Date(data.ends_at) ?? event.ends_at;
event.capacity = data.capacity ?? event.capacity;
Expand All @@ -56,7 +57,6 @@ export class EventResolver {
if (!venue) throw new Error('Cant find venue');
event.venue = venue;
}

return event.save();
}

Expand Down
7 changes: 7 additions & 0 deletions server/models/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class Event extends BaseModel {
@Column({ nullable: false })
description!: string;

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

@Field(() => Date)
@Column({ type: 'timestamp' })
start_at!: Date;
Expand Down Expand Up @@ -77,6 +81,7 @@ export class Event extends BaseModel {
constructor(params: {
name: string;
description: string;
url?: string;
start_at: Date;
ends_at: Date;
canceled?: boolean;
Expand All @@ -89,6 +94,7 @@ export class Event extends BaseModel {
const {
name,
description,
url,
start_at,
ends_at,
canceled,
Expand All @@ -99,6 +105,7 @@ export class Event extends BaseModel {

this.name = name;
this.description = description;
this.url = url;
this.start_at = start_at;
this.ends_at = ends_at;
this.canceled = canceled || false;
Expand Down