### File

`src/app/Services/profile.service.ts`

### Constructor

`constructor(tokenStorage: TokenStorageService, http: HttpClient)`

### Methods

Public getUserData
`getUserData()`
Function to get all Userdata Returns: `any` Observable

Public updateProfile
`updateProfile(username: string, password: number)`
Function to update user profile Parameters : username password Returns: `any` Observable

Public addTelegramId
`addTelegramId(telegram_user_id: string)`
Function to add a telegram id Parameters : telegramUserID Returns: `any` Observable

Public addCronString
`addCronString(cron: string)`
Function to add a cron string for automatic updates Parameters : cronString Returns: `any` Observable

    import { HttpClient, HttpHeaders } from '@angular/common/http';
    import { Injectable } from '@angular/core';
    import { Observable } from 'rxjs';
    import { TokenStorageService } from './token.service';

    const API_URL = 'https://gruppe1.testsites.info/api/';

    @Injectable({
      providedIn: 'root',
    })
    export class ProfileService {
      constructor(
        private tokenStorage: TokenStorageService,
        private http: HttpClient
      ) {}

      /**
       * Function to get all Userdata
       * @returns Observable
       */
      public getUserData(): Observable<any> {
        return this.http.get(API_URL + 'user', {
          headers: new HttpHeaders({
            'Content-Type': 'application/json',
            Authorization: 'Bearer ' + this.tokenStorage.getToken(),
          }),
          responseType: 'text',
        });
      }

      /**
       * Function to update user profile
       * @param  {string} username
       * @param  {number} password
       * @returns Observable
       */
      public updateProfile(username: string, password: number): Observable<any> {
        return this.http.put(
          API_URL + 'user',
          {
            username,
            password,
          },
          {
            headers: new HttpHeaders({
              'Content-Type': 'application/json',
              Authorization: 'Bearer ' + this.tokenStorage.getToken(),
            }),
          }
        );
      }

      /**
       * Function to add a telegram id
       * @param  {string} telegramUserID
       * @returns Observable
       */
      public addTelegramId(telegram_user_id: string): Observable<any> {
        return this.http.post(
          API_URL + 'telegram',
          {
            telegram_user_id,
          },
          {
            headers: new HttpHeaders({
              'Content-Type': 'application/json',
              Authorization: 'Bearer ' + this.tokenStorage.getToken(),
            }),
          }
        );
      }

      /**
       * Function to add a cron string for automatic updates
       * @param  {string} cronString
       * @returns Observable
       */
      public addCronString(cron: string): Observable<any> {
        return this.http.put(
          'https://gruppe1.testsites.info/api/user' + '/setCron',
          {
            cron,
          },
          {
            headers: new HttpHeaders({
              'Content-Type': 'application/json',
              Authorization: 'Bearer ' + this.tokenStorage.getToken(),
            }),
          }
        );
      }
    }

# results matching ""

# No results matching ""