argos/dmp-frontend/src/app/core/services/user/user.service.ts

75 lines
3.3 KiB
TypeScript
Raw Normal View History

import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
2018-02-01 15:04:36 +01:00
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
2019-01-18 18:03:45 +01:00
import { environment } from '../../../../environments/environment';
import { DataTableData } from '../../model/data-table/data-table-data';
import { DataTableRequest } from '../../model/data-table/data-table-request';
import { UserListingModel } from '../../model/user/user-listing';
import { UserCriteria } from '../../query/user/user-criteria';
import { BaseHttpService } from '../http/base-http.service';
import { ConfigurationService } from '../configuration/configuration.service';
import { UserCredentialModel } from '@app/core/model/user/user-credential';
2018-02-01 15:04:36 +01:00
@Injectable()
2019-01-18 18:03:45 +01:00
export class UserService {
2018-02-01 15:04:36 +01:00
2018-10-05 17:00:54 +02:00
private actionUrl: string;
2020-10-07 15:40:18 +02:00
private headers = new HttpHeaders();
2018-02-01 15:04:36 +01:00
constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) {
2018-02-01 15:04:36 +01:00
this.actionUrl = configurationService.server + 'user/';
2018-10-05 17:00:54 +02:00
}
2018-02-01 15:04:36 +01:00
2018-10-05 17:00:54 +02:00
getPaged(dataTableRequest: DataTableRequest<UserCriteria>): Observable<DataTableData<UserListingModel>> {
return this.http.post<DataTableData<UserListingModel>>(this.actionUrl + 'getPaged', JSON.stringify(dataTableRequest), { headers: this.headers });
}
2018-02-01 15:04:36 +01:00
2018-10-05 17:00:54 +02:00
getUser(id: String): Observable<UserListingModel> {
return this.http.get<UserListingModel>(this.actionUrl + id, { headers: this.headers });
}
2018-08-24 17:21:02 +02:00
getEmails(id: String): Observable<UserCredentialModel[]> {
return this.http.get<UserCredentialModel[]>(`${this.actionUrl}${id}/emails`, { headers: this.headers });
}
2018-10-05 17:00:54 +02:00
updateRoles(itemToUpdate: UserListingModel): Observable<UserListingModel> {
return this.http.post<UserListingModel>(this.actionUrl + 'updateRoles', JSON.stringify(itemToUpdate), { headers: this.headers });
}
2018-02-01 15:04:36 +01:00
2018-10-05 17:00:54 +02:00
delete(id: String): Observable<any> {
return this.http.delete<any>(this.actionUrl + id, { headers: this.headers });
}
2018-03-21 14:15:06 +01:00
2018-10-05 17:00:54 +02:00
getRecentActivity(): Observable<any[]> {
return this.http.get<any[]>(this.actionUrl + 'recentActivity', { headers: this.headers });
}
2018-08-30 13:09:36 +02:00
2018-10-05 17:00:54 +02:00
updateUserSettings(value: any): Observable<any[]> {
return this.http.post<any[]>(this.actionUrl + 'settings', value, { headers: this.headers });
}
getCollaboratorsPaged(dataTableRequest: DataTableRequest<UserCriteria>): Observable<DataTableData<UserListingModel>> {
return this.http.post<DataTableData<UserListingModel>>(this.actionUrl + 'getCollaboratorsPaged', JSON.stringify(dataTableRequest), { headers: this.headers });
}
getFromEmail(email: string): Observable<UserListingModel> {
return this.http.post<UserListingModel>(this.actionUrl + 'find', email, {headers: this.headers});
}
public registerDOIToken(code: string, redirectUri: string): Observable<any> {
const url = this.actionUrl + 'registerDOIToken';
return this.http.post(url, {zenodoRequest: {code: code}, redirectUri: redirectUri}, { headers: this.headers });
}
2020-04-10 16:16:37 +02:00
public deleteDOIToken(): Observable<any> {
const url = this.actionUrl + 'deleteDOIToken';
return this.http.delete(url, { headers: this.headers });
}
downloadCSV(): Observable<HttpResponse<Blob>> {
let headerCsv: HttpHeaders = this.headers.set('Content-Type', 'application/csv')
return this.httpClient.get(this.actionUrl + 'getCsv/', { responseType: 'blob', observe: 'response', headers: headerCsv });
}
2018-02-01 15:04:36 +01:00
}