65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
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) {
|
|
}
|
|
|
|
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.http.get(getUrl).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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|