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

#1837 - Fix missing details on submitting Designation Request #1848

Merged
merged 6 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -25,6 +25,7 @@ import {
import { InstitutionUserRoles } from "../../auth/user-types.enum";
import { FormNames } from "../../services/form/constants";
import { DesignationAgreementControllerService } from "./designation-agreement.controller.service";
import { InstitutionControllerService } from "../institution/institution.controller.service";
import {
ApiBadRequestResponse,
ApiForbiddenResponse,
Expand All @@ -46,6 +47,7 @@ export class DesignationAgreementInstitutionsController extends BaseController {
private readonly designationAgreementService: DesignationAgreementService,
private readonly formService: FormService,
private readonly designationAgreementControllerService: DesignationAgreementControllerService,
private readonly institutionControllerService: InstitutionControllerService,
) {
super();
}
Expand Down Expand Up @@ -81,6 +83,15 @@ export class DesignationAgreementInstitutionsController extends BaseController {
"User does not have the rights to create a designation agreement.",
);
}

// Check if institution is private or public and append it to the payload
const isInstitutionPrivate =
await this.institutionControllerService.checkIfInstitutionIsPrivate(
userToken.authorizations.institutionId,
);

payload.isBCPrivate = isInstitutionPrivate;
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved

// Validate the dynamic data submission.
const submissionResult = await this.formService.dryRunSubmission(
FormNames.DesignationAgreementDetails,
Expand All @@ -106,7 +117,9 @@ export class DesignationAgreementInstitutionsController extends BaseController {
const createdDesignation =
await this.designationAgreementService.submitDesignationAgreement(
userToken.authorizations.institutionId,
submissionResult.data.data.dynamicData,
submissionResult.data.data.dynamicData
? submissionResult.data.data.dynamicData
: {},
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
userToken.userId,
payload.locations
.filter((location) => location.requestForDesignation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export class SubmitDesignationAgreementAPIInDTO {
@ValidateNested({ each: true })
@Type(() => SubmittedLocationsAPIInDTO)
locations: SubmittedLocationsAPIInDTO[];

andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
/**
* Indicates if Institution is private or public
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
*/
isBCPrivate: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@ export class InstitutionControllerService {
description: institutionType.name,
}));
}

/**
* Check if institution is private or public.
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
* @param institutionId is the institution id.
* @returns boolean true if institution is private, else false.
*/
async checkIfInstitutionIsPrivate(institutionId: number): Promise<boolean> {
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
const institutionType =
await this.institutionService.getInstitutionTypeById(institutionId);
return INSTITUTION_TYPE_BC_PRIVATE === institutionType.institutionType.id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,27 @@ export class InstitutionService extends RecordDataModelService<Institution> {
.getOne();
}

/**
* Get the institutionType by institution id.
* @param institutionId Institution id.
* @returns Institution retrieved, if found, otherwise returns null.
*/
async getInstitutionTypeById(institutionId: number): Promise<Institution> {
return this.repo.findOne({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the where is just an id, we can use findonebyId instead of findOne, just a suggestion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findOneById is marked as deprecated. The one to be used instead would be findOneBy but it does not seem to have the select options only the where

findOneBy(where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity | null>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes just check its deprecated, yes we can use findOneBy but in this scenario, its kind of selects everything. I am okay to have it as it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I will leave it as it is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The findOneBy here wouldn't bring the institutionType. AFAIK findOneBy doesn't allow you to specify the relations.

select: {
institutionType: {
id: true,
},
},
where: {
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
id: institutionId,
},
relations: {
institutionType: true,
},
});
}

/**
* Get the basic info of the institution by ID.
* @param institutionId Institution id.
Expand Down