-
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 branch 'main' of github.com:bakaphp/kanvas-core-js into feat/up…
…date-get-company
- Loading branch information
Showing
9 changed files
with
358 additions
and
2 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,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; | ||
} | ||
} |
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 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 | ||
} | ||
} | ||
`; |
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,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 | ||
} | ||
fromUsers { | ||
id | ||
displayname | ||
} | ||
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 | ||
} | ||
} | ||
} | ||
`; |
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
Oops, something went wrong.