Skip to content

Commit

Permalink
fix: handle add new response action bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Oct 14, 2024
1 parent 4f42711 commit 44b1351
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 265 deletions.
39 changes: 20 additions & 19 deletions src/domain/usecases/utils/incident-action/GetIncidentActionById.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { FutureData } from "../../../../data/api-futures";
import { IncidentResponseActionDataValues } from "../../../../data/repositories/IncidentActionD2Repository";
import { Maybe } from "../../../../utils/ts-utils";
import _c from "../../../entities/generic/Collection";
import { Future } from "../../../entities/generic/Future";
import { ActionPlan } from "../../../entities/incident-action-plan/ActionPlan";
import { IncidentActionPlan } from "../../../entities/incident-action-plan/IncidentActionPlan";
Expand Down Expand Up @@ -42,26 +40,38 @@ export function getIncidentAction(
.flatMap(responseActionDataValues => {
return Future.joinObj(
getIncidentResponseActionOptionFutures(
responseActionDataValues,
optionsRepository,
teamMemberRepository
)
).flatMap(responseActionOptions => {
const { searchAssignROOptions, statusOptions, verificationOptions } =
responseActionOptions;

const responseActions =
responseActionDataValues?.map(responseActionDataValue => {
const searchAssignRO = searchAssignROOptions.find(
option =>
option.username === responseActionDataValue?.searchAssignRO
);
const status = statusOptions.find(
option => option.id === responseActionDataValue?.status
)?.id as Status;
const verification = verificationOptions.find(
option => option.id === responseActionDataValue?.verification
)?.id as Verification;

return new ResponseAction({
id: responseActionDataValue?.id ?? "",
mainTask: responseActionDataValue?.mainTask ?? "",
subActivities: responseActionDataValue?.subActivities ?? "",
subPillar: responseActionDataValue?.subPillar ?? "",
searchAssignRO: responseActionOptions.searchAssignRO,
searchAssignRO: searchAssignRO,
dueDate: responseActionDataValue?.dueDate
? new Date(responseActionDataValue.dueDate)
: new Date(),
timeLine: responseActionDataValue?.timeLine ?? "",
status: responseActionOptions.status?.id as Status,
verification: responseActionOptions.verification
?.id as Verification,
status: status,
verification: verification,
});
}) ?? [];

Expand All @@ -79,21 +89,12 @@ export function getIncidentAction(
}

function getIncidentResponseActionOptionFutures(
responseActionsBase: Maybe<IncidentResponseActionDataValues[]>,
optionsRepository: OptionsRepository,
teamMemberRepository: TeamMemberRepository
) {
const responseActionBase = responseActionsBase ? responseActionsBase[0] : undefined;

return {
searchAssignRO: responseActionBase?.searchAssignRO
? teamMemberRepository.get(responseActionBase.searchAssignRO)
: Future.success(undefined),
status: responseActionBase?.status
? optionsRepository.getStatusOption(responseActionBase.status)
: Future.success(undefined),
verification: responseActionBase?.verification
? optionsRepository.getVerificationOption(responseActionBase.verification)
: Future.success(undefined),
searchAssignROOptions: teamMemberRepository.getAll(),
statusOptions: optionsRepository.getStatusOptions(),
verificationOptions: optionsRepository.getVerificationOptions(),
};
}
Loading

0 comments on commit 44b1351

Please sign in to comment.