Skip to content

Commit

Permalink
Merge branch 'main' into DAP-1006-email-template
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyMitch authored Nov 27, 2024
2 parents c75c49b + 917fa59 commit 81899ee
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 26 deletions.
32 changes: 16 additions & 16 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ You can test the creation of a file list ARS662 by following these steps.
"classification": "654321-10",
"file": "",
"opr": true,
"startDate": "01-01-2024",
"endDate": "12-31-2024",
"soDate": "02-01-2024",
"fdDate": "12-01-2024"
"startDate": "2024/01/01",
"endDate": "2024/12/31",
"soDate": "2024/02/01",
"fdDate": "2024/12/01"
},
"D:/test/Folder2": {
"schedule": "654321",
"classification": "123456-20",
"file": "",
"opr": false,
"startDate": "03-01-2024",
"endDate": "11-30-2024",
"soDate": "04-01-2024",
"fdDate": "10-31-2024"
"startDate": "2024/01/01",
"endDate": "2024/12/31",
"soDate": "2024/02/01",
"fdDate": "2024/12/01"
}
},
"files": {
Expand Down Expand Up @@ -112,20 +112,20 @@ curl -X POST http://localhost:3200/filelist/test \
"classification": "654321-10",
"file": "",
"opr": true,
"startDate": "01-01-2024",
"endDate": "12-31-2024",
"soDate": "02-01-2024",
"fdDate": "12-01-2024"
"startDate": "2024/01/01",
"endDate": "2024/12/31",
"soDate": "2024/02/01",
"fdDate": "2024/12/01"
},
"D:/test/Folder2": {
"schedule": "654321",
"classification": "123456-20",
"file": "",
"opr": false,
"startDate": "03-01-2024",
"endDate": "11-30-2024",
"soDate": "04-01-2024",
"fdDate": "10-31-2024"
"startDate": "2024/01/01",
"endDate": "2024/12/31",
"soDate": "2024/02/01",
"fdDate": "2024/12/01"
}
},
"files": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const setupMetadata = ({ worksheet, files }: Data) => {
formatDate(row.birthtime),
formatDate(row.lastModified),
formatDate(row.lastAccessed),
row.lastSaved ? formatDate(row.lastSaved) : "",
row?.lastSaved ? formatDate(row.lastSaved) : "",
row?.authors ?? "",
row?.owner ?? "",
row?.company ?? "",
Expand Down
7 changes: 5 additions & 2 deletions backend/src/modules/filelist/utils/queueConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Workbook } from "exceljs";
import { createExcelWorkbook } from "./excel";
import { sendEmail } from "src/modules/ches/utils";
import { filelistEmail } from "./email";
import { formatDate } from "src/utils";

const QUEUE_NAME = "CREATE_FILE_LIST_QUEUE";

Expand Down Expand Up @@ -39,10 +40,12 @@ export const queueConsumer = async (msg: amqp.ConsumeMessage, channel: amqp.Chan
return console.error("Email not found in filelist.");
}

const date = formatDate(new Date().toISOString());

// Handle output file type
switch (filelist.outputFileType) {
case "excel": {
const filename = `Digital_File_List_${new Date().toLocaleDateString().replace(/\//g, "-")}.xlsx`;
const filename = `Digital_File_List_${date}.xlsx`;

// Create Excel workbook
const workbook: Workbook = createExcelWorkbook({
Expand Down Expand Up @@ -78,7 +81,7 @@ export const queueConsumer = async (msg: amqp.ConsumeMessage, channel: amqp.Chan
}

case "json": {
const filename = `Digital_File_List_${new Date().toLocaleDateString().replace(/\//g, "-")}.json`;
const filename = `Digital_File_List_${date}.json`;

// Create JSON file list
const jsonFile: JsonFileList = createJsonFileList({
Expand Down
27 changes: 25 additions & 2 deletions backend/src/utils/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
export const formatDate = (date?: string | null): string => {
if (!date || date === "") return "";

// Check if the string is in ISO format
const isISO = date.includes("T");
if (!isISO) {
// Handle non-ISO date string in the format YYYY/MM/DD
const parts = date.split("/");
if (parts.length !== 3) {
return ""; // Return an empty string if the format is unexpected
}

const [year, month, day] = parts;
if (!year || !month || !day) {
return ""; // Return an empty string if any part is missing
}

const parsedYear = year.trim();
const parsedMonth = month.trim().padStart(2, "0");
const parsedDay = day.trim().padStart(2, "0");
return `${parsedYear}-${parsedMonth}-${parsedDay}`;
}

// Handle ISO date strings (UTC timezone)
const parsedDate = new Date(date);
if (Number.isNaN(parsedDate.getTime())) {
return date; // Return the original value if it's not a valid date
}

const year = parsedDate.getUTCFullYear();
const month = String(parsedDate.getUTCMonth() + 1).padStart(2, "0");
const day = String(parsedDate.getUTCDate()).padStart(2, "0");
const year = parsedDate.getUTCFullYear();
return `${month}-${day}-${year}`;
return `${year}-${month}-${day}`;
};
43 changes: 43 additions & 0 deletions backend/tests/utils/formatDate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { formatDate } from "@/utils";

describe("formatDate", () => {
it("should return an empty string if date is undefined", () => {
expect(formatDate(undefined)).toBe("");
});

it("should return an empty string if date is null", () => {
expect(formatDate(null)).toBe("");
});

it("should return an empty string if date is an empty string", () => {
expect(formatDate("")).toBe("");
});

it("should format a valid ISO date string to YYYY-MM-DD", () => {
expect(formatDate("2024-11-25T00:00:00Z")).toBe("2024-11-25");
});

it("should format a valid date string in YYYY/MM/DD to YYYY-MM-DD", () => {
expect(formatDate("2024/11/25")).toBe("2024-11-25");
});

it("should return an empty string for unexpected non-ISO formats", () => {
expect(formatDate("Invalid Date Format")).toBe("");
});

it("should handle leap year dates correctly", () => {
expect(formatDate("2024-02-29T12:00:00Z")).toBe("2024-02-29");
});

it("should correctly format non-UTC ISO times", () => {
expect(formatDate("2024-11-25T23:59:59-08:00")).toBe("2024-11-26");
});

it("should handle YYYY/MM/DD format with extra spaces", () => {
expect(formatDate(" 2024 / 11 / 25 ")).toBe("2024-11-25");
});

it("should return an empty string if the YYYY/MM/DD format is incomplete", () => {
expect(formatDate("2024/11")).toBe("");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const GridEditDateCell = ({
<DatePicker
value={value}
onChange={handleChange}
format="YYYY/MM/DD"
slots={{ textField: WrappedGridEditDateInput }}
/>
);
Expand Down Expand Up @@ -141,7 +142,7 @@ export const FolderDisplayGrid = ({ rows, onFolderDelete, processRowUpdate, apiR
renderEditCell: (params) => <GridEditDateCell {...params} />,
valueFormatter: (value) => {
if (value) {
return (value as Dayjs).format("MM/DD/YYYY");
return (value as Dayjs).format("YYYY/MM/DD");
}
return "";
},
Expand All @@ -155,7 +156,7 @@ export const FolderDisplayGrid = ({ rows, onFolderDelete, processRowUpdate, apiR
renderEditCell: (params) => <GridEditDateCell {...params} />,
valueFormatter: (value) => {
if (value) {
return (value as Dayjs).format("MM/DD/YYYY");
return (value as Dayjs).format("YYYY/MM/DD");
}
return "";
},
Expand All @@ -169,7 +170,7 @@ export const FolderDisplayGrid = ({ rows, onFolderDelete, processRowUpdate, apiR
renderEditCell: (params) => <GridEditDateCell {...params} />,
valueFormatter: (value) => {
if (value) {
return (value as Dayjs).format("MM/DD/YYYY");
return (value as Dayjs).format("YYYY/MM/DD");
}
return "";
},
Expand All @@ -183,7 +184,7 @@ export const FolderDisplayGrid = ({ rows, onFolderDelete, processRowUpdate, apiR
renderEditCell: (params) => <GridEditDateCell {...params} />,
valueFormatter: (value) => {
if (value) {
return (value as Dayjs).format("MM/DD/YYYY");
return (value as Dayjs).format("YYYY/MM/DD");
}
return "";
},
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/renderer/src/pages/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const FileListPage = () => {
// Check if filePath is already in the rows
const isAlreadyInRows = rows.some((row) => row.folder === filePath);

if (isAlreadyInRows) continue; // Skip if filePath is already in rows
if (isAlreadyInRows || filePath === "") continue; // Skip if filePath is already in rows

const curFolderRow: FolderRow = {
id: index, // Unique IDs for new rows
Expand Down

0 comments on commit 81899ee

Please sign in to comment.