fix naming

This commit is contained in:
ppetzold 2023-03-14 19:31:38 +01:00
parent 339249ce24
commit 8f7889d1a9

View File

@ -37,17 +37,17 @@ export type SortBy<T> = Order<T>[]
export const positiveNumberOrDefault = (value: number | undefined, defaultValue: number, minValue: 0 | 1 = 0) => export const positiveNumberOrDefault = (value: number | undefined, defaultValue: number, minValue: 0 | 1 = 0) =>
value === undefined || value < minValue ? defaultValue : value value === undefined || value < minValue ? defaultValue : value
export type ColumnProperties = { propertyPath?: string; propertyName: string; isEmbedded: boolean; column: string } export type ColumnProperties = { propertyPath?: string; propertyName: string; isNested: boolean; column: string }
export function getPropertiesByColumnName(column: string): ColumnProperties { export function getPropertiesByColumnName(column: string): ColumnProperties {
const propertyPath = column.split('.') const propertyPath = column.split('.')
if (propertyPath.length > 1) { if (propertyPath.length > 1) {
const propertyNamePath = propertyPath.slice(1) const propertyNamePath = propertyPath.slice(1)
let isEmbedded = false, let isNested = false,
propertyName = propertyNamePath.join('.') propertyName = propertyNamePath.join('.')
if (!propertyName.startsWith('(') && propertyNamePath.length > 1) { if (!propertyName.startsWith('(') && propertyNamePath.length > 1) {
isEmbedded = true isNested = true
} }
propertyName = propertyName.replace('(', '').replace(')', '') propertyName = propertyName.replace('(', '').replace(')', '')
@ -55,11 +55,11 @@ export function getPropertiesByColumnName(column: string): ColumnProperties {
return { return {
propertyPath: propertyPath[0], propertyPath: propertyPath[0],
propertyName, // the join is in case of an embedded entity propertyName, // the join is in case of an embedded entity
isEmbedded, isNested,
column: `${propertyPath[0]}.${propertyName}`, column: `${propertyPath[0]}.${propertyName}`,
} }
} else { } else {
return { propertyName: propertyPath[0], isEmbedded: false, column: propertyPath[0] } return { propertyName: propertyPath[0], isNested: false, column: propertyPath[0] }
} }
} }
@ -124,7 +124,7 @@ export function fixColumnAlias(
if (isRelation) { if (isRelation) {
if (isVirtualProperty && query) { if (isVirtualProperty && query) {
return `(${query(`${alias}_${properties.propertyPath}`)})` // () is needed to avoid parameter conflict return `(${query(`${alias}_${properties.propertyPath}`)})` // () is needed to avoid parameter conflict
} else if ((isVirtualProperty && !query) || properties.isEmbedded) { } else if ((isVirtualProperty && !query) || properties.isNested) {
return `${alias}_${properties.propertyPath}_${properties.propertyName}` return `${alias}_${properties.propertyPath}_${properties.propertyName}`
} else { } else {
return `${alias}_${properties.propertyPath}.${properties.propertyName}` return `${alias}_${properties.propertyPath}.${properties.propertyName}`