@cuboapp/api-backend 1.0.3 → 1.0.5
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/helpers/index.ts +3 -1
- package/src/helpers/query.ts +3 -0
- package/src/helpers/withes.ts +9 -3
- package/src/index.ts +4 -1
- package/src/types/db.ts +10 -1
package/package.json
CHANGED
package/src/helpers/index.ts
CHANGED
|
@@ -99,6 +99,8 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>> {
|
|
|
99
99
|
case 'string':
|
|
100
100
|
if (value === 'null') {
|
|
101
101
|
value = null
|
|
102
|
+
} else if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
|
|
103
|
+
value = value.split(',')
|
|
102
104
|
}
|
|
103
105
|
break
|
|
104
106
|
case 'number':
|
|
@@ -132,7 +134,7 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>> {
|
|
|
132
134
|
value = null
|
|
133
135
|
} else {
|
|
134
136
|
if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
|
|
135
|
-
value = value.split(',')
|
|
137
|
+
value = value.split(',').map(Number)
|
|
136
138
|
} else {
|
|
137
139
|
const potentialValue = precision === 0 ? parseInt(value) : parseFloat(value)
|
|
138
140
|
|
package/src/helpers/query.ts
CHANGED
package/src/helpers/withes.ts
CHANGED
|
@@ -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
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
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
|
|
|
@@ -333,6 +333,9 @@ export class CuboBackendApi<T extends CuboApiEntitiesMap<T>> {
|
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
const item: any = await this.getOne(entityAlias, req, opts)
|
|
336
|
+
if (!item) {
|
|
337
|
+
throw { status: 404, text: 'Entity not found' }
|
|
338
|
+
}
|
|
336
339
|
|
|
337
340
|
const dto = await this.helpers.data.prepare('delete', entity!.fields, req.body || {}, opts?.performer_id)
|
|
338
341
|
if (!Object.keys(dto)) {
|
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?: (
|
|
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
|
|