-
Notifications
You must be signed in to change notification settings - Fork 14
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
#3815 - Identification of changed information during edit #4221
Changes from 16 commits
3ad2b33
ece7202
45d09ac
d969f2e
ddc7a3d
5012f57
20f09e9
d7ec513
168f042
5c39f11
ea1c3e8
1648afd
094f568
69a87f3
19be56b
4356d2d
32e42a4
40ac7c9
015951c
87cc4dd
7c56184
69dad6b
524fe44
a88feb5
4039fb6
a9f371a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
CompletedApplicationDetailsAPIOutDTO, | ||
EnrolmentApplicationDetailsAPIOutDTO, | ||
InProgressApplicationDetailsAPIOutDTO, | ||
ApplicationFormData, | ||
} from "./models/application.dto"; | ||
import { | ||
AllowAuthorizedParty, | ||
|
@@ -81,16 +82,35 @@ export class ApplicationAESTController extends BaseController { | |
`Application id ${applicationId} was not found.`, | ||
); | ||
} | ||
|
||
let currentReadOnlyData: ApplicationFormData; | ||
let previousReadOnlyData: ApplicationFormData; | ||
if (loadDynamicData) { | ||
application.data = | ||
await this.applicationControllerService.generateApplicationFormData( | ||
const currentReadOnlyDataPromise = | ||
this.applicationControllerService.generateApplicationFormData( | ||
application.data, | ||
); | ||
// Check if a previous application exists. | ||
const [previousApplicationVersion] = | ||
await this.applicationService.getPreviousApplicationVersions( | ||
applicationId, | ||
{ loadDynamicData: true, limit: 1 }, | ||
); | ||
Comment on lines
+90
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor. Can this part which is blocking can be executed first, so that then next 2 request which are parallel can happen after this. ? Not a blocker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if I am following, to be clear, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be my feeling but i felt little more convenient to see both parallel requests one after the other instead of one awaiting request in the middle that's all. As I mentioned earlier it is not a blocker as there is no difference overall from execution perspective. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will make the change believing that it will be easier to understand in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code is updated. |
||
// If there is a previous application, generate its read-only data. | ||
const previousReadOnlyDataPromise = | ||
previousApplicationVersion && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
this.applicationControllerService.generateApplicationFormData( | ||
previousApplicationVersion.data, | ||
); | ||
// Wait for both promises to resolve. | ||
[currentReadOnlyData, previousReadOnlyData] = await Promise.all([ | ||
currentReadOnlyDataPromise, | ||
previousReadOnlyDataPromise, | ||
]); | ||
application.data = currentReadOnlyData; | ||
} | ||
|
||
return this.applicationControllerService.transformToApplicationDTO( | ||
application, | ||
{ previousData: previousReadOnlyData }, | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import { | |
ApplicationProgressDetailsAPIOutDTO, | ||
CompletedApplicationDetailsAPIOutDTO, | ||
InProgressApplicationDetailsAPIOutDTO, | ||
ApplicationDataChangeAPIOutDTO, | ||
} from "./models/application.dto"; | ||
import { | ||
credentialTypeToDisplay, | ||
|
@@ -35,7 +36,11 @@ import { | |
getPIRDeniedReason, | ||
getUserFullName, | ||
} from "../../utilities"; | ||
import { getDateOnlyFormat } from "@sims/utilities"; | ||
import { | ||
ApplicationDataChange, | ||
getDateOnlyFormat, | ||
compareApplicationData, | ||
} from "@sims/utilities"; | ||
import { | ||
Application, | ||
ApplicationData, | ||
|
@@ -440,12 +445,26 @@ export class ApplicationControllerService { | |
|
||
/** | ||
* Transformation util for Application. | ||
* @param application | ||
* @returns Application DTO | ||
* @param application application to be converted to the DTO. | ||
* @param options additional options. | ||
* - `previousData` previous application to allow changes detection. | ||
* @returns application DTO. | ||
*/ | ||
async transformToApplicationDTO( | ||
application: Application, | ||
options?: { previousData?: unknown }, | ||
): Promise<ApplicationSupplementalDataAPIOutDTO> { | ||
let changes: ApplicationDataChangeAPIOutDTO[]; | ||
if (options?.previousData) { | ||
const applicationDataChanges = compareApplicationData( | ||
application.data, | ||
options.previousData, | ||
); | ||
if (applicationDataChanges.length) { | ||
changes = []; | ||
this.transformToApplicationChangesDTO(applicationDataChanges, changes); | ||
} | ||
} | ||
return { | ||
data: application.data, | ||
id: application.id, | ||
|
@@ -461,9 +480,41 @@ export class ApplicationControllerService { | |
applicationEndDate: application.currentAssessment?.offering?.studyEndDate, | ||
applicationInstitutionName: | ||
application.location?.institution.legalOperatingName, | ||
changes, | ||
}; | ||
} | ||
|
||
/** | ||
* Recursively converts the {@link ApplicationDataChange} service model to the | ||
* DTO model {@link ApplicationDataChangeAPIOutDTO} which will ensure | ||
* that only required properties will be returned from the API also preventing | ||
* that future changes in the service model will not be directly returned. | ||
* @param applicationDataChanges service model application changes. | ||
* @param applicationDataChangeAPIOutDTO converted API DTO model. | ||
*/ | ||
transformToApplicationChangesDTO( | ||
applicationDataChanges: ApplicationDataChange[], | ||
applicationDataChangeAPIOutDTO: ApplicationDataChangeAPIOutDTO[], | ||
) { | ||
guru-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
applicationDataChanges.forEach((dataChange) => { | ||
const dataChangeDTO: ApplicationDataChangeAPIOutDTO = { | ||
key: dataChange.key, | ||
index: dataChange.index, | ||
changeType: dataChange.changeType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: add changes to the const dataChangeDTO: changes: dataChange.changes.length ? [] : undefined and do the below changes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not able to see the benefit. Would it be to improve the code readability or something else? |
||
}; | ||
applicationDataChangeAPIOutDTO.push(dataChangeDTO); | ||
// Check if there are nested changes | ||
if (!dataChange.changes.length) { | ||
guru-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
dataChangeDTO.changes = []; | ||
this.transformToApplicationChangesDTO( | ||
dataChange.changes, | ||
dataChangeDTO.changes, | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Convert disbursements into the enrolment DTO with information | ||
* about first and second disbursements. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍