import {Injectable} from '@angular/core'; import {AppConfig} from '../../app.config'; import {Promotion} from '../../models/model-interfaces'; import {HttpGateway} from '../http-gateway'; import {Observable} from 'rxjs'; @Injectable() export class PromotionService { hasUnprocessedPromotion = false; constructor(private httpGateway: HttpGateway, private config: AppConfig) { } getUnconfirmedPromotions(fraction?: string): Observable { return this.httpGateway.get(this.config.apiPromotionPath + '?inProgress=true&fractFilter=' + fraction); } checkUnconfirmedPromotions(fraction?: string) { this.getUnconfirmedPromotions(fraction).subscribe((items) => { if (items.length > 0) { this.hasUnprocessedPromotion = true; } }); } getSquadPromotions(squadId: string): Observable { return this.httpGateway.get(this.config.apiPromotionPath + '?squadId=' + squadId); } requestPromotion(promotion: Promotion): Observable { return this.httpGateway.post(this.config.apiPromotionPath, promotion); } updatePromotion(promotion): Observable { return this.httpGateway.patch(this.config.apiPromotionPath + '/' + promotion._id, promotion); } deletePromotion(promotionId) { return this.httpGateway.delete(this.config.apiPromotionPath + promotionId); } }