-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from bakaphp/feat/CAD-121
feat: Implement Event queries and mutations
- Loading branch information
Showing
10 changed files
with
334 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
EVENT_CATEGORIES_QUERY, | ||
EVENT_PARTICIPANTS_QUERY, | ||
EVENT_QUERY, | ||
EVENT_TYPES_QUERY, | ||
} from '../../queries'; | ||
|
||
import { ClientType } from '../../'; | ||
|
||
import { | ||
CreateEventResponse, | ||
EventInputInterface, | ||
GetParticipantsByEventId, | ||
GetEventResponse, | ||
OrderBy, | ||
EventTypeInterface, | ||
EventCategoryInterface, | ||
} from '../../types'; | ||
|
||
import { CREATE_EVENT_MUTATION } from '../../mutations'; | ||
|
||
export class Event { | ||
constructor(protected client: ClientType) {} | ||
|
||
public async createEvent( | ||
input: EventInputInterface | ||
): Promise<CreateEventResponse> { | ||
const { data } = await this.client.mutate({ | ||
mutation: CREATE_EVENT_MUTATION, | ||
variables: { input }, | ||
}); | ||
return data.createEvent; | ||
} | ||
|
||
public async getEvent( | ||
options: { | ||
first?: number; | ||
page?: number; | ||
orderBy?: Array<OrderBy>; | ||
} = {} | ||
): Promise<GetEventResponse> { | ||
const { first, page, orderBy } = options; | ||
const response = await this.client.query({ | ||
query: EVENT_QUERY, | ||
variables: { first, page, orderBy }, | ||
fetchPolicy: 'network-only', | ||
partialRefetch: true, | ||
}); | ||
return response.data.events; | ||
} | ||
|
||
public async getEventTypes(): Promise<EventTypeInterface[]> { | ||
const response = await this.client.query({ | ||
query: EVENT_TYPES_QUERY, | ||
fetchPolicy: 'network-only', | ||
partialRefetch: true, | ||
}); | ||
return response.data.eventTypes.data; | ||
} | ||
|
||
public async getEventCategories(): Promise<EventCategoryInterface[]> { | ||
const response = await this.client.query({ | ||
query: EVENT_CATEGORIES_QUERY, | ||
fetchPolicy: 'network-only', | ||
partialRefetch: true, | ||
}); | ||
return response.data.eventCategories.data; | ||
} | ||
|
||
public async getParticipantsByEventId( | ||
eventId: string | ||
): Promise<GetParticipantsByEventId> { | ||
const { data } = await this.client.query({ | ||
query: EVENT_PARTICIPANTS_QUERY, | ||
variables: { | ||
where: { column: 'EVENT_VERSION_ID', operator: 'EQ', value: eventId }, | ||
}, | ||
fetchPolicy: 'network-only', | ||
partialRefetch: true, | ||
}); | ||
return data.eventVersionParticipants as GetParticipantsByEventId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { gql } from '@apollo/client/core'; | ||
export const CREATE_EVENT_MUTATION = gql` | ||
mutation CreateEvent($input: EventInput!) { | ||
createEvent(input: $input) { | ||
id | ||
name | ||
type { | ||
name | ||
} | ||
eventStatus { | ||
id | ||
name | ||
} | ||
versions { | ||
data { | ||
id | ||
name | ||
agenda | ||
description | ||
slug | ||
dates { | ||
id | ||
date | ||
start_time | ||
end_time | ||
} | ||
} | ||
} | ||
category { | ||
id | ||
name | ||
slug | ||
position | ||
created_at | ||
updated_at | ||
} | ||
description | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { gql } from '@apollo/client/core'; | ||
|
||
export const EVENT_QUERY = gql` | ||
query Events( | ||
$first: Int | ||
$page: Int | ||
$orderBy: [QueryEventsOrderByOrderByClause!] | ||
) { | ||
events(first: $first, page: $page, orderBy: $orderBy) { | ||
data { | ||
id | ||
name | ||
type { | ||
name | ||
} | ||
eventStatus { | ||
id | ||
name | ||
} | ||
versions { | ||
data { | ||
id | ||
name | ||
agenda | ||
description | ||
slug | ||
dates { | ||
id | ||
date | ||
start_time | ||
end_time | ||
} | ||
total_attendees | ||
} | ||
} | ||
category { | ||
id | ||
name | ||
slug | ||
position | ||
created_at | ||
updated_at | ||
} | ||
description | ||
} | ||
paginatorInfo { | ||
total | ||
currentPage | ||
hasMorePages | ||
lastPage | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const EVENT_TYPES_QUERY = gql` | ||
query EventCategories { | ||
eventTypes { | ||
data { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const EVENT_CATEGORIES_QUERY = gql` | ||
query EventCategories { | ||
eventCategories { | ||
data { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const EVENT_PARTICIPANTS_QUERY = gql` | ||
query EventVersionParticipants( | ||
$where: QueryEventVersionParticipantsWhereWhereConditions | ||
) { | ||
eventVersionParticipants(where: $where) { | ||
data { | ||
participant { | ||
id | ||
people { | ||
id | ||
name | ||
tags { | ||
data { | ||
id | ||
name | ||
} | ||
} | ||
custom_fields { | ||
data { | ||
name | ||
value | ||
} | ||
} | ||
contacts { | ||
type { | ||
name | ||
} | ||
value | ||
} | ||
} | ||
} | ||
} | ||
paginatorInfo { | ||
total | ||
currentPage | ||
hasMorePages | ||
lastPage | ||
} | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { PaginatorInfo } from "./paginator"; | ||
|
||
export interface EventInputInterface { | ||
name: string; | ||
description: string; | ||
category_id: string | undefined; | ||
type_id: string | undefined; | ||
dates: { | ||
date: string; | ||
start_time: string; | ||
end_time: string; | ||
}[]; | ||
} | ||
|
||
export interface EventInterface { | ||
id: string; | ||
name: string; | ||
description: string; | ||
type: EventTypeInterface; | ||
eventStatus: EventStatusInterface; | ||
category: EventCategoryInterface; | ||
created_at?: string; | ||
updated_at?: string; | ||
} | ||
|
||
export interface GetEventResponse { | ||
data: EventInterface[]; | ||
paginatorInfo?: PaginatorInfo; | ||
} | ||
|
||
export type CreateEventResponse = Partial<EventInterface> & | ||
Partial<{ | ||
errors: { | ||
message: string; | ||
path: string[]; | ||
}[]; | ||
}>; | ||
|
||
export type ParticipantInterface = { | ||
id: string; | ||
people: { | ||
name: string; | ||
contacts: { | ||
type: { | ||
name: string | ||
}; | ||
value: string | number; | ||
}[]; | ||
tags: { | ||
data: { | ||
id: string; | ||
name: string; | ||
}[]; | ||
}; | ||
custom_fields: { | ||
name: string; | ||
value: string | number; | ||
}[]; | ||
}; | ||
company: { | ||
name: string; | ||
}; | ||
}; | ||
export type GetParticipantsByEventId = { | ||
data: { | ||
participant: ParticipantInterface; | ||
}[]; | ||
paginatorInfo?: PaginatorInfo; | ||
}[]; | ||
|
||
export interface EventCategoryInterface { | ||
id: string; | ||
name: string; | ||
} | ||
export interface EventStatusInterface { | ||
id: string; | ||
name: string; | ||
} | ||
export interface EventTypeInterface { | ||
id: string; | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters