File

projects/web-mev/src/app/core/user/user.service.ts

Description

User service

Index

Properties
Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

activate
activate(body)
Parameters :
Name Optional
body No
Returns : Observable<any>
changePassword
changePassword(body)
Parameters :
Name Optional
body No
Returns : Observable<any>
delete
delete(id: number)
Parameters :
Name Type Optional
id number No
Returns : any
get
get(id: number)
Parameters :
Name Type Optional
id number No
Returns : Observable<User>
getAll
getAll()
Returns : Observable<User[]>
register
register(body)
Parameters :
Name Optional
body No
Returns : Observable<any>
update
update(user: User, id: number)
Parameters :
Name Type Optional
user User No
id number No
Returns : any

Properties

Private Readonly API_URL
Default value : environment.apiUrl
import { Injectable } from '@angular/core';
import { environment } from '@environments/environment';
import { User } from '@app/_models/user';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';

/**
 * User service
 *
 */
@Injectable({
  providedIn: 'root'
})
export class UserService {
  private readonly API_URL = environment.apiUrl;

  constructor(private http: HttpClient) {}

  get(id: number): Observable<User> {
    return this.http.get<any>(`${this.API_URL}/users/${id}/`);
  }

  getAll(): Observable<User[]> {
    return this.http.get<any[]>(`${this.API_URL}/users/`);
  }

  register(body): Observable<any> {
    return this.http.post<any>(`${this.API_URL}/users/register/`, body);
  }

  activate(body): Observable<any> {
    return this.http.post<any>(`${this.API_URL}/users/activate/`, body);
  }

  changePassword(body): Observable<any> {
    return this.http.post<any>(`${this.API_URL}/users/change-password/`, body);
  }

  update(user: User, id: number) {
    return this.http.put<any>(
      `${this.API_URL}/users/${id}/`,
      JSON.stringify(user)
    );
  }

  delete(id: number) {
    return this.http.delete<any>(`${this.API_URL}/users/${id}/`);
  }
}

result-matching ""

    No results matching ""