Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message comment #135

Merged
merged 2 commits into from
Dec 27, 2023
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
60 changes: 60 additions & 0 deletions src/modules/messages-comments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ClientType } from '../../index';
import {
MessageCommentInputInterface,
MessageCommentsInterface,
WhereCondition,
} from '../../types/';
import {
MESSAGE_COMMENT_MUTATION,
MESSAGE_COMMENT_UPDATE_MUTATION,
MESSAGE_COMMENT_DELETE_MUTATION,
} from '../../mutations/';
import { COMMENTS_QUERY } from '../../queries/';
export class MessagesComments {
constructor(protected client: ClientType) {}

public async addComment(
input: MessageCommentInputInterface
): Promise<MessageCommentsInterface> {
const response = await this.client.mutate({
mutation: MESSAGE_COMMENT_MUTATION,
variables: { input },
});

return response.data.addComment as MessageCommentsInterface;
}

public async updateComment(
id: string,
input: MessageCommentInputInterface
): Promise<MessageCommentsInterface> {
const response = await this.client.mutate({
mutation: MESSAGE_COMMENT_UPDATE_MUTATION,
variables: { id, input },
});

return response.data.updateComment as MessageCommentsInterface;
}

public async deleteComment(id: string): Promise<MessageCommentsInterface> {
const response = await this.client.mutate({
mutation: MESSAGE_COMMENT_DELETE_MUTATION,
variables: { id },
});

return response.data.deleteComment as MessageCommentsInterface;
}

public async getComments(
where: WhereCondition,
first: number,
page?: number
): Promise<MessageCommentsInterface[]> {
const response = await this.client.query({
query: COMMENTS_QUERY,
variables: { where, first, page },
});

return response.data.comments.data as MessageCommentsInterface[];
}
}
11 changes: 8 additions & 3 deletions src/modules/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
InteractionTypeInput,
HasAppModuleMessageWhereConditions,
OrderByMessage,
WhereCondition
WhereCondition,
} from '../../types';
import {
CREATE_MESSAGE_MUTATION,
Expand All @@ -16,9 +16,14 @@ import {
} from '../../mutations';

import { GET_MESSAGES_QUERY } from '../../queries';

import { MessagesComments } from '../messages-comments';
export class Messages {
constructor(protected client: ClientType) {}

public comments: MessagesComments;

constructor(protected client: ClientType) {
this.comments = new MessagesComments(client);
}

public async createMessage(
input: MessageInputInterface
Expand Down
1 change: 1 addition & 0 deletions src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './companies.mutation';
export * from './companies-branches.mutation';
export * from './follows.mutation';
export * from './people.mutation';
export * from './message-comment.mutation';
37 changes: 37 additions & 0 deletions src/mutations/message-comment.mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { gql } from '@apollo/client/core';

export const MESSAGE_COMMENT_MUTATION = gql`
mutation addComment($input: CommentInput!) {
addComment(input: $input) {
comments {
message
id
parent {
id
message
}
}
}
}
`;

export const MESSAGE_COMMENT_UPDATE_MUTATION = gql`
mutation updateComment($id: ID!, $input: CommentInput!) {
updateComment(id: $id, input: $input) {
comments {
message
id
parent {
id
message
}
}
}
}
`;

export const MESSAGE_COMMENT_DELETE_MUTATION = gql`
mutation deleteComment($id: ID!) {
deleteComment(id: $id)
}
`;
1 change: 1 addition & 0 deletions src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './companies-branches.query';
export * from './companies.query';
export * from './follows.query';
export * from './people.query';
export * from './message-comment.query';
27 changes: 27 additions & 0 deletions src/queries/message-comment.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { gql } from '@apollo/client/core';

export const COMMENTS_QUERY = gql`
query comments(
$where: QueryCommentsWhereWhereConditions
$first: Int!
$page: Int
) {
comments(where: $where, first: $first, page: $page) {
data {
comments {
message
id
parent {
id
message
}
}
}
paginatorInfo {
currentPage
lastPage
hasMorePages
}
}
}
`;
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './topics';
export * from './follows';
export * from './people';
export * from './contact';
export * from './message-comment';
16 changes: 16 additions & 0 deletions src/types/message-comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { UserInterface, CompanyInterface, MessagesInterface } from './index';

export interface MessageCommentInputInterface {
message_id: string;
message: string;
parent_id?: string;
}

export interface MessageCommentsInterface {
id: string;
user: UserInterface;
company: CompanyInterface;
parent?: MessageCommentsInterface;
messages: MessagesInterface;
message: string;
}