datasurvey/src/main/webapp/app/entities/user/user.service.ts

46 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-07-03 21:48:27 +00:00
import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { createRequestOption } from 'app/core/request/request-util';
import { isPresent } from 'app/core/util/operators';
import { Pagination } from 'app/core/request/request.model';
import { IUser, getUserIdentifier } from './user.model';
import { map } from 'rxjs/operators';
export type EntityResponseType = HttpResponse<IUser>;
2021-07-03 21:48:27 +00:00
@Injectable({ providedIn: 'root' })
export class UserService {
private resourceUrl = this.applicationConfigService.getEndpointFor('api/users');
constructor(private http: HttpClient, private applicationConfigService: ApplicationConfigService) {}
query(req?: Pagination): Observable<HttpResponse<IUser[]>> {
const options = createRequestOption(req);
return this.http.get<IUser[]>(this.resourceUrl, { params: options, observe: 'response' });
}
2021-08-01 21:25:27 +00:00
retrieveAllPublicUsers(): Observable<IUser[]> {
return this.http.get<IUser[]>(this.resourceUrl);
}
2021-07-03 21:48:27 +00:00
addUserToCollectionIfMissing(userCollection: IUser[], ...usersToCheck: (IUser | null | undefined)[]): IUser[] {
const users: IUser[] = usersToCheck.filter(isPresent);
if (users.length > 0) {
const userCollectionIdentifiers = userCollection.map(userItem => getUserIdentifier(userItem)!);
const usersToAdd = users.filter(userItem => {
const userIdentifier = getUserIdentifier(userItem);
if (userIdentifier == null || userCollectionIdentifiers.includes(userIdentifier)) {
return false;
}
userCollectionIdentifiers.push(userIdentifier);
return true;
});
return [...usersToAdd, ...userCollection];
}
return userCollection;
}
}