2018-03-07 11:56:50 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Award} from '../../models/model-interfaces';
|
|
|
|
import {AppConfig} from '../../app.config';
|
|
|
|
import {HttpClient} from '../http-client';
|
2017-05-10 11:04:06 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AwardingService {
|
|
|
|
|
2017-07-23 10:57:46 +02:00
|
|
|
hasUnprocessedAwards = false;
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
constructor(private http: HttpClient,
|
|
|
|
private config: AppConfig) {
|
|
|
|
}
|
|
|
|
|
2017-06-10 22:07:32 +02:00
|
|
|
getUnconfirmedAwards(fraction?: string) {
|
2017-08-01 23:52:10 +02:00
|
|
|
return this.http.get(this.config.apiAwardPath + '?inProgress=true&fractFilter=' + fraction)
|
2018-03-11 09:39:05 +01:00
|
|
|
.map(res => res.json());
|
2017-06-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
|
2017-07-27 16:38:35 +02:00
|
|
|
checkUnprocessedAwards(fraction?: string) {
|
|
|
|
this.getUnconfirmedAwards(fraction).subscribe((items) => {
|
|
|
|
if (items.length > 0) {
|
2018-03-07 11:56:50 +01:00
|
|
|
this.hasUnprocessedAwards = true;
|
2017-07-27 16:38:35 +02:00
|
|
|
}
|
2018-03-07 11:56:50 +01:00
|
|
|
});
|
2017-07-27 16:38:35 +02:00
|
|
|
}
|
|
|
|
|
2018-06-18 20:44:18 +02:00
|
|
|
getUnprocessedSquadAwards(squadId?: string) {
|
|
|
|
return this.http.get(this.config.apiAwardSquadPath.concat('/').concat(squadId))
|
|
|
|
.map(res => res.json());
|
|
|
|
}
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
/**
|
|
|
|
* get awards array with populated decorations
|
|
|
|
*/
|
|
|
|
getUserAwardings(userId: string) {
|
2017-08-01 23:52:10 +02:00
|
|
|
return this.http.get(this.config.apiAwardPath + '?userId=' + userId)
|
2018-03-11 09:39:05 +01:00
|
|
|
.map(res => res.json());
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 22:07:32 +02:00
|
|
|
addAwarding(award: Award) {
|
2018-03-07 11:56:50 +01:00
|
|
|
return this.http.post(this.config.apiAwardPath, award);
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 22:07:32 +02:00
|
|
|
updateAward(award) {
|
2017-08-01 23:52:10 +02:00
|
|
|
return this.http.patch(this.config.apiAwardPath + '/' + award._id, award)
|
2018-03-11 09:39:05 +01:00
|
|
|
.map(res => res.json());
|
2017-06-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
requestAwarding(award: Award) {
|
2018-03-07 11:56:50 +01:00
|
|
|
return this.http.post(this.config.apiRequestAwardPath, award);
|
2017-06-09 18:30:35 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
deleteAwarding(awardingId) {
|
2018-03-07 11:56:50 +01:00
|
|
|
return this.http.delete(this.config.apiAwardPath + '/' + awardingId);
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|