import {Injectable} from '@angular/core'; import {Award} from '../../models/model-interfaces'; import {AppConfig} from '../../app.config'; import {HttpClient} from '../http-client'; @Injectable() export class AwardingService { hasUnprocessedAwards = false; constructor(private http: HttpClient, private config: AppConfig) { } getUnconfirmedAwards(fraction?: string) { return this.http.get(this.config.apiAwardPath + '?inProgress=true&fractFilter=' + fraction) .map(res => res.json()); } checkUnprocessedAwards(fraction?: string) { this.getUnconfirmedAwards(fraction).subscribe((items) => { if (items.length > 0) { this.hasUnprocessedAwards = true; } }); } /** * get awards array with populated decorations */ getUserAwardings(userId: string) { return this.http.get(this.config.apiAwardPath + '?userId=' + userId) .map(res => res.json()); } addAwarding(award: Award) { return this.http.post(this.config.apiAwardPath, award); } updateAward(award) { return this.http.patch(this.config.apiAwardPath + '/' + award._id, award) .map(res => res.json()); } requestAwarding(award: Award) { return this.http.post(this.config.apiRequestAwardPath, award); } deleteAwarding(awardingId) { return this.http.delete(this.config.apiAwardPath + '/' + awardingId); } }