@cuboapp/api-backend 1.0.3 → 1.0.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuboapp/api-backend",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Backend Api for CuboApp",
5
5
  "main": "src/index.ts",
6
6
  "repository": "git@github.com:cuboapp/api-backend.git",
@@ -127,6 +127,9 @@ export class ApiHelpersQuery<T extends CuboApiEntitiesMap<T>> {
127
127
  ${offsetString}
128
128
  `
129
129
 
130
+ // console.log('conditions', { conditions })
131
+ // console.log('sql', sql)
132
+
130
133
  return {
131
134
  withes,
132
135
  selects,
@@ -76,12 +76,18 @@ export class ApiHelpersWithes<T extends CuboApiEntitiesMap<T>> {
76
76
  throw new Error('relation for key not found: "' + partKey + '"')
77
77
  }
78
78
 
79
+ let relationEntity: CuboEntity | undefined
80
+
79
81
  if (relation_entity_id) {
80
- lastEntity = await this.helpers.entities.getById(relation_entity_id)
81
- } else if (relation_entity_alias) {
82
- lastEntity = await this.helpers.entities.getByAlias(relation_entity_alias)
82
+ relationEntity = await this.helpers.entities.getById(relation_entity_id)
83
+ }
84
+
85
+ if (!relationEntity && relation_entity_alias) {
86
+ relationEntity = await this.helpers.entities.getByAlias(relation_entity_alias)
83
87
  }
84
88
 
89
+ lastEntity = relationEntity
90
+
85
91
  if (!lastEntity) {
86
92
  throw new Error('entity for relation key not found: "' + partKey + '"')
87
93
  }
package/src/index.ts CHANGED
@@ -273,7 +273,7 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>> {
273
273
  const entity = await this.helpers.entities.getByAlias(entityAlias)
274
274
  const augmentation = this.augmentations?.[entityAlias]
275
275
 
276
- if (augmentation?.beforeUpdate) {
276
+ if (augmentation?.beforeUpdate && !opts?.excludeHooks?.includes('beforeUpdate')) {
277
277
  opts.queryOptions = await augmentation.beforeUpdate(req, opts)
278
278
  }
279
279
 
package/src/types/db.ts CHANGED
@@ -18,7 +18,16 @@ export type CuboCrudMethodOptions<E extends object = {}> = {
18
18
  transaction?: Transaction
19
19
  performer_id?: number
20
20
  extra?: any
21
- excludeHooks?: ('beforeGetMany' | 'beforeGetOne' | 'afterCreate' | 'afterUpdate' | 'afterDelete' | 'afterGetMany' | 'afterGetOne')[]
21
+ excludeHooks?: (
22
+ | 'beforeGetMany'
23
+ | 'beforeGetOne'
24
+ | 'afterCreate'
25
+ | 'afterUpdate'
26
+ | 'afterDelete'
27
+ | 'afterGetMany'
28
+ | 'afterGetOne'
29
+ | 'beforeUpdate'
30
+ )[]
22
31
 
23
32
  log?: boolean
24
33