58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {Promotion, Rank} from '../../models/model-interfaces';
|
|
import {RankService} from '../../services/army-management/rank.service';
|
|
import {PromotionService} from '../../services/army-management/promotion.service';
|
|
import {LoginService} from '../../services/app-user-service/login-service';
|
|
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
|
|
|
|
|
|
@Component({
|
|
templateUrl: './confirm-promotion.component.html',
|
|
styleUrls: ['./confirm-promotion.component.scss'],
|
|
})
|
|
export class ConfirmPromotionComponent implements OnInit {
|
|
|
|
ranks: Rank[];
|
|
|
|
promotions: Promotion[];
|
|
|
|
constructor(private rankService: RankService,
|
|
private promotionService: PromotionService,
|
|
private loginService: LoginService,
|
|
private snackBarService: SnackBarService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
const currentUser = this.loginService.getCurrentUser();
|
|
// show only current users fraction promotions
|
|
this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {
|
|
this.ranks = ranks;
|
|
});
|
|
this.promotionService.getUnconfirmedPromotions(currentUser.squad.fraction).subscribe(promotions => {
|
|
this.promotions = promotions;
|
|
});
|
|
}
|
|
|
|
confirm(promotion: Promotion, decision: boolean, rejectReason?: string) {
|
|
const updateObject = {
|
|
_id: promotion._id,
|
|
confirmed: decision ? 1 : 2
|
|
};
|
|
|
|
if (rejectReason) {
|
|
updateObject['rejectReason'] = rejectReason;
|
|
}
|
|
|
|
this.promotionService.updatePromotion(updateObject).subscribe(res => {
|
|
const currentUser = this.loginService.getCurrentUser();
|
|
this.promotionService.getUnconfirmedPromotions(currentUser.squad.fraction).subscribe(promotions => {
|
|
this.promotions = promotions;
|
|
if (promotions.length < 1) {
|
|
this.promotionService.hasUnprocessedPromotion = false;
|
|
}
|
|
this.snackBarService.showSuccess('generic.save.success');
|
|
});
|
|
});
|
|
}
|
|
}
|