Skip to content

Commit

Permalink
refactor: file name change, getGrade as readonly, use Either for erro…
Browse files Browse the repository at this point in the history
…r, add role to team member
  • Loading branch information
9sneha-n committed Jun 28, 2024
1 parent 3da15ac commit bf63847
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TeamMember } from "./incident-management-team/TeamMember";
import { OrgUnit } from "./OrgUnit";
import { CodedNamedRef, NamedRef } from "./Ref";
import { RiskAssessment } from "./risk-assessment/RiskAssessment";
import { Maybe } from "../../utils/ts-utils";

type HazardType =
| "Biological:Human"
Expand Down Expand Up @@ -42,7 +43,7 @@ type DiseaseOutbreakEventAttrs = NamedRef & {
notified: DateWithNarrative;
responseNarrative: string;
incidentManager: TeamMember;
notes: string;
notes: Maybe<string>;
riskAssessments: RiskAssessment[];
IncidentActionPlan: IncidentActionPlan;
IncidentManagementTeam: IncidentManagementTeam;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { NamedRef } from "../Ref";
import { Struct } from "../generic/Struct";
import { TeamMember } from "./TeamMember";

type TeamRole = NamedRef & {
level: number;
};

interface RoleTeamMemberMap {
role: TeamRole;
teamMember: TeamMember;
}
interface IncidentManagementTeamAttrs {
teamHierarchy: RoleTeamMemberMap[];
teamHierarchy: TeamMember[];
}

export class IncidentManagementTeam extends Struct<IncidentManagementTeamAttrs>() {}
7 changes: 5 additions & 2 deletions src/domain/entities/incident-management-team/TeamMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { Struct } from "../generic/Struct";
type PhoneNumber = string;
type Email = string;
type IncidentManagerStatus = "Available" | "Unavailable";
type Postion = string; //TO DO : make a list once available from client.

export type TeamRole = NamedRef & {
level: number;
};

interface TeamMemberAttrs extends NamedRef {
position: Postion;
phone: PhoneNumber;
email: Email;
status: IncidentManagerStatus;
photo: URL;
role: TeamRole;
}

export class TeamMember extends Struct<TeamMemberAttrs>() {
Expand Down
28 changes: 16 additions & 12 deletions src/domain/entities/risk-assessment/RiskAssessmentGrading.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import i18n from "@eyeseetea/feedback-component/locales";
import { Ref } from "../Ref";
import { Struct } from "../generic/Struct";
import { Maybe } from "../../../utils/ts-utils";
import { Either } from "../generic/Either";

type WeightedOptions = {
label: "Low" | "Medium" | "High";
weight: 1 | 2 | 3;
};

export const LowWeightedOption: WeightedOptions = {
label: "Low",
weight: 1,
Expand Down Expand Up @@ -92,7 +91,6 @@ interface RiskAssessmentGradingAttrs extends Ref {
capacity: CapacityOptions;
reputationalRisk: WeightedOptions;
severity: WeightedOptions;
grade: Maybe<Grade>;
}

export class RiskAssessmentGrading extends Struct<RiskAssessmentGradingAttrs>() {
Expand All @@ -101,11 +99,14 @@ export class RiskAssessmentGrading extends Struct<RiskAssessmentGradingAttrs>()
}

public static create(attrs: RiskAssessmentGradingAttrs): RiskAssessmentGrading {
const riskAssessmentGrading = new RiskAssessmentGrading(attrs);
return riskAssessmentGrading._update({ grade: riskAssessmentGrading.calculateGrade() });
return new RiskAssessmentGrading(attrs);
}

calculateGrade(): Grade {
getGrade = (): Either<Error, Grade> => {
return this.calculateGrade();
};

calculateGrade(): Either<Error, Grade> {
const totalWeight =
this.populationAtRisk.weight +
this.attackRate.weight +
Expand All @@ -115,12 +116,15 @@ export class RiskAssessmentGrading extends Struct<RiskAssessmentGradingAttrs>()
this.reputationalRisk.weight +
this.severity.weight;

if (totalWeight > 21) throw new Error(i18n.t("Invalid grade"));
if (totalWeight > 21) return Either.error(new Error(i18n.t("Invalid grade")));

const grade: Grade =
totalWeight <= 7
? "Grade 1"
: totalWeight > 7 && totalWeight <= 14
? "Grade 2"
: "Grade 3";

return totalWeight <= 7
? "Grade 1"
: totalWeight > 7 && totalWeight <= 14
? "Grade 2"
: "Grade 3";
return Either.success(grade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ describe("RiskAssessmentGrading", () => {
capacity: LowCapacity,
reputationalRisk: LowWeightedOption,
severity: LowWeightedOption,
grade: undefined,
});

expect(riskAssessmentGrading.grade).toBe("Grade 1");
const grade = riskAssessmentGrading.getGrade().value.data;
expect(grade).toBe("Grade 1");
});

it("should be Grade2 if total weight is greater than 7 and less than equal to 14", () => {
Expand All @@ -44,10 +43,9 @@ describe("RiskAssessmentGrading", () => {
capacity: MediumCapacity,
reputationalRisk: MediumWeightedOption,
severity: MediumWeightedOption,
grade: undefined,
});

expect(riskAssessmentGrading.grade).toBe("Grade 2");
const grade = riskAssessmentGrading.getGrade().value.data;
expect(grade).toBe("Grade 2");
});

it("should be Grade3 if score is greater than 14", () => {
Expand All @@ -61,10 +59,10 @@ describe("RiskAssessmentGrading", () => {
capacity: HighCapacity,
reputationalRisk: HighWeightedOption,
severity: HighWeightedOption,
grade: undefined,
});

expect(riskAssessmentGrading.grade).toBe("Grade 3");
const grade = riskAssessmentGrading.getGrade().value.data;
expect(grade).toBe("Grade 3");
});

it("should be Grade3 if score is greater than 14", () => {
Expand All @@ -78,9 +76,9 @@ describe("RiskAssessmentGrading", () => {
capacity: LowCapacity,
reputationalRisk: HighWeightedOption,
severity: HighWeightedOption,
grade: undefined,
});

expect(riskAssessmentGrading.grade).toBe("Grade 3");
const grade = riskAssessmentGrading.getGrade().value.data;
expect(grade).toBe("Grade 3");
});
});

0 comments on commit bf63847

Please sign in to comment.