30 lines
862 B
TypeScript
30 lines
862 B
TypeScript
|
import { HttpClient } from '@angular/common/http';
|
||
|
import { inject, Injectable } from '@angular/core';
|
||
|
import { environment } from '../../../environments/environment';
|
||
|
import TwitchRedemption from '../models/twitch-redemption';
|
||
|
import { of } from 'rxjs';
|
||
|
|
||
|
@Injectable({
|
||
|
providedIn: 'root'
|
||
|
})
|
||
|
export class TwitchRedemptionService {
|
||
|
private http = inject(HttpClient);
|
||
|
private twitchRedemptions: TwitchRedemption[] = [];
|
||
|
private loaded = false
|
||
|
|
||
|
fetch(force: boolean = false) {
|
||
|
if (!force && this.loaded)
|
||
|
return of(this.twitchRedemptions);
|
||
|
|
||
|
const $ = this.http.get<TwitchRedemption[]>(environment.API_HOST + '/twitch/redemptions', {
|
||
|
headers: {
|
||
|
'Authorization': 'Bearer ' + localStorage.getItem('jwt'),
|
||
|
}
|
||
|
});
|
||
|
$.subscribe(d => {
|
||
|
this.twitchRedemptions = d;
|
||
|
this.loaded = true;
|
||
|
});
|
||
|
return $;
|
||
|
}
|
||
|
}
|