Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow updating of Primary Contact Email for SRWs #985

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h3>ALC Intake</h3>
<span class="sent-text">
<strong>Sent</strong>
</span>
<span class='response-date'>{{ responseDate | momentFormat }}</span>
<span class="response-date">{{ responseDate | momentFormat }}</span>
</div>
</ng-container>
<ng-container *ngIf="!responseSent">
Expand All @@ -44,6 +44,6 @@ <h3>ALC Intake</h3>
</div>
<div *ngIf="contactEmail">
<div class="subheading2">Primary Contact Email</div>
<app-inline-text [value]="contactEmail" (save)="updateSubmissionEmail($event)"></app-inline-text>
<app-inline-text [value]="contactEmail" [required]="true" (save)="updateSubmissionEmail($event)"></app-inline-text>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,26 @@ export class IntakeComponent implements OnInit {
}

async updateSubmissionEmail(email: string | null) {
//TODO: Implemented in ALCS-1074
if (!email) {
return;
}

this.confirmationDialogService
.openDialog({
title: 'Change Primary Contact Email',
body: 'Any changes made here will also be reflected in the portal. Do you want to continue?',
})
.subscribe(async (didConfirm) => {
if (didConfirm) {
const notification = this.notification;
if (notification) {
const update = await this.notificationSubmissionService.setContactEmail(email, notification.fileNumber);
if (update) {
this.toastService.showSuccessToast('Notification updated');
}
}
}
});
}

private async loadGovernments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ describe('NotificationSubmissionService', () => {
expect(result).toEqual(mockSubmittedNOI);
expect(mockHttpClient.get).toBeCalledTimes(1);
});

it('should make a patch request for email', async () => {
mockHttpClient.patch.mockReturnValue(of(mockSubmittedNOI));

const result = await service.setContactEmail('1', '1');

expect(result).toEqual(mockSubmittedNOI);
expect(mockHttpClient.patch).toBeCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export class NotificationSubmissionService {
}
}

async setContactEmail(email: string, fileNumber: string): Promise<NotificationSubmissionDetailedDto> {
try {
return firstValueFrom(
this.http.patch<NotificationSubmissionDetailedDto>(`${this.baseUrl}/${fileNumber}`, {
contactEmail: email,
})
);
} catch (e) {
this.toastService.showErrorToast('Failed to fetch Notification Submission');
throw e;
}
}

async setSubmissionStatus(fileNumber: string, statusCode: string): Promise<NotificationSubmissionDto> {
try {
return firstValueFrom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</form>
<div class="button-container">
<button mat-button (click)="cancelEdit()">CANCEL</button>
<button mat-button class="save" (click)="confirmEdit()">SAVE</button>
<button mat-button class="save" [disabled]="required && !pendingValue" (click)="confirmEdit()">SAVE</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AfterContentChecked, Component, ElementRef, EventEmitter, Input, Output
export class InlineTextComponent implements AfterContentChecked {
@Input() value?: string | undefined;
@Input() placeholder: string = 'Enter a value';
@Input() required = false;
@Output() save = new EventEmitter<string | null>();

@ViewChild('editInput') textInput!: ElementRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,28 @@ describe('NotificationSubmissionController', () => {
);
expect(result).toEqual({ url: fakeDownloadUrl });
});

it('should call through to service for updating email', async () => {
mockNotificationSubmissionService.getUuid.mockResolvedValue('uuid');
mockNotificationSubmissionService.update.mockResolvedValue(
new NotificationSubmission(),
);
mockNotificationSubmissionService.getByFileNumber.mockResolvedValue(
new NotificationSubmission({
fileNumber: 'fileNumber',
}),
);
mockNotificationSubmissionService.mapToDetailedDTO.mockResolvedValue(
createMock<NotificationSubmissionDetailedDto>(),
);

await controller.update('fileNumber', 'email', {
user: {
entity: new User(),
},
});

expect(mockNotificationSubmissionService.getUuid).toBeCalledTimes(1);
expect(mockNotificationSubmissionService.update).toBeCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,29 @@ export class NotificationSubmissionController {
);
return this.get(fileNumber, req);
}

@UserRoles(...ANY_AUTH_ROLE)
@Patch('/:fileNumber')
async update(
@Param('fileNumber') fileNumber: string,
@Body('contactEmail') contactEmail: string,
@Req() req,
) {
if (!contactEmail.trim()) {
throw new ServiceValidationException('Email is required');
}

const uuid = await this.notificationSubmissionService.getUuid(fileNumber);
if (uuid) {
await this.notificationSubmissionService.update(
uuid,
{
contactEmail,
},
req.user.entity,
);
}

return this.get(fileNumber, req);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,30 @@ describe('NotificationSubmissionService', () => {

expect(app).toBe(noiSubmission);
});

it('should call through to the repo for getFileNumber', async () => {
const fileNumber = 'file-number';
const noiSubmission = new NotificationSubmission({
fileNumber,
});
mockRepository.findOne.mockResolvedValue(noiSubmission);

const res = await service.getFileNumber('uuid');

expect(res).toBe(fileNumber);
expect(mockRepository.findOne).toHaveBeenCalledTimes(1);
});

it('should call through to the repo for getUuid', async () => {
const uuid = 'uuid';
const noiSubmission = new NotificationSubmission({
uuid,
});
mockRepository.findOne.mockResolvedValue(noiSubmission);

const res = await service.getUuid('file-number');

expect(res).toBe(uuid);
expect(mockRepository.findOne).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ export class NotificationSubmissionService {
return submission?.fileNumber;
}

async getUuid(fileNumber: string) {
const submission = await this.notificationSubmissionRepository.findOne({
where: {
fileNumber,
},
select: {
uuid: true,
fileNumber: true,
},
});
return submission?.uuid;
}

async getAllByUser(user: User) {
const whereClauses = await this.generateWhereClauses({}, user);

Expand Down