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