Added services and resolvers for redemptions and related.
This commit is contained in:
30
src/app/shared/services/twitch-redemption.service.ts
Normal file
30
src/app/shared/services/twitch-redemption.service.ts
Normal file
@ -0,0 +1,30 @@
|
||||
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 $;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user