Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bakaphp/kanvas-core-js into feat/up…
Browse files Browse the repository at this point in the history
…date-get-company
  • Loading branch information
jerlyrosa committed Jan 17, 2024
2 parents 2842a9b + 7ae317d commit 98a95ed
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
SystemModules,
Follow,
People,
Notifications,
} from './modules';

import { setContext } from '@apollo/client/link/context';
Expand Down Expand Up @@ -114,7 +115,7 @@ export default class KanvasCore {
public companiesBranches: CompaniesBranches;
public follow: Follow;
public people: People;

public notifications: Notifications;
constructor(protected options: Options) {
this.client = new ApolloClient({
link: this.generateLink(),
Expand Down Expand Up @@ -145,6 +146,7 @@ export default class KanvasCore {
this.companiesBranches = new CompaniesBranches(this.client);
this.follow = new Follow(this.client);
this.people = new People(this.client);
this.notifications = new Notifications(this.client);
}
protected generateURL() {
return new HttpLink({ uri: this.options.url });
Expand Down
1 change: 1 addition & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './companies';
export * from './companies-branches';
export * from './follows';
export * from './people';
export * from './notifications';
97 changes: 97 additions & 0 deletions src/modules/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { ClientType } from 'index';

import {
NOTIFICATION_QUERY,
NOTIFICATION_TYPE_QUERY,
NOTIFICATION_CHANNEL_QUERY,
} from '../../queries';

import {
NotificationInterface,
NotificationTypeInterface,
NotificationChannelInterface,
NotificationEntityFilterInputInterface,
NotificationTypeFilterInputInterface,
WhereCondition,
} from '../../types';

import {
READ_ALL_NOTIFICATIONS_MUTATION,
SEND_NOTIFICATION_BASE_TEMPLATE_MUTATION,
SEND_NOTIFICATION_BY_MESSAGE_MUTATION,
} from '../../mutations';

export class Notifications {
constructor(protected client: ClientType) {}

public async getNotifications(
where: WhereCondition,
whereEntity: NotificationEntityFilterInputInterface,
whereType: NotificationTypeFilterInputInterface,
first: number,
page: number
): Promise<NotificationInterface[]> {
const response = await this.client.query({
query: NOTIFICATION_QUERY,
variables: { where, first, page, whereEntity, whereType },
});
return response.data.notifications.data as NotificationInterface[];
}

public async getNotificationTypes(
where: WhereCondition,
first: number,
page: number
): Promise<NotificationTypeInterface[]> {
const response = await this.client.query({
query: NOTIFICATION_TYPE_QUERY,
variables: { where, first, page },
});
return response.data.notificationTypes.data as NotificationTypeInterface[];
}

public async getNotificationChannels(
where: WhereCondition,
first: number,
page: number
): Promise<NotificationChannelInterface[]> {
const response = await this.client.query({
query: NOTIFICATION_CHANNEL_QUERY,
variables: { where, first, page },
});
return response.data.notificationChannels
.data as NotificationChannelInterface[];
}

public async readAllNotifications(): Promise<boolean> {
const response = await this.client.mutate({
mutation: READ_ALL_NOTIFICATIONS_MUTATION,
});
return response.data.readAllNotifications as boolean;
}

public async sendNotificationBaseTemplate(
template_name: string,
data: any,
via: string[],
users_id: number[]
): Promise<boolean> {
const response = await this.client.mutate({
mutation: SEND_NOTIFICATION_BASE_TEMPLATE_MUTATION,
variables: { template_name, data, via, users_id },
});
return response.data.sendNotificationBaseTemplate as boolean;
}

public async sendNotificationByMessage(
message: string,
via: string[],
users_id: number[]
): Promise<boolean> {
const response = await this.client.mutate({
mutation: SEND_NOTIFICATION_BY_MESSAGE_MUTATION,
variables: { message, via, users_id },
});
return response.data.sendNotificationByMessage as boolean;
}
}
3 changes: 2 additions & 1 deletion src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export * from './companies-branches.mutation';
export * from './follows.mutation';
export * from './people.mutation';
export * from './message-comment.mutation';
export * from './settings.mutation';
export * from './notification.mutation';
export * from './settings.mutation';
40 changes: 40 additions & 0 deletions src/mutations/notification.mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { gql } from '@apollo/client/core';

export const READ_ALL_NOTIFICATIONS_MUTATION = gql`
mutation readAllNotifications {
readAllNotifications
}
`;

export const SEND_NOTIFICATION_BASE_TEMPLATE_MUTATION = gql`
mutation sendNotificationBaseTemplate(
$template_name: String!
$data: Mixed!
$via: [String!]!
$users_id: [Int!]!
) {
sendNotificationBaseTemplate(
template_name: $template_name
data: $data
via: $via
users_id: $users_id
)
}
`;

export const SEND_NOTIFICATION_BY_MESSAGE_MUTATION = gql`
mutation sendNotificationByMessage(
$message: String!
$via: [String!]!
$users_id: [Int!]!
) {
sendNotificationByMessage(
message: $message
via: $via
users_id: $users_id
) {
sent
message
}
}
`;
1 change: 1 addition & 0 deletions src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './companies.query';
export * from './follows.query';
export * from './people.query';
export * from './message-comment.query';
export * from './notification.query';
156 changes: 156 additions & 0 deletions src/queries/notification.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { gql } from '@apollo/client/core';

export const NOTIFICATION_QUERY = gql`
query notifications(
$where: QueryNotificationsWhereWhereConditions
$whereEntity: NotificationEntityFilterInput
$whereType: NotificationTypeFilterInput
$orderBy: [QueryNotificationsOrderByOrderByClause!]
$first: Int
$page: Int
) {
notifications(
where: $where
whereEntity: $whereEntity
whereType: $whereType
orderBy: $orderBy
first: $first
page: $page
) {
data {
id
users {
id
displayname
email
}
fromUsers {
id
displayname
email
}
companies {
id
name
}
systemModule {
id
name
slug
}
types {
id
name
key
verb
event
description
template
weight
is_published
}
entity_id
entity
content
read
content_group
created_at
updated_at
}
paginatorInfo {
total
currentPage
hasMorePages
lastPage
count
}
}
}
`;

export const NOTIFICATION_TYPE_QUERY = gql`
query notificationTypes(
$where: QueryNotificationTypesWhereWhereConditions
$orderBy: [QueryNotificationTypesOrderByOrderByClause!]
$first: Int
$page: Int
) {
notificationTypes(
where: $where
orderBy: $orderBy
first: $first
page: $page
) {
data {
id
systemModule {
id
name
slug
}
parent {
id
name
key
verb
event
description
template
weight
is_published
}
channel {
id
name
slug
}
name
key
verb
event
description
template
weight
is_published
created_at
updated_at
}
paginatorInfo {
total
currentPage
hasMorePages
lastPage
count
}
}
}
`;

export const NOTIFICATION_CHANNEL_QUERY = gql`
query notificationChannels(
$where: QueryNotificationChannelsWhereWhereConditions
$orderBy: [QueryNotificationChannelsOrderByOrderByClause!]
$first: Int
$page: Int
) {
notificationChannels(
where: $where
orderBy: $orderBy
first: $first
page: $page
) {
data {
id
name
slug
}
paginatorInfo {
total
currentPage
hasMorePages
lastPage
count
}
}
}
`;
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './follows';
export * from './people';
export * from './contact';
export * from './message-comment';
export * from './notification';
Loading

0 comments on commit 98a95ed

Please sign in to comment.