Skip to content

Commit

Permalink
Merge pull request #329 from bakaphp/feat/CAD-121
Browse files Browse the repository at this point in the history
feat: Implement Event queries and mutations
  • Loading branch information
RivierGrullon authored Oct 18, 2024
2 parents 5a3f610 + 91c6346 commit 5db0abe
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.13.0",
"version": "0.14.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
Receiver,
Contact,
FilesystemMapper,
Event,
} from './modules';

import { setContext } from '@apollo/client/link/context';
Expand Down Expand Up @@ -128,6 +129,7 @@ export default class KanvasCore {
public receiver: Receiver;
public contact: Contact;
public filesystemMapper: FilesystemMapper;
public event: Event;

constructor(protected options: Options) {
this.client = new ApolloClient({
Expand Down Expand Up @@ -166,6 +168,7 @@ export default class KanvasCore {
this.receiver = new Receiver(this.options.url, this.options.key);
this.contact = new Contact(this.client);
this.filesystemMapper = new FilesystemMapper(this.client);
this.event = new Event(this.client);
}
protected generateURL() {
return new HttpLink({ uri: this.options.url });
Expand Down
83 changes: 83 additions & 0 deletions src/modules/event/index.ts
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;
}
}
1 change: 1 addition & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './organization';
export * from './tags';
export * from './receiver';
export * from './contact';
export * from './event';
40 changes: 40 additions & 0 deletions src/mutations/event.mutation.ts
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
}
}
`;
3 changes: 2 additions & 1 deletion src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export * from './notification.mutation';
export * from './settings.mutation';
export * from './organization.mutation'
export * from './tags.mutation';
export * from './mapper.mutation';
export * from './mapper.mutation';
export * from './event.mutation';
118 changes: 118 additions & 0 deletions src/queries/event.query.ts
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
}
}
}
`;
3 changes: 2 additions & 1 deletion src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export * from './notification.query';
export * from './channel.query';
export * from './tags.query';
export * from './contact.query';
export * from './mapper.query';
export * from './mapper.query';
export * from './event.query';
82 changes: 82 additions & 0 deletions src/types/events.ts
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;
}
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export * from './people';
export * from './contact';
export * from './message-comment';
export * from './notification';
export * from './mapper';
export * from './mapper';
export * from './events';

0 comments on commit 5db0abe

Please sign in to comment.