11import { HttpClient , HttpParams } from '@angular/common/http' ;
22import { Injectable } from '@angular/core' ;
3- import { Observable } from 'rxjs' ;
3+ import { throwError } from 'rxjs' ;
44
55import { environment } from 'environments/environment' ;
66import { Channel , PageFilters } from 'app/common/interfaces/mainflux.interface' ;
77import { NotificationsService } from 'app/common/services/notifications/notifications.service' ;
88
99const defLimit : number = 10 ;
10- const defConnLimit : number = 5 ;
1110
1211@Injectable ( )
1312export class ChannelsService {
@@ -28,7 +27,7 @@ export class ChannelsService {
2827 err => {
2928 this . notificationsService . error ( 'Failed to create Channel' ,
3029 `Error: ${ err . status } - ${ err . statusText } ` ) ;
31- return Observable . throw ( err ) ;
30+ return throwError ( err ) ;
3231 } ,
3332 ) ;
3433 }
@@ -44,7 +43,7 @@ export class ChannelsService {
4443 err => {
4544 this . notificationsService . error ( 'Failed to create Channels' ,
4645 `Error: ${ err . status } - ${ err . statusText } ` ) ;
47- return Observable . throw ( err ) ;
46+ return throwError ( err ) ;
4847 } ,
4948 ) ;
5049 }
@@ -60,7 +59,7 @@ export class ChannelsService {
6059 err => {
6160 this . notificationsService . error ( 'Failed to fetch Channel' ,
6261 `Error: ${ err . status } - ${ err . statusText } ` ) ;
63- return Observable . throw ( err ) ;
62+ return throwError ( err ) ;
6463 } ,
6564 ) ;
6665 }
@@ -97,7 +96,7 @@ export class ChannelsService {
9796 err => {
9897 this . notificationsService . error ( 'Failed to fetch Channels' ,
9998 `Error: ${ err . status } - ${ err . statusText } ` ) ;
100- return Observable . throw ( err ) ;
99+ return throwError ( err ) ;
101100 } ,
102101 ) ;
103102 }
@@ -113,7 +112,7 @@ export class ChannelsService {
113112 err => {
114113 this . notificationsService . error ( 'Failed to edit Channel' ,
115114 `Error: ${ err . status } - ${ err . statusText } ` ) ;
116- return Observable . throw ( err ) ;
115+ return throwError ( err ) ;
117116 } ,
118117 ) ;
119118 }
@@ -129,7 +128,7 @@ export class ChannelsService {
129128 err => {
130129 this . notificationsService . error ( 'Failed to delete Channel' ,
131130 `Error: ${ err . status } - ${ err . statusText } ` ) ;
132- return Observable . throw ( err ) ;
131+ return throwError ( err ) ;
133132 } ,
134133 ) ;
135134 }
@@ -145,7 +144,7 @@ export class ChannelsService {
145144 err => {
146145 this . notificationsService . error ( 'Failed to connect Thing to Channel' ,
147146 `Error: ${ err . status } - ${ err . statusText } ` ) ;
148- return Observable . throw ( err ) ;
147+ return throwError ( err ) ;
149148 } ,
150149 ) ;
151150 }
@@ -163,9 +162,9 @@ export class ChannelsService {
163162 )
164163 . catch (
165164 err => {
166- this . notificationsService . error ( 'Failed to connect Things to Channels ' ,
165+ this . notificationsService . error ( 'Failed to connect Thing(s) to Channel(s) ' ,
167166 `Error: ${ err . status } - ${ err . statusText } ` ) ;
168- return Observable . throw ( err ) ;
167+ return throwError ( err ) ;
169168 } ,
170169 ) ;
171170 }
@@ -181,14 +180,34 @@ export class ChannelsService {
181180 err => {
182181 this . notificationsService . error ( 'Failed to disconnect Thing from Channel' ,
183182 `Error: ${ err . status } - ${ err . statusText } ` ) ;
184- return Observable . throw ( err ) ;
183+ return throwError ( err ) ;
184+ } ,
185+ ) ;
186+ }
187+
188+ disconnectThings ( channelIDs : string [ ] , thingIDs : string [ ] ) {
189+ const conReq = {
190+ channel_ids : channelIDs ,
191+ thing_ids : thingIDs ,
192+ } ;
193+ return this . http . put ( `${ environment . disconnectUrl } ` , conReq )
194+ . map (
195+ resp => {
196+ return resp ;
197+ } ,
198+ )
199+ . catch (
200+ err => {
201+ this . notificationsService . error ( 'Failed to disconnect Thing(s) from Channel(s)' ,
202+ `Error: ${ err . status } - ${ err . statusText } ` ) ;
203+ return throwError ( err ) ;
185204 } ,
186205 ) ;
187206 }
188207
189208 connectedThings ( chanID : string , offset ?: number , limit ?: number ) {
190209 offset = offset || 0 ;
191- limit = limit || defConnLimit ;
210+ limit = limit || defLimit ;
192211
193212 const params = new HttpParams ( )
194213 . set ( 'offset' , offset . toString ( ) )
@@ -204,14 +223,14 @@ export class ChannelsService {
204223 err => {
205224 this . notificationsService . error ( 'Failed to fetch connected Things to the Channel' ,
206225 `Error: ${ err . status } - ${ err . statusText } ` ) ;
207- return Observable . throw ( err ) ;
226+ return throwError ( err ) ;
208227 } ,
209228 ) ;
210229 }
211230
212231 disconnectedThings ( chanID : string , offset ?: number , limit ?: number ) {
213232 offset = offset || 0 ;
214- limit = limit || defConnLimit ;
233+ limit = limit || defLimit ;
215234
216235 const params = new HttpParams ( )
217236 . set ( 'offset' , offset . toString ( ) )
@@ -228,7 +247,7 @@ export class ChannelsService {
228247 err => {
229248 this . notificationsService . error ( 'Failed to fetch not connected Things to the Channel' ,
230249 `Error: ${ err . status } - ${ err . statusText } ` ) ;
231- return Observable . throw ( err ) ;
250+ return throwError ( err ) ;
232251 } ,
233252 ) ;
234253 }
0 commit comments