From 40ad829ab370b883d7daaaf6e52a10d5a9ac17d3 Mon Sep 17 00:00:00 2001 From: Daniel Haselhan Date: Thu, 23 May 2024 16:33:02 -0700 Subject: [PATCH] Keep organization name when changing from indv -> organization * Also fixed a bug where the corporate summary was not getting deleted --- .../transferee-dialog.component.ts | 15 ++++++----- .../owner-dialog/owner-dialog.component.ts | 17 +++++++----- .../application-owner.service.spec.ts | 6 +++-- .../application-owner.service.ts | 26 ++++++++++++------- .../notice-of-intent-owner.dto.ts | 10 +++---- .../notice-of-intent-owner.service.spec.ts | 7 +++-- .../notice-of-intent-owner.service.ts | 26 ++++++++++++------- 7 files changed, 68 insertions(+), 39 deletions(-) diff --git a/portal-frontend/src/app/features/notifications/edit-submission/transferees/transferee-dialog/transferee-dialog.component.ts b/portal-frontend/src/app/features/notifications/edit-submission/transferees/transferee-dialog/transferee-dialog.component.ts index d2335059d2..b96bb4516d 100644 --- a/portal-frontend/src/app/features/notifications/edit-submission/transferees/transferee-dialog/transferee-dialog.component.ts +++ b/portal-frontend/src/app/features/notifications/edit-submission/transferees/transferee-dialog/transferee-dialog.component.ts @@ -44,7 +44,7 @@ export class TransfereeDialogComponent { public data: { submissionUuid: string; existingTransferee?: NotificationTransfereeDto; - } + }, ) { if (data && data.existingTransferee) { this.onChangeType({ @@ -66,7 +66,7 @@ export class TransfereeDialogComponent { this.organizationName.setValidators([Validators.required]); } else { this.organizationName.setValidators([]); - this.organizationName.reset(); + this.organizationName.updateValueAndValidity(); } } @@ -78,8 +78,10 @@ export class TransfereeDialogComponent { } this.isLoading = true; + const orgName = this.type.value === OWNER_TYPE.ORGANIZATION ? this.organizationName.getRawValue() : null; + const createDto: NotificationTransfereeCreateDto = { - organizationName: this.organizationName.getRawValue() || undefined, + organizationName: orgName, firstName: this.firstName.getRawValue() || undefined, lastName: this.lastName.getRawValue() || undefined, email: this.email.getRawValue()!, @@ -91,7 +93,7 @@ export class TransfereeDialogComponent { await this.transfereeService.create(createDto); this.dialogRef.close(true); } else { - this.form.markAllAsTouched() + this.form.markAllAsTouched(); } } @@ -101,8 +103,9 @@ export class TransfereeDialogComponent { async onSave() { if (this.form.valid) { + const orgName = this.type.value === OWNER_TYPE.ORGANIZATION ? this.organizationName.getRawValue() : null; const updateDto: NotificationTransfereeUpdateDto = { - organizationName: this.organizationName.getRawValue(), + organizationName: orgName, firstName: this.firstName.getRawValue(), lastName: this.lastName.getRawValue(), email: this.email.getRawValue()!, @@ -115,7 +118,7 @@ export class TransfereeDialogComponent { this.dialogRef.close(true); } } else { - this.form.markAllAsTouched() + this.form.markAllAsTouched(); } } } diff --git a/portal-frontend/src/app/shared/owner-dialogs/owner-dialog/owner-dialog.component.ts b/portal-frontend/src/app/shared/owner-dialogs/owner-dialog/owner-dialog.component.ts index f4403ac5f7..58c228fd21 100644 --- a/portal-frontend/src/app/shared/owner-dialogs/owner-dialog/owner-dialog.component.ts +++ b/portal-frontend/src/app/shared/owner-dialogs/owner-dialog/owner-dialog.component.ts @@ -69,7 +69,7 @@ export class OwnerDialogComponent { existingOwner?: ApplicationOwnerDto; documentService: ApplicationDocumentService | NoticeOfIntentDocumentService; ownerService: ApplicationOwnerService | NoticeOfIntentOwnerService; - } + }, ) { if (data && data.existingOwner) { this.onChangeType({ @@ -98,9 +98,10 @@ export class OwnerDialogComponent { } else { this.organizationName.setValidators([]); this.corporateSummary.setValidators([]); - this.organizationName.reset(); this.corporateSummary.reset(); } + this.corporateSummary.updateValueAndValidity(); + this.organizationName.updateValueAndValidity(); } async onCreate() { @@ -118,11 +119,13 @@ export class OwnerDialogComponent { return; } } + + const orgName = this.type.value === OWNER_TYPE.ORGANIZATION ? this.organizationName.getRawValue() : null; const createDto: ApplicationOwnerCreateDto & NoticeOfIntentOwnerCreateDto = { - organizationName: this.organizationName.getRawValue() || undefined, + organizationName: orgName, firstName: this.firstName.getRawValue() || undefined, lastName: this.lastName.getRawValue() || undefined, - corporateSummaryUuid: documentUuid?.uuid, + corporateSummaryUuid: documentUuid?.uuid ?? null, email: this.email.getRawValue()!, phoneNumber: this.phoneNumber.getRawValue()!, typeCode: this.type.getRawValue()!, @@ -171,11 +174,12 @@ export class OwnerDialogComponent { document = await this.uploadPendingFile(this.pendingFile); } + const orgName = this.type.value === OWNER_TYPE.ORGANIZATION ? this.organizationName.getRawValue() : null; const updateDto: ApplicationOwnerUpdateDto = { - organizationName: this.organizationName.getRawValue(), + organizationName: orgName, firstName: this.firstName.getRawValue(), lastName: this.lastName.getRawValue(), - corporateSummaryUuid: document?.uuid, + corporateSummaryUuid: document?.uuid ?? null, email: this.email.getRawValue()!, phoneNumber: this.phoneNumber.getRawValue()!, typeCode: this.type.getRawValue()!, @@ -190,6 +194,7 @@ export class OwnerDialogComponent { this.isLoading = false; } else { this.form.markAllAsTouched(); + this.showFileErrors = true; } } diff --git a/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.spec.ts b/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.spec.ts index 88afbeb092..a179e27c76 100644 --- a/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.spec.ts +++ b/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.spec.ts @@ -170,9 +170,11 @@ describe('ApplicationOwnerService', () => { corporateSummaryUuid: 'oldUuid', corporateSummary: new ApplicationDocument(), }); + const mockDocument = new ApplicationDocument(); mockRepo.findOneOrFail.mockResolvedValue(owner); mockRepo.save.mockResolvedValue(new ApplicationOwner()); mockAppDocumentService.delete.mockResolvedValue({} as any); + mockAppDocumentService.get.mockResolvedValue(mockDocument); await service.update('', { organizationName: '', @@ -182,10 +184,10 @@ describe('ApplicationOwnerService', () => { corporateSummaryUuid: 'newUuid', }); - expect(owner.corporateSummaryUuid).toEqual('newUuid'); + expect(owner.corporateSummary).toBe(mockDocument); expect(mockAppDocumentService.delete).toHaveBeenCalledTimes(1); expect(mockRepo.findOneOrFail).toHaveBeenCalledTimes(1); - expect(mockRepo.save).toHaveBeenCalledTimes(2); + expect(mockRepo.save).toHaveBeenCalledTimes(1); }); it('should call through for delete', async () => { diff --git a/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.ts b/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.ts index f51f66f7bf..513d5c3418 100644 --- a/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.ts +++ b/services/apps/alcs/src/portal/application-submission/application-owner/application-owner.service.ts @@ -138,22 +138,30 @@ export class ApplicationOwnerService { }); } - //If attaching new document and old one was defined, delete it + //If null or new document, delete old one if ( - updateDto.corporateSummaryUuid && + updateDto.corporateSummaryUuid !== undefined && existingOwner.corporateSummaryUuid !== updateDto.corporateSummaryUuid && existingOwner.corporateSummary ) { - const oldSummary = existingOwner.corporateSummary; + await this.applicationDocumentService.delete( + existingOwner.corporateSummary, + ); existingOwner.corporateSummary = null; - await this.repository.save(existingOwner); - await this.applicationDocumentService.delete(oldSummary); + existingOwner.corporateSummaryUuid = null; } - existingOwner.corporateSummaryUuid = - updateDto.corporateSummaryUuid !== undefined - ? updateDto.corporateSummaryUuid - : existingOwner.corporateSummaryUuid; + //Attach new one + if ( + updateDto.corporateSummaryUuid && + updateDto.corporateSummaryUuid !== existingOwner.corporateSummaryUuid + ) { + const newSummary = await this.applicationDocumentService.get( + updateDto.corporateSummaryUuid, + ); + existingOwner.corporateSummary = newSummary; + existingOwner.corporateSummaryUuid = newSummary.uuid; + } existingOwner.organizationName = updateDto.organizationName !== undefined diff --git a/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.dto.ts b/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.dto.ts index 5d67fa462d..80c52ac708 100644 --- a/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.dto.ts +++ b/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.dto.ts @@ -8,8 +8,8 @@ import { } from 'class-validator'; import { NoticeOfIntentDocumentDto } from '../../../alcs/notice-of-intent/notice-of-intent-document/notice-of-intent-document.dto'; import { - OwnerTypeDto, OWNER_TYPE, + OwnerTypeDto, } from '../../../common/owner-type/owner-type.entity'; import { emailRegex } from '../../../utils/email.helper'; import { NoticeOfIntentParcelDto } from '../notice-of-intent-parcel/notice-of-intent-parcel.dto'; @@ -66,7 +66,7 @@ export class NoticeOfIntentOwnerUpdateDto { @IsString() @IsOptional() - organizationName?: string; + organizationName?: string | null; @IsString() @IsOptional() @@ -75,7 +75,7 @@ export class NoticeOfIntentOwnerUpdateDto { @Matches(emailRegex) @IsOptional() email?: string; - + @IsString() @IsOptional() crownLandOwnerType?: string; @@ -86,7 +86,7 @@ export class NoticeOfIntentOwnerUpdateDto { @IsUUID() @IsOptional() - corporateSummaryUuid?: string; + corporateSummaryUuid?: string | null; } export class NoticeOfIntentOwnerCreateDto extends NoticeOfIntentOwnerUpdateDto { @@ -125,7 +125,7 @@ export class SetPrimaryContactDto { @IsString() noticeOfIntentSubmissionUuid: string; - + @IsString() @IsOptional() crownLandOwnerType?: string; diff --git a/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.spec.ts b/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.spec.ts index 487a09906d..336eb07536 100644 --- a/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.spec.ts +++ b/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.spec.ts @@ -181,6 +181,8 @@ describe('NoticeOfIntentOwnerService', () => { mockRepo.findOneOrFail.mockResolvedValue(owner); mockRepo.save.mockResolvedValue(new NoticeOfIntentOwner()); mockAppDocumentService.delete.mockResolvedValue({} as any); + const mockDocument = new NoticeOfIntentDocument(); + mockAppDocumentService.get.mockResolvedValue(mockDocument); await service.update( '', @@ -194,10 +196,11 @@ describe('NoticeOfIntentOwnerService', () => { new User(), ); - expect(owner.corporateSummaryUuid).toEqual('newUuid'); + expect(owner.corporateSummary).toBe(mockDocument); expect(mockAppDocumentService.delete).toHaveBeenCalledTimes(1); expect(mockRepo.findOneOrFail).toHaveBeenCalledTimes(1); - expect(mockRepo.save).toHaveBeenCalledTimes(2); + expect(mockRepo.save).toHaveBeenCalledTimes(1); + expect(mockAppDocumentService.get).toHaveBeenCalledTimes(1); }); it('should call through for delete', async () => { diff --git a/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.ts b/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.ts index 80fd8246dd..a70ce05189 100644 --- a/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.ts +++ b/services/apps/alcs/src/portal/notice-of-intent-submission/notice-of-intent-owner/notice-of-intent-owner.service.ts @@ -153,22 +153,30 @@ export class NoticeOfIntentOwnerService { }); } - //If attaching new document and old one was defined, delete it + //If null or new document, delete old one if ( - updateDto.corporateSummaryUuid && + updateDto.corporateSummaryUuid !== undefined && existingOwner.corporateSummaryUuid !== updateDto.corporateSummaryUuid && existingOwner.corporateSummary ) { - const oldSummary = existingOwner.corporateSummary; + await this.noticeOfIntentDocumentService.delete( + existingOwner.corporateSummary, + ); existingOwner.corporateSummary = null; - await this.repository.save(existingOwner); - await this.noticeOfIntentDocumentService.delete(oldSummary); + existingOwner.corporateSummaryUuid = null; } - existingOwner.corporateSummaryUuid = - updateDto.corporateSummaryUuid !== undefined - ? updateDto.corporateSummaryUuid - : existingOwner.corporateSummaryUuid; + //Attach new one + if ( + updateDto.corporateSummaryUuid && + updateDto.corporateSummaryUuid !== existingOwner.corporateSummaryUuid + ) { + const newSummary = await this.noticeOfIntentDocumentService.get( + updateDto.corporateSummaryUuid, + ); + existingOwner.corporateSummary = newSummary; + existingOwner.corporateSummaryUuid = newSummary.uuid; + } existingOwner.organizationName = updateDto.organizationName !== undefined