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 const changeRecos = this.changeRecoRepo
.concat( .getChangeRecoOfMotion(amendment.id)
this.motionRepo.getAmendmentsInstantly(motion.id).flatMap((amendment: ViewMotion) => { .filter(reco => reco.showInFinalView());
const changeRecos = this.changeRecoRepo return this.motionRepo.getAmendmentAmendedParagraphs(amendment, lineLength, changeRecos);
.getChangeRecoOfMotion(amendment.id) });
.filter(reco => reco.showInFinalView());
if (changeRecos && changeRecos.length) { return motionChangeRecos
return this.motionRepo.getAmendmentAmendedParagraphs(amendment, lineLength, changeRecos); .concat(motionAmendments)
} .filter(change => !!change)
}) .sort((a, b) => a.getLineFrom() - b.getLineFrom()) as ViewUnifiedChange[];
)
.sort((a, b) => {
return a.getLineFrom() - b.getLineFrom();
});
} else {
return [];
}
} }
/** /**