Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Records export: include "info" column #3635

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions server/modules/record/repository/recordRepository.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as R from 'ramda'
import * as camelize from 'camelize'
import * as toSnakeCase from 'to-snake-case'

import { Dates, Objects } from '@openforis/arena-core'

import * as A from '@core/arena'
import * as StringUtils from '@core/stringUtils'
import { db } from '@server/db/db'
import * as DbUtils from '@server/db/dbUtils'

Expand All @@ -29,22 +28,24 @@ const tableColumns = [
'date_modified',
'validation',
'info',
'merged_into_record_uuid',
]
const dateColumns = ['date_created', 'date_modified']
const tableName = 'record'

const selectFieldDateCreated = DbUtils.selectDate('date_created')
const selectFieldDateModified = DbUtils.selectDate('date_modified')
const recordSelectFields = `uuid, owner_uuid, step, cycle, ${selectFieldDateCreated}, ${selectFieldDateModified}, merged_into_record_uuid, preview, validation`
const recordSelectFields = [
...tableColumns.filter((col) => !dateColumns.includes(col)),
...dateColumns.map((dateCol) => DbUtils.selectDate(dateCol)),
].join(', ')

const dbTransformCallback =
(surveyId, includeValidationFields = true) =>
(record) => {
if (!record) return null

const validation = Record.getValidation(record)
return R.pipe(
R.dissoc(Validation.keys.validation),
camelize,
A.camelizePartial({ limitToLevel: 1 }),
R.assoc('surveyId', surveyId),
R.assoc(
Validation.keys.validation,
Expand Down Expand Up @@ -99,6 +100,7 @@ export const insertRecordsInBatch = async ({ surveyId, records, userUuid }, clie
date_modified: Record.getDateModified(record),
validation: JSON.stringify(Validation.isObjValid(record) ? {} : Record.getValidation(record)),
info: Record.getInfo(record),
merged_into_record_uuid: Record.getMergedIntoRecordUuid(record),
}))
)
)
Expand Down Expand Up @@ -214,7 +216,7 @@ export const fetchRecordsSummaryBySurveyId = async (

const whereConditionsJoint = recordsSelectWhereConditions.map((condition) => `(${condition})`).join(' AND ')
const whereCondition = whereConditionsJoint ? `WHERE ${whereConditionsJoint}` : ''
const sortByColumnName = toSnakeCase(sortBy)
const sortByColumnName = StringUtils.toSnakeCase(sortBy)

return client.map(
`
Expand Down
Loading