diff options
Diffstat (limited to 'client/src/app/shared/users/user.service.ts')
-rw-r--r-- | client/src/app/shared/users/user.service.ts | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index d9b81c181..cc5c051f1 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Observable } from 'rxjs' | 1 | import { from, Observable } from 'rxjs' |
2 | import { catchError, map } from 'rxjs/operators' | 2 | import { catchError, concatMap, map, toArray } from 'rxjs/operators' |
3 | import { HttpClient, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpParams } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
5 | import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' | 5 | import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' |
@@ -153,15 +153,26 @@ export class UserService { | |||
153 | ) | 153 | ) |
154 | } | 154 | } |
155 | 155 | ||
156 | updateUsers (users: User[], userUpdate: UserUpdate) { | ||
157 | return from(users) | ||
158 | .pipe( | ||
159 | concatMap(u => this.authHttp.put(UserService.BASE_USERS_URL + u.id, userUpdate)), | ||
160 | toArray(), | ||
161 | catchError(err => this.restExtractor.handleError(err)) | ||
162 | ) | ||
163 | } | ||
164 | |||
156 | getUser (userId: number) { | 165 | getUser (userId: number) { |
157 | return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId) | 166 | return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId) |
158 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 167 | .pipe(catchError(err => this.restExtractor.handleError(err))) |
159 | } | 168 | } |
160 | 169 | ||
161 | getUsers (pagination: RestPagination, sort: SortMeta): Observable<ResultList<User>> { | 170 | getUsers (pagination: RestPagination, sort: SortMeta, search?: string): Observable<ResultList<User>> { |
162 | let params = new HttpParams() | 171 | let params = new HttpParams() |
163 | params = this.restService.addRestGetParams(params, pagination, sort) | 172 | params = this.restService.addRestGetParams(params, pagination, sort) |
164 | 173 | ||
174 | if (search) params = params.append('search', search) | ||
175 | |||
165 | return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params }) | 176 | return this.authHttp.get<ResultList<User>>(UserService.BASE_USERS_URL, { params }) |
166 | .pipe( | 177 | .pipe( |
167 | map(res => this.restExtractor.convertResultListDateToHuman(res)), | 178 | map(res => this.restExtractor.convertResultListDateToHuman(res)), |
@@ -170,21 +181,38 @@ export class UserService { | |||
170 | ) | 181 | ) |
171 | } | 182 | } |
172 | 183 | ||
173 | removeUser (user: { id: number }) { | 184 | removeUser (usersArg: User | User[]) { |
174 | return this.authHttp.delete(UserService.BASE_USERS_URL + user.id) | 185 | const users = Array.isArray(usersArg) ? usersArg : [ usersArg ] |
175 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 186 | |
187 | return from(users) | ||
188 | .pipe( | ||
189 | concatMap(u => this.authHttp.delete(UserService.BASE_USERS_URL + u.id)), | ||
190 | toArray(), | ||
191 | catchError(err => this.restExtractor.handleError(err)) | ||
192 | ) | ||
176 | } | 193 | } |
177 | 194 | ||
178 | banUser (user: { id: number }, reason?: string) { | 195 | banUsers (usersArg: User | User[], reason?: string) { |
179 | const body = reason ? { reason } : {} | 196 | const body = reason ? { reason } : {} |
197 | const users = Array.isArray(usersArg) ? usersArg : [ usersArg ] | ||
180 | 198 | ||
181 | return this.authHttp.post(UserService.BASE_USERS_URL + user.id + '/block', body) | 199 | return from(users) |
182 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 200 | .pipe( |
201 | concatMap(u => this.authHttp.post(UserService.BASE_USERS_URL + u.id + '/block', body)), | ||
202 | toArray(), | ||
203 | catchError(err => this.restExtractor.handleError(err)) | ||
204 | ) | ||
183 | } | 205 | } |
184 | 206 | ||
185 | unbanUser (user: { id: number }) { | 207 | unbanUsers (usersArg: User | User[]) { |
186 | return this.authHttp.post(UserService.BASE_USERS_URL + user.id + '/unblock', {}) | 208 | const users = Array.isArray(usersArg) ? usersArg : [ usersArg ] |
187 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 209 | |
210 | return from(users) | ||
211 | .pipe( | ||
212 | concatMap(u => this.authHttp.post(UserService.BASE_USERS_URL + u.id + '/unblock', {})), | ||
213 | toArray(), | ||
214 | catchError(err => this.restExtractor.handleError(err)) | ||
215 | ) | ||
188 | } | 216 | } |
189 | 217 | ||
190 | private formatUser (user: User) { | 218 | private formatUser (user: User) { |