Skip to content

Commit

Permalink
Merge branch 'master' into enhancement/data-explorer-edit
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 5, 2024
2 parents 671af3f + 7b3358c commit bf62a2f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const insertNodesInBulk = async ({ user, surveyId, nodesArray, systemActi
const nodeValues = nodesArray.map((node) => [
Node.getUuid(node),
Node.getDateCreated(node),
Node.getDateCreated(node),
Node.getDateModified(node),
Node.getRecordUuid(node),
Node.getParentUuid(node),
Node.getNodeDefUuid(node),
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as Record from '@core/record/record'
import * as Node from '@core/record/node'
import { Schemata, TableDataNodeDef } from '@common/model/db'
import { TableDataNodeDefColUtils } from '@common/model/db/tables/dataNodeDef/colUtils'
import * as SchemaRdb from '@common/surveyRdb/schemaRdb'
import * as NodeDefTable from '@common/surveyRdb/nodeDefTable'

import { RdbUpdateTypes, RdbUpdates } from './RdbUpdates'
Expand Down Expand Up @@ -48,6 +47,8 @@ const _getValuesByColumnName = ({ survey, record, nodeDef, node, ancestorMultipl
const result = {
[columnSet.uuid]: Node.getUuid(node),
[columnSet.parentUuid]: Node.getUuid(ancestorMultipleEntity),
[columnSet.dateCreated]: Node.getDateCreated(node),
[columnSet.dateModified]: Node.getDateModified(node),
}
if (NodeDef.isRoot(nodeDef)) {
Object.assign(result, {
Expand Down Expand Up @@ -93,7 +94,7 @@ export const generateRdbUpdates = ({ survey, record, nodes }) => {
const ancestorMultipleEntity = _findAncestor({ ancestorDefUuid, node, nodes })
const update = {
type,
schema: SchemaRdb.getName(Survey.getId(survey)),
schema: Schemata.getSchemaSurveyRdb(Survey.getId(survey)),
table: NodeDefTable.getTableName(nodeDef, ancestorDef),
nodeDefUuid: NodeDef.getUuid(nodeDef),
nodeDefHierarchyLevel: NodeDef.getMetaHierarchy(nodeDef).length,
Expand Down

0 comments on commit bf62a2f

Please sign in to comment.