Cleaner pdf getUnifiedChanges solution

Fixes a bug where cercain amendments where causing an
"titleChange of undefined" error
This commit is contained in:
Sean 2020-08-10 14:17:43 +02:00
parent ccc3e38427
commit 09a10c7e92

View File

@ -164,7 +164,7 @@ export class MotionPdfService {
private createTitle(motion: ViewMotion, crMode: ChangeRecoMode, lineLength: number): object { private createTitle(motion: ViewMotion, crMode: ChangeRecoMode, lineLength: number): object {
// summary of change recommendations (for motion diff version only) // summary of change recommendations (for motion diff version only)
const changes = this.getUnifiedChanges(motion, lineLength); const changes = this.getUnifiedChanges(motion, lineLength);
const titleChange = changes.find(change => change.isTitleChange()); const titleChange = changes.find(change => change?.isTitleChange());
const changedTitle = this.changeRecoRepo.getTitleWithChanges(motion.title, titleChange, crMode); const changedTitle = this.changeRecoRepo.getTitleWithChanges(motion.title, titleChange, crMode);
const identifier = motion.identifier ? ' ' + motion.identifier : ''; const identifier = motion.identifier ? ' ' + motion.identifier : '';
@ -630,26 +630,19 @@ export class MotionPdfService {
* @returns * @returns
*/ */
private getUnifiedChanges(motion: ViewMotion, lineLength: number): ViewUnifiedChange[] { private getUnifiedChanges(motion: ViewMotion, lineLength: number): ViewUnifiedChange[] {
const changeRecosOfMotion = this.changeRecoRepo.getChangeRecoOfMotion(motion.id); const motionChangeRecos = this.changeRecoRepo.getChangeRecoOfMotion(motion.id);
if (changeRecosOfMotion && changeRecosOfMotion.length) { const motionAmendments = this.motionRepo.getAmendmentsInstantly(motion.id).flatMap((amendment: ViewMotion) => {
return changeRecosOfMotion
.concat(
this.motionRepo.getAmendmentsInstantly(motion.id).flatMap((amendment: ViewMotion) => {
const changeRecos = this.changeRecoRepo const changeRecos = this.changeRecoRepo
.getChangeRecoOfMotion(amendment.id) .getChangeRecoOfMotion(amendment.id)
.filter(reco => reco.showInFinalView()); .filter(reco => reco.showInFinalView());
if (changeRecos && changeRecos.length) {
return this.motionRepo.getAmendmentAmendedParagraphs(amendment, lineLength, changeRecos); return this.motionRepo.getAmendmentAmendedParagraphs(amendment, lineLength, changeRecos);
}
})
)
.sort((a, b) => {
return a.getLineFrom() - b.getLineFrom();
}); });
} else {
return []; return motionChangeRecos
} .concat(motionAmendments)
.filter(change => !!change)
.sort((a, b) => a.getLineFrom() - b.getLineFrom()) as ViewUnifiedChange[];
} }
/** /**