2017-05-10 11:04:06 +02:00
|
|
|
import {Injectable} from "@angular/core";
|
2017-07-23 10:57:46 +02:00
|
|
|
import {Award} from "../../models/model-interfaces";
|
2017-05-10 11:04:06 +02:00
|
|
|
import {AppConfig} from "../../app.config";
|
|
|
|
import {HttpClient} from "../http-client";
|
|
|
|
|
|
|
|
@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-02-26 09:04:27 +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) {
|
|
|
|
this.hasUnprocessedAwards = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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-02-26 09:04:27 +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) {
|
2017-08-01 23:52:10 +02: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-02-26 09:04:27 +01:00
|
|
|
.map(res => res.json())
|
2017-06-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
requestAwarding(award: Award) {
|
2017-08-01 23:52:10 +02: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) {
|
2017-08-01 23:52:10 +02:00
|
|
|
return this.http.delete(this.config.apiAwardPath + '/' + awardingId)
|
2017-05-10 11:04:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|