opt-cc/static/src/app/request/confirm-promotion/confirm-promotion.component.ts

57 lines
1.7 KiB
TypeScript

import {Component} from "@angular/core";
import {Promotion, Rank} from "../../models/model-interfaces";
import {RankService} from "../../services/rank-service/rank.service";
import {PromotionService} from "../../services/promotion-service/promotion.service";
@Component({
templateUrl: './confirm-promotion.component.html',
styleUrls: ['./confirm-promotion.component.css'],
})
export class ConfirmPromotionComponent {
showSuccessLabel = false;
ranks: Rank[];
promotions: Promotion[];
constructor(private rankService: RankService,
private promotionService: PromotionService) {
}
ngOnInit() {
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
// 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) {
const updateObject = {
_id: promotion._id,
confirmed: decision ? 1 : 2
};
this.promotionService.updatePromotion(updateObject).subscribe(res => {
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
this.promotionService.getUnconfirmedPromotions(currentUser.squad.fraction).subscribe(promotions => {
this.promotions = promotions;
if (promotions.length < 1) {
this.promotionService.hasUnprocessedPromotion = false;
}
this.showSuccessLabel = true;
setTimeout(() => {
this.showSuccessLabel = false;
}, 2000);
});
});
}
}