45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
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<Promotion[]> {
|
|
return this.httpGateway.get<Promotion[]>(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<Promotion[]> {
|
|
return this.httpGateway.get<Promotion[]>(this.config.apiPromotionPath + '?squadId=' + squadId);
|
|
}
|
|
|
|
requestPromotion(promotion: Promotion): Observable<Promotion> {
|
|
return this.httpGateway.post<Promotion>(this.config.apiPromotionPath, promotion);
|
|
}
|
|
|
|
updatePromotion(promotion): Observable<Promotion> {
|
|
return this.httpGateway.patch<Promotion>(this.config.apiPromotionPath + '/' + promotion._id, promotion);
|
|
}
|
|
|
|
deletePromotion(promotionId) {
|
|
return this.httpGateway.delete(this.config.apiPromotionPath + promotionId);
|
|
}
|
|
}
|