54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {Award} from '../../models/model-interfaces';
|
|
import {AwardingService} from '../../services/army-management/awarding.service';
|
|
import {LoginService} from '../../services/app-user-service/login-service';
|
|
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
|
|
|
|
|
|
@Component({
|
|
templateUrl: './confirm-award.component.html',
|
|
styleUrls: ['./confirm-award.component.scss'],
|
|
})
|
|
export class ConfirmAwardComponent implements OnInit {
|
|
|
|
awards: Award[];
|
|
|
|
constructor(private awardingService: AwardingService,
|
|
private loginService: LoginService,
|
|
private snackBarService: SnackBarService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
const currentUser = this.loginService.getCurrentUser();
|
|
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
|
|
this.awards = awards;
|
|
});
|
|
}
|
|
|
|
confirm(award: Award, decision: boolean, reason: string, rejectReason: string) {
|
|
const updateObject = {
|
|
_id: award._id,
|
|
confirmed: decision ? 1 : 2
|
|
};
|
|
|
|
if (rejectReason) {
|
|
updateObject['rejectReason'] = rejectReason;
|
|
}
|
|
|
|
if (reason && reason !== award.reason) {
|
|
updateObject['reason'] = reason;
|
|
}
|
|
|
|
this.awardingService.updateAward(updateObject).subscribe(res => {
|
|
const currentUser = this.loginService.getCurrentUser();
|
|
this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
|
|
this.awards = awards;
|
|
if (awards.length < 1) {
|
|
this.awardingService.hasUnprocessedAwards = false;
|
|
}
|
|
this.snackBarService.showSuccess('generic.save.success');
|
|
});
|
|
});
|
|
}
|
|
}
|