Skip to content

Commit

Permalink
Fix TODOs in app-api (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbay-bluetiger authored Jan 29, 2025
1 parent 0df584c commit fff97ea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 53 deletions.
4 changes: 0 additions & 4 deletions logs/todos.log
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.

./services/app-api/utils/other/copy.ts:44: TODO, remove cast
./services/app-api/utils/other/copy.ts:59: TODO, make this ReportFieldData
./services/app-api/utils/other/copy.ts:61: TODO, make this Choice[] | ReportFieldData[]
./services/app-api/utils/time/time.ts:77: TODO: Remove this block in 2025
./services/ui-src/src/components/banners/AdminBannerProvider.test.tsx:137: TODO:
./services/ui-src/src/components/layout/Timeout.tsx:33: TODO: When autosave is implemented, set up a callback function to listen to calls to update in authLifecycle
./services/ui-src/src/components/pages/Admin/AdminPage.test.tsx:107: TODO: actually toggle active status
Expand Down
44 changes: 23 additions & 21 deletions services/app-api/utils/other/copy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getReportFieldData } from "../../storage/reports";
import { getPossibleFieldsFromFormTemplate } from "../formTemplates/formTemplates";
import { AnyObject, ReportFieldData, ReportJson, State } from "../types";
import { ReportFieldData, ReportJson, State } from "../types";

/**
*
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function copyFieldDataFromSource(
pruneEntityData(
sourceFieldData,
key,
sourceFieldData[key] as AnyObject[], // TODO, remove cast
sourceFieldData[key] as ReportFieldData[],
possibleFields
);
} else if (!possibleFields.includes(key)) {
Expand All @@ -56,9 +56,9 @@ export async function copyFieldDataFromSource(
}

function pruneEntityData(
sourceFieldData: AnyObject, // TODO, make this ReportFieldData
sourceFieldData: ReportFieldData,
key: string,
entityData: AnyObject[], // TODO, make this Choice[] | ReportFieldData[]
entityData: ReportFieldData[],
possibleFields: string[]
) {
//adding fields to be copied over from entries
Expand All @@ -69,36 +69,38 @@ function pruneEntityData(
delete sourceFieldData[key];
return;
}
for (const entityKey in entity) {

Object.keys(entity).forEach((entityKey) => {
//check to see if the object is an array, this is for capturing substeps in the initiatives
if (typeof entity[entityKey] === "object") {
if (Array.isArray(entity[entityKey])) {
pruneEntityData(
sourceFieldData,
key,
entity[entityKey],
entity[entityKey] as ReportFieldData[],
possibleFields
);
} else {
if (!concatEntityFields.includes(entityKey)) {
if (
!entityKey.includes("name") &&
!["key", "value"].includes(entityKey)
) {
delete entityData[index][entityKey];
}
}
} else if (
!concatEntityFields.includes(entityKey) &&
!entityKey.includes("name") &&
!["key", "value"].includes(entityKey)
) {
delete entityData[index][entityKey];
}
}
});

if (Object.keys(entity).length === 0) {
delete entityData[index];
} else entityData[index]["isCopied"] = true;
} else {
entityData[index]["isCopied"] = true;
}
});

//filter out any closeout data
if (sourceFieldData && sourceFieldData[key]) {
sourceFieldData[key] = sourceFieldData[key].filter(
(field: AnyObject) => !field["isInitiativeClosed"]
if (Array.isArray(sourceFieldData[key])) {
const filteredData = (sourceFieldData[key] as ReportFieldData[]).filter(
(field) => !field["isInitiativeClosed"]
);
sourceFieldData[key] = filteredData;
}
// Delete whole key if there's nothing in it.
if (entityData.every((e) => e === null)) {
Expand Down
23 changes: 0 additions & 23 deletions services/app-api/utils/time/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,4 @@ describe("calculateDueDate()", () => {
expect(dueDate).toBe("02/29/2024");
});
});

describe("Calculate due dates for 2024", () => {
const currentYear = 2024;
const reportType = ReportType.WP;

describe("Period 1", () => {
const reportPeriod = 1;

test("returns WP due date in 2024 as 9/1", () => {
const dueDate = calculateDueDate(currentYear, reportPeriod, reportType);
expect(dueDate).toBe("09/01/2024");
});
});

describe("Period 2", () => {
const reportPeriod = 2;

test("returns WP due date in 2024 as 9/3", () => {
const dueDate = calculateDueDate(currentYear, reportPeriod, reportType);
expect(dueDate).toBe(`09/03/2024`);
});
});
});
});
5 changes: 0 additions & 5 deletions services/app-api/utils/time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ export const calculateDueDate = (
dueDate = "11/1";
}

// TODO: Remove this block in 2025
if (reportType === ReportType.WP && year === 2024) {
dueDate = reportPeriod === 1 ? "9/1" : "9/3";
}

if (reportType === ReportType.SAR) {
dueDate = "8/29";

Expand Down

0 comments on commit fff97ea

Please sign in to comment.