@cuboapp/api-backend 3.0.4 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/index.ts +3 -9
- package/src/helpers/index.ts +18 -16
- package/src/helpers/withes.ts +25 -22
package/package.json
CHANGED
package/src/core/index.ts
CHANGED
|
@@ -529,14 +529,7 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>, A extends unknown =
|
|
|
529
529
|
if (this.options.hooks?.onAfterUpdate && !this.excluded(opts, 'baseHooks')) {
|
|
530
530
|
await this.options.hooks.onAfterUpdate(entity, row, prevById.get((row as any).id) as T[K], opts)
|
|
531
531
|
}
|
|
532
|
-
this.crdtPush(
|
|
533
|
-
'update',
|
|
534
|
-
entity,
|
|
535
|
-
row,
|
|
536
|
-
opts,
|
|
537
|
-
prevById.get((row as any).id),
|
|
538
|
-
Object.keys(dto)
|
|
539
|
-
)
|
|
532
|
+
this.crdtPush('update', entity, row, opts, prevById.get((row as any).id), Object.keys(dto))
|
|
540
533
|
}
|
|
541
534
|
|
|
542
535
|
return updated
|
|
@@ -670,7 +663,8 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>, A extends unknown =
|
|
|
670
663
|
req,
|
|
671
664
|
auth: opts.auth as A,
|
|
672
665
|
performer_id: opts.performer_id,
|
|
673
|
-
queryOptions
|
|
666
|
+
queryOptions,
|
|
667
|
+
transaction: opts?.transaction
|
|
674
668
|
}
|
|
675
669
|
}
|
|
676
670
|
|
package/src/helpers/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Database, createDatabase } from '@cuboapp/database'
|
|
|
3
3
|
import { CuboApiEntitiesMap, CuboEntity, CuboEntityField, CuboEntityFieldExtra, CuboEntityFieldType } from '@cuboapp/types'
|
|
4
4
|
import { cloneDeep } from '@cuboapp/utils'
|
|
5
5
|
|
|
6
|
-
import type { CuboBackendApi } from '../core'
|
|
7
6
|
import {
|
|
8
7
|
CUBO_CRUD_DEFAULT_FIELDS,
|
|
9
8
|
CUBO_CRUD_DEFAULT_PAGE_LIMIT,
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
CUBO_CRUD_QUERY_KEY_REGEX,
|
|
13
12
|
CUBO_CRUD_QUERY_SYMBOL_NOT
|
|
14
13
|
} from '../constants'
|
|
14
|
+
import type { CuboBackendApi } from '../core'
|
|
15
15
|
import { CuboDialect, getDialect } from '../dialects'
|
|
16
16
|
import { CuboBackendApiDbConnectionType, CuboCrudFindQuery, CuboCrudRequest, CuboDataFilter, CuboDataFiltersQuery } from '../types'
|
|
17
17
|
|
|
@@ -495,22 +495,24 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A = unknown> {
|
|
|
495
495
|
const conditionField = entity.fields?.find((f) => f.alias === parts[0])
|
|
496
496
|
const defaultField = CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === parts[0])
|
|
497
497
|
|
|
498
|
-
if (!conditionField && !defaultField) {
|
|
499
|
-
|
|
498
|
+
// if (!conditionField && !defaultField) {
|
|
499
|
+
// throw new Error('condition field "' + parts[0] + '" not found in entity "' + entity.alias + '"')
|
|
500
|
+
// }
|
|
501
|
+
|
|
502
|
+
if (conditionField || defaultField) {
|
|
503
|
+
const fieldAlias = conditionField ? conditionField.alias : defaultField!.alias
|
|
504
|
+
const preparedCondition = this.clearFieldConditionValue(conditionField ? conditionField : defaultField!, query[key])
|
|
505
|
+
const prepared = this.prepareConditionSql(
|
|
506
|
+
`t1.${fieldAlias}`,
|
|
507
|
+
`c_1_${fieldAlias}_value`,
|
|
508
|
+
preparedCondition.value,
|
|
509
|
+
preparedCondition.condition,
|
|
510
|
+
preparedCondition.is_not
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
conditions.push(...(prepared.conditions || []))
|
|
514
|
+
Object.assign(replacements, prepared.replacements || {})
|
|
500
515
|
}
|
|
501
|
-
|
|
502
|
-
const fieldAlias = conditionField ? conditionField.alias : defaultField!.alias
|
|
503
|
-
const preparedCondition = this.clearFieldConditionValue(conditionField ? conditionField : defaultField!, query[key])
|
|
504
|
-
const prepared = this.prepareConditionSql(
|
|
505
|
-
`t1.${fieldAlias}`,
|
|
506
|
-
`c_1_${fieldAlias}_value`,
|
|
507
|
-
preparedCondition.value,
|
|
508
|
-
preparedCondition.condition,
|
|
509
|
-
preparedCondition.is_not
|
|
510
|
-
)
|
|
511
|
-
|
|
512
|
-
conditions.push(...(prepared.conditions || []))
|
|
513
|
-
Object.assign(replacements, prepared.replacements || {})
|
|
514
516
|
}
|
|
515
517
|
}
|
|
516
518
|
|
package/src/helpers/withes.ts
CHANGED
|
@@ -158,35 +158,38 @@ export class ApiHelpersWithes<T extends CuboApiEntitiesMap<T>> {
|
|
|
158
158
|
const conditionField =
|
|
159
159
|
lastEntity.fields?.find((f) => f.alias === conditionLastKey) || CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === conditionLastKey)
|
|
160
160
|
|
|
161
|
-
if (!conditionField) {
|
|
162
|
-
|
|
163
|
-
}
|
|
161
|
+
// if (!conditionField) {
|
|
162
|
+
// throw new Error('condition field "' + conditionKey + '" not found in entity "' + entity.alias + '"')
|
|
163
|
+
// }
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const exWith = withes.find((w) => (w.full_key = conditionKeyParts.join('.')))
|
|
165
|
+
if (conditionField) {
|
|
166
|
+
let conditionTableAlias = 't1'
|
|
168
167
|
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
}
|
|
168
|
+
if (conditionKeyParts.length > 0) {
|
|
169
|
+
const exWith = withes.find((w) => (w.full_key = conditionKeyParts.join('.')))
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
if (!exWith) {
|
|
172
|
+
throw new Error('condition field relation "' + conditionKey + '" not found')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
conditionTableAlias = 't_' + exWith.table_name
|
|
176
|
+
}
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
opts.conditions = opts.conditions || []
|
|
177
179
|
|
|
178
|
-
|
|
180
|
+
const preparedCondition = this.helpers.clearFieldConditionValue(conditionField, opts.conditionValue)
|
|
179
181
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
const prepared = this.helpers.prepareConditionSql(
|
|
183
|
+
`${conditionTableAlias}.${conditionField.alias}`,
|
|
184
|
+
`${conditionTableAlias}_${conditionField.alias}_value`,
|
|
185
|
+
preparedCondition.value,
|
|
186
|
+
preparedCondition.condition,
|
|
187
|
+
preparedCondition.is_not
|
|
188
|
+
)
|
|
187
189
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
opts.conditions.push(...(prepared.conditions || []))
|
|
191
|
+
Object.assign(opts.replacements, prepared.replacements || {})
|
|
192
|
+
}
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
// сортировка
|