/// /// Copyright © 2016-2022 The Thingsboard Authors /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { defaultHttpOptionsFromConfig, RequestConfig } from '@core/http/http-utils'; import { Observable } from 'rxjs'; import { PageLink } from '@shared/models/page/page-link'; import { PageData } from '@shared/models/page/page-data'; import { Notification, NotificationRequest, NotificationRule, NotificationSettings, NotificationTarget, NotificationTemplate, SlackChanelType, SlackConversation } from '@shared/models/notification.models'; import { User } from '@shared/models/user.model'; @Injectable({ providedIn: 'root' }) export class NotificationService { constructor( private http: HttpClient ) { } public getNotifications(pageLink: PageLink, config?: RequestConfig): Observable> { return this.http.get>(`/api/notifications${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); } public markNotificationAsRead(id: string, config?: RequestConfig): Observable { return this.http.put(`/api/notification/${id}/read`, defaultHttpOptionsFromConfig(config)); } public createNotificationRequest(notification: NotificationRequest, config?: RequestConfig): Observable { return this.http.post('/api/notification/request', notification, defaultHttpOptionsFromConfig(config)); } public getNotificationRequestById(id: string, config?: RequestConfig): Observable { return this.http.get(`/api/notification/request/${id}`, defaultHttpOptionsFromConfig(config)); } public deleteNotificationRequest(id: string, config?: RequestConfig): Observable { return this.http.delete(`/api/notification/request/${id}`, defaultHttpOptionsFromConfig(config)); } public getNotificationRequests(pageLink: PageLink, config?: RequestConfig): Observable> { return this.http.get>('/api/notification/request/', defaultHttpOptionsFromConfig(config)); } public getNotificationSettings(config?: RequestConfig): Observable { return this.http.get('/api/notification/settings', defaultHttpOptionsFromConfig(config)); } public saveNotificationSettings(notificationSettings: NotificationSettings, config?: RequestConfig): Observable { return this.http.post('/api/notification/settings', notificationSettings, defaultHttpOptionsFromConfig(config)); } public listSlackConversations(type: SlackChanelType, config?: RequestConfig): Observable> { return this.http.get>(`/api/notification/slack/conversations?type=${type}`, defaultHttpOptionsFromConfig(config)); } public saveNotificationRule(notificationRule: NotificationRule, config?: RequestConfig): Observable { return this.http.post('/api/notification/rule', notificationRule, defaultHttpOptionsFromConfig(config)); } public getNotificationRuleById(id: string, config?: RequestConfig): Observable { return this.http.get(`/api/notification/rule/${id}`, defaultHttpOptionsFromConfig(config)); } public deleteNotificationRule(id: string, config?: RequestConfig): Observable { return this.http.delete(`/api/notification/rule/${id}`, defaultHttpOptionsFromConfig(config)); } public getNotificationRules(pageLink: PageLink, config?: RequestConfig): Observable> { return this.http.get>(`/api/notification/rules${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); } public saveNotificationTarget(notificationTarget: NotificationTarget, config?: RequestConfig): Observable { return this.http.post('/api/notification/target', notificationTarget, defaultHttpOptionsFromConfig(config)); } public getNotificationTargetById(id: string, config?: RequestConfig): Observable { return this.http.get(`/api/notification/target/${id}`, defaultHttpOptionsFromConfig(config)); } public deleteNotificationTarget(id: string, config?: RequestConfig): Observable { return this.http.delete(`/api/notification/target/${id}`, defaultHttpOptionsFromConfig(config)); } public getNotificationTargets(pageLink: PageLink, config?: RequestConfig): Observable> { return this.http.get>(`/api/notification/targets${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); } public getRecipientsForNotificationTargetConfig(notificationTarget: NotificationTarget, pageLink: PageLink, config?: RequestConfig): Observable> { return this.http.post>(`/api/notification/target/recipients${pageLink.toQuery()}`, notificationTarget, defaultHttpOptionsFromConfig(config)); } public saveNotificationTemplate(notificationTarget: NotificationTemplate, config?: RequestConfig): Observable { return this.http.post('/api/notification/template', notificationTarget, defaultHttpOptionsFromConfig(config)); } public getNotificationTemplateById(id: string, config?: RequestConfig): Observable { return this.http.get(`/api/notification/template/${id}`, defaultHttpOptionsFromConfig(config)); } public deleteNotificationTemplate(id: string, config?: RequestConfig): Observable { return this.http.delete(`/api/notification/template/${id}`, defaultHttpOptionsFromConfig(config)); } public getNotificationTemplates(pageLink: PageLink, config?: RequestConfig): Observable> { return this.http.get>(`/api/notification/templates${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config)); } }