@cuboapp/api-backend 1.0.29 → 1.0.30
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 +5 -5
- package/src/helpers/index.ts +23 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuboapp/api-backend",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Backend Api for CuboApp",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"repository": "git@github.com:cuboapp/api-backend.git",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@cuboapp/constants": "2.0.
|
|
12
|
-
"@cuboapp/crdt": "1.0.
|
|
11
|
+
"@cuboapp/constants": "2.0.8",
|
|
12
|
+
"@cuboapp/crdt": "1.0.9",
|
|
13
13
|
"@cuboapp/database": "1.0.4",
|
|
14
|
-
"@cuboapp/types": "2.0.
|
|
14
|
+
"@cuboapp/types": "2.0.13",
|
|
15
15
|
"@cuboapp/utils": "1.0.10",
|
|
16
|
-
"@cuboapp/ws": "1.0.
|
|
16
|
+
"@cuboapp/ws": "1.0.6",
|
|
17
17
|
"pg": "^8.17.2",
|
|
18
18
|
"yjs": "^13.6.29"
|
|
19
19
|
},
|
package/src/helpers/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { CuboBackendApiDbConnectionType, CuboCrudFindQuery, CuboCrudRequest } fr
|
|
|
16
16
|
import { ApiHelpersConvert } from './convert'
|
|
17
17
|
import { ApiHelpersData } from './data'
|
|
18
18
|
|
|
19
|
+
import { cloneDeep } from '@cuboapp/utils'
|
|
19
20
|
import { ApiHelpersWithes } from './withes'
|
|
20
21
|
|
|
21
22
|
export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
@@ -316,13 +317,17 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
this.connecting[type] = new Promise(async (success) => {
|
|
319
|
-
|
|
320
|
+
if (this.api.options.db.connection) {
|
|
321
|
+
this.connections[type] = this.api.options.db.connection
|
|
322
|
+
} else {
|
|
323
|
+
const { iaas, pk_key, pk_type, ...config } = this.api.options.db.options
|
|
320
324
|
|
|
321
|
-
|
|
322
|
-
|
|
325
|
+
this.connections[type] = createDatabase(config, JSON.parse(JSON.stringify({ iaas, pk_key, pk_type })))
|
|
326
|
+
await this.connections[type].connect()
|
|
323
327
|
|
|
324
|
-
|
|
325
|
-
|
|
328
|
+
if (config.dialect === 'postgres' && config.schema) {
|
|
329
|
+
await this.connections[type].connection.query(`SET schema '${config.schema}';`)
|
|
330
|
+
}
|
|
326
331
|
}
|
|
327
332
|
|
|
328
333
|
success(this.connections[type])
|
|
@@ -353,17 +358,18 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
|
353
358
|
queryDto?: Partial<CuboCrudFindQuery>,
|
|
354
359
|
isCount?: boolean
|
|
355
360
|
): Promise<Partial<CuboCrudFindQuery>> {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
const
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
361
|
+
const dto: Partial<CuboCrudFindQuery> = cloneDeep(queryDto || {})
|
|
362
|
+
|
|
363
|
+
const withes = dto.withes ?? []
|
|
364
|
+
const selects = dto.selects ?? []
|
|
365
|
+
const joins = dto.joins ?? []
|
|
366
|
+
const conditions = dto.conditions ?? []
|
|
367
|
+
const havings = dto.havings ?? []
|
|
368
|
+
const sorts = dto.sorts ?? []
|
|
369
|
+
const replacements = dto.replacements ?? {}
|
|
370
|
+
const groupBy = dto.groupBy ?? undefined
|
|
371
|
+
|
|
372
|
+
const { sort, limit: _limit, page, with: _withes, ...query } = cloneDeep(req.query || {})
|
|
367
373
|
|
|
368
374
|
// plain conditions (nested are in withes.ts)
|
|
369
375
|
for (const key in query || {}) {
|
|
@@ -374,6 +380,7 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
|
|
|
374
380
|
const defaultField = CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === parts[0])
|
|
375
381
|
|
|
376
382
|
if (!conditionField && !defaultField) {
|
|
383
|
+
console.log(entity.alias, entity.fields)
|
|
377
384
|
throw new Error('condition field "' + parts[0] + '" not found in entity "' + entity.alias + '"')
|
|
378
385
|
}
|
|
379
386
|
|