Skip to content

Commit

Permalink
#1837 - Fix missing details on submitting Designation Request (#1848)
Browse files Browse the repository at this point in the history
* #1837 - Fixed the Designation Request bug

* Update code with review comments

* Updated code with review comments

* Updated code with review comments

* Updated code with review comments

* Updated code with the review comments
  • Loading branch information
sh16011993 authored Mar 30, 2023
1 parent 2dcbe73 commit 25c01c4
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
IsInstitutionAdmin,
UserToken,
} from "../../auth/decorators";
import { DesignationAgreementService, FormService } from "../../services";
import {
DesignationAgreementService,
FormService,
InstitutionService,
} from "../../services";
import {
DesignationAgreementAPIOutDTO,
DesignationAgreementDetailsAPIOutDTO,
Expand Down Expand Up @@ -45,6 +49,7 @@ export class DesignationAgreementInstitutionsController extends BaseController {
constructor(
private readonly designationAgreementService: DesignationAgreementService,
private readonly formService: FormService,
private readonly institutionService: InstitutionService,
private readonly designationAgreementControllerService: DesignationAgreementControllerService,
) {
super();
Expand Down Expand Up @@ -81,6 +86,12 @@ export class DesignationAgreementInstitutionsController extends BaseController {
"User does not have the rights to create a designation agreement.",
);
}

// Check if institution is private and append it to the payload.
payload.isBCPrivate = await this.institutionService.isPrivateInstitution(
userToken.authorizations.institutionId,
);

// Validate the dynamic data submission.
const submissionResult = await this.formService.dryRunSubmission(
FormNames.DesignationAgreementDetails,
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[];
/**
* isBCPrivate is part of the form and defines if the dynamic area of the form.io definition will be visible or not, which also will impact the validation using the dryrun.
* Since this value has the source of truth on the institution, it must be populated by the API prior to the dryrun validation and it is part of DTO to make explicit its place in the form payload submitted but it will also be ignored by Nestjs because it does not have a decorator.
*/
isBCPrivate: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
INSTITUTION_USER_ALREADY_EXISTS,
LEGAL_SIGNING_AUTHORITY_EXIST,
} from "../../constants";
import { INSTITUTION_TYPE_BC_PRIVATE } from "@sims/sims-db/constant";
import { InstitutionUserAuthService } from "../institution-user-auth/institution-user-auth.service";
import { UserService } from "../user/user.service";

Expand Down Expand Up @@ -694,6 +695,37 @@ export class InstitutionService extends RecordDataModelService<Institution> {
.getOne();
}

/**
* Check if institution is private.
* @param institutionId is the institution id.
* @returns boolean true if institution is private, else false.
*/
async isPrivateInstitution(institutionId: number): Promise<boolean> {
const institutionType = await this.getInstitutionTypeById(institutionId);
return INSTITUTION_TYPE_BC_PRIVATE === institutionType.institutionType.id;
}

/**
* 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({
select: {
institutionType: {
id: true,
},
},
relations: {
institutionType: true,
},
where: {
id: institutionId,
},
});
}

/**
* Get the basic info of the institution by ID.
* @param institutionId Institution id.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { getSQLFileData } from "../utilities/sqlLoader";

export class DesignationAgreementsTableAlterSubmittedData1680120153698
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
getSQLFileData(
"Update-col-submitted-data-drop-not-null.sql",
"DesignationAgreements",
),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
getSQLFileData(
"Update-col-submitted-data-add-not-null.sql",
"DesignationAgreements",
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Updated the submitted_data column from NULL to NOT NULL
ALTER TABLE
sims.designation_agreements
ALTER COLUMN
submitted_data
SET
NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Updated the submitted_data column from NOT NULL to NULL
ALTER TABLE
sims.designation_agreements
ALTER COLUMN
submitted_data DROP NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export class DesignationAgreement extends RecordDataModel {
@Column({
name: "submitted_data",
type: "jsonb",
nullable: false,
nullable: true,
})
submittedData: any;
submittedData: unknown;
/**
* Current status of the designation agreement.
*/
Expand Down

0 comments on commit 25c01c4

Please sign in to comment.