@cuboapp/api-backend 1.0.6 → 1.0.8

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.6",
3
+ "version": "1.0.8",
4
4
  "description": "Backend Api for CuboApp",
5
5
  "main": "src/index.ts",
6
6
  "repository": "git@github.com:cuboapp/api-backend.git",
@@ -42,7 +42,8 @@ export class ApiHelpersConvert<T extends CuboApiEntitiesMap<T>> {
42
42
 
43
43
  const rowValue = get(row, initialValueKey, undefined)
44
44
 
45
- if (!withEl.entity.id && withEl.entity.alias === 'users') {
45
+ // todo: fix fields from core
46
+ if (!withEl.entity && withEl.entity.alias === 'users') {
46
47
  userFieldsPrepared.push(withEl.full_key)
47
48
 
48
49
  switch (rowValue) {
@@ -54,28 +54,30 @@ export class ApiHelpersQuery<T extends CuboApiEntitiesMap<T>> {
54
54
  }
55
55
 
56
56
  // sort
57
- if (sort !== undefined && typeof sort === 'string') {
58
- const sortParts = sort.split(',')
57
+ if (!sorts.length) {
58
+ if (sort !== undefined && typeof sort === 'string') {
59
+ const sortParts = sort.split(',')
59
60
 
60
- for (const sortPart of sortParts) {
61
- const parts = sortPart.replace(CUBO_CRUD_QUERY_KEY_REGEX, '')?.split('.')
61
+ for (const sortPart of sortParts) {
62
+ const parts = sortPart.replace(CUBO_CRUD_QUERY_KEY_REGEX, '')?.split('.')
62
63
 
63
- if (parts.length === 1) {
64
- const sortDirection = sortPart[0] === '-' ? 'desc' : 'asc'
65
- const sortKey = sortPart[0] === '-' ? sortPart.slice(1) : sortPart
64
+ if (parts.length === 1) {
65
+ const sortDirection = sortPart[0] === '-' ? 'desc' : 'asc'
66
+ const sortKey = sortPart[0] === '-' ? sortPart.slice(1) : sortPart
66
67
 
67
- const conditionField = entity.fields?.find((f) => f.alias === sortKey)
68
- const defaultField = CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === sortKey)
68
+ const conditionField = entity.fields?.find((f) => f.alias === sortKey)
69
+ const defaultField = CUBO_CRUD_DEFAULT_FIELDS.find((f) => f.alias === sortKey)
69
70
 
70
- if (!conditionField && !defaultField) {
71
- throw new Error('sortPart field "' + sortKey + '" not found')
72
- }
71
+ if (!conditionField && !defaultField) {
72
+ throw new Error('sortPart field "' + sortKey + '" not found')
73
+ }
73
74
 
74
- sorts.push('t1.' + sortKey + ' ' + sortDirection)
75
+ sorts.push('t1.' + sortKey + ' ' + sortDirection)
76
+ }
75
77
  }
78
+ } else {
79
+ sorts.push('t1.id desc')
76
80
  }
77
- } else {
78
- sorts.push('t1.id desc')
79
81
  }
80
82
 
81
83
  // limit & offset
@@ -238,9 +238,9 @@ export class ApiHelpersWithes<T extends CuboApiEntitiesMap<T>> {
238
238
  const havings: string[] = [...(opts?.queryOptions?.havings || [])]
239
239
  const replacements: Record<string, any> = { ...(opts?.queryOptions?.replacements || {}) }
240
240
  const groupBy: string = opts?.queryOptions?.groupBy || undefined
241
+ const sorts: string[] = opts?.queryOptions?.sorts || []
241
242
 
242
243
  const withes: CuboCrudWith[] = []
243
- const sorts: string[] = []
244
244
 
245
245
  // from sort key
246
246
  if (_sort) {