Skip to content

Commit

Permalink
Enforce date downloaded column
Browse files Browse the repository at this point in the history
  • Loading branch information
ccxzhang committed Oct 11, 2024
1 parent 333c420 commit 8ae29be
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/renderer/src/pages/MainPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const MainPage = ({ queryDb }) => {
const { selectedCategory } = useSelector((state) => state.category)
const { frequency, startDate, endDate } = useSelector((state) => state.dateRange)
const { dhis2Url, username, password } = useSelector((state) => state.auth)
const currentDate = new Date().toISOString().split('T')[0]

const getOrganizationUnits = () => {
if (selectedOrgUnits.length > 0) {
Expand Down Expand Up @@ -111,13 +112,22 @@ const MainPage = ({ queryDb }) => {

const writeChunkToFile = (text, fileStream, headerState) => {
const indexOfFirstNewline = text.indexOf('\n')

if (!headerState.written) {
const header = text.slice(0, indexOfFirstNewline)
// Add 'downloaded_date' column to the header
const header = text.slice(0, indexOfFirstNewline) + ',downloaded_date'
fileStream.write(header + '\n')
headerState.written = true // Update the shared header state
headerState.written = true
}
const dataWithoutHeader = text.slice(indexOfFirstNewline + 1)
fileStream.write(dataWithoutHeader)

// Append currentDate to each row
const dataRows = text
.slice(indexOfFirstNewline + 1)
.split('\n')
.filter(Boolean) // Ensure no empty rows
const dataWithDate = dataRows.map((row) => row + `,${currentDate}`).join('\n')

fileStream.write(dataWithDate + '\n')
}

const saveQueryToDatabase = async (downloadParams) => {
Expand Down

0 comments on commit 8ae29be

Please sign in to comment.