@cuboapp/api-backend 1.0.36 → 1.0.37

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.36",
3
+ "version": "1.0.37",
4
4
  "description": "Backend Api for CuboApp",
5
5
  "main": "src/index.ts",
6
6
  "repository": "git@github.com:cuboapp/api-backend.git",
@@ -12,7 +12,7 @@
12
12
  "@cuboapp/crdt": "1.0.11",
13
13
  "@cuboapp/database": "1.0.6",
14
14
  "@cuboapp/types": "2.0.13",
15
- "@cuboapp/utils": "1.0.10",
15
+ "@cuboapp/utils": "1.0.11",
16
16
  "@cuboapp/ws": "1.0.6",
17
17
  "mime-types": "^3.0.2",
18
18
  "pg": "^8.17.2",
@@ -93,7 +93,7 @@ export class ApiHelpersConvert<T extends CuboApiEntitiesMap<T>> {
93
93
  case CUBO_ENTITY_FIELD_TYPE.BOOLEAN:
94
94
  return value !== undefined ? (['true', true].includes(value) ? true : false) : null
95
95
  case CUBO_ENTITY_FIELD_TYPE.DATE:
96
- return value
96
+ return value !== undefined ? value : null
97
97
  case CUBO_ENTITY_FIELD_TYPE.FILE:
98
98
  // console.warn('field type "file" is not implemented yet')
99
99
  return undefined
@@ -26,7 +26,7 @@ export class ApiHelpersData<T extends CuboApiEntitiesMap<T>> {
26
26
  }
27
27
  break
28
28
  case 'delete':
29
- prepared.deleted_at = dto?.deleted_at !== undefined ? dto.deleted_at : new Date().toISOString()
29
+ prepared.deleted_at = dto?.deleted_at !== undefined ? dto.deleted_at : new Date()
30
30
  prepared.deleted_by = dto?.deleted_by !== undefined ? dto.deleted_by : performer_id
31
31
  break
32
32
  }
@@ -1,6 +1,7 @@
1
1
  import { CUBO_ENTITY_FIELD_TYPE } from '@cuboapp/constants'
2
2
  import { Database, createDatabase } from '@cuboapp/database'
3
3
  import { CuboApiEntitiesMap, CuboEntity, CuboEntityField, CuboEntityFieldExtra, CuboEntityFieldType } from '@cuboapp/types'
4
+ import { cloneDeep } from '@cuboapp/utils'
4
5
 
5
6
  import { CuboBackendApi } from '../..'
6
7
  import {
@@ -15,8 +16,6 @@ import { CuboBackendApiDbConnectionType, CuboCrudFindQuery, CuboCrudRequest } fr
15
16
 
16
17
  import { ApiHelpersConvert } from './convert'
17
18
  import { ApiHelpersData } from './data'
18
-
19
- import { cloneDeep } from '@cuboapp/utils'
20
19
  import { ApiHelpersWithes } from './withes'
21
20
 
22
21
  export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
@@ -100,109 +99,119 @@ export class ApiHelpers<T extends CuboApiEntitiesMap<T>, A> {
100
99
  switch (field.type) {
101
100
  case CUBO_ENTITY_FIELD_TYPE.TEXT:
102
101
  case CUBO_ENTITY_FIELD_TYPE.TEXTAREA:
103
- switch (type) {
104
- case 'object':
105
- if (value !== null) {
102
+ case CUBO_ENTITY_FIELD_TYPE.DATE:
103
+ case CUBO_ENTITY_FIELD_TYPE.TIMESTAMP:
104
+ {
105
+ switch (type) {
106
+ case 'object':
107
+ if (value !== null) {
108
+ throw new Error('"' + field.alias + '" must be string')
109
+ }
110
+ break
111
+ case 'string':
112
+ if (value === 'null') {
113
+ value = null
114
+ } else if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
115
+ value = value.split(',')
116
+ }
117
+ break
118
+ case 'number':
119
+ value = `${value}`
120
+ break
121
+ default:
106
122
  throw new Error('"' + field.alias + '" must be string')
107
- }
108
- break
109
- case 'string':
110
- if (value === 'null') {
111
- value = null
112
- } else if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
113
- value = value.split(',')
114
- }
115
- break
116
- case 'number':
117
- value = `${value}`
118
- break
119
- default:
120
- throw new Error('"' + field.alias + '" must be string')
123
+ }
121
124
  }
122
125
  break
123
126
  case CUBO_ENTITY_FIELD_TYPE.SELECT:
124
- if (value === 'null') {
125
- value = null
126
- } else {
127
- if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
128
- value = value.split(',')
127
+ {
128
+ if (value === 'null') {
129
+ value = null
130
+ } else {
131
+ if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
132
+ value = value.split(',')
133
+ }
129
134
  }
130
135
  }
131
136
  break
132
137
  case CUBO_ENTITY_FIELD_TYPE.NUMBER:
133
- // const precision = field.extra?.number_precision || 0
134
- const precision = 0
135
-
136
- switch (type) {
137
- case 'object':
138
- if (value !== null) {
139
- throw new Error('"' + field.alias + '" must be string')
140
- }
141
- break
142
- case 'string':
143
- if (value === 'null') {
144
- value = null
145
- } else {
146
- if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
147
- value = value.split(',').map(Number)
148
- } else if (condition === CUBO_CRUD_QUERY_CONDITION.BTW) {
149
- const [fromStr, toStr] = value.split(':')
150
- const from = precision === 0 ? parseInt(fromStr) : parseFloat(fromStr)
151
- const to = precision === 0 ? parseInt(toStr) : parseFloat(toStr)
152
-
153
- if (isNaN(from) || isNaN(to)) {
154
- throw new Error(`"${field.alias}": both values for "btw" must be valid numbers`)
155
- }
156
-
157
- value = precision > 0 ? `${from.toFixed(precision)}:${to.toFixed(precision)}` : `${from}:${to}`
138
+ {
139
+ // const precision = field.extra?.number_precision || 0
140
+ const precision = 0
141
+
142
+ switch (type) {
143
+ case 'object':
144
+ if (value !== null) {
145
+ throw new Error('"' + field.alias + '" must be string')
146
+ }
147
+ break
148
+ case 'string':
149
+ if (value === 'null') {
150
+ value = null
158
151
  } else {
159
- const potentialValue = precision === 0 ? parseInt(value) : parseFloat(value)
160
- if (isNaN(potentialValue)) {
161
- throw new Error('"' + field.alias + '" must be number')
152
+ if ([CUBO_CRUD_QUERY_CONDITION.IN, CUBO_CRUD_QUERY_CONDITION.NIN].includes(condition)) {
153
+ value = value.split(',').map(Number)
154
+ } else if (condition === CUBO_CRUD_QUERY_CONDITION.BTW) {
155
+ const [fromStr, toStr] = value.split(':')
156
+ const from = precision === 0 ? parseInt(fromStr) : parseFloat(fromStr)
157
+ const to = precision === 0 ? parseInt(toStr) : parseFloat(toStr)
158
+
159
+ if (isNaN(from) || isNaN(to)) {
160
+ throw new Error(`"${field.alias}": both values for "btw" must be valid numbers`)
161
+ }
162
+
163
+ value = precision > 0 ? `${from.toFixed(precision)}:${to.toFixed(precision)}` : `${from}:${to}`
162
164
  } else {
163
- if (precision > 0) {
164
- value = parseFloat(potentialValue.toFixed(precision))
165
+ const potentialValue = precision === 0 ? parseInt(value) : parseFloat(value)
166
+ if (isNaN(potentialValue)) {
167
+ throw new Error('"' + field.alias + '" must be number')
165
168
  } else {
166
- value = potentialValue
169
+ if (precision > 0) {
170
+ value = parseFloat(potentialValue.toFixed(precision))
171
+ } else {
172
+ value = potentialValue
173
+ }
167
174
  }
168
175
  }
169
176
  }
170
- }
171
- break
172
- case 'number':
173
- if (precision > 0) {
174
- value = parseFloat(parseFloat(value).toFixed(precision))
175
- } else {
176
- value = parseInt(value)
177
- }
178
- break
179
- default:
180
- throw new Error('"' + field.alias + '" must be number')
177
+ break
178
+ case 'number':
179
+ if (precision > 0) {
180
+ value = parseFloat(parseFloat(value).toFixed(precision))
181
+ } else {
182
+ value = parseInt(value)
183
+ }
184
+ break
185
+ default:
186
+ throw new Error('"' + field.alias + '" must be number')
187
+ }
181
188
  }
182
189
  break
183
190
  case CUBO_ENTITY_FIELD_TYPE.BOOLEAN:
184
- switch (type) {
185
- case 'object':
186
- if (value !== null) {
187
- throw new Error('"' + field.alias + '" must be string')
188
- }
189
- break
190
- case 'string':
191
- if (value === 'null') {
192
- value = null
193
- } else if (!['true', 'false'].includes(value)) {
194
- throw new Error('"' + field.alias + '" must be true or false')
195
- }
196
- break
197
- case 'number':
198
- if (![0, 1].includes(value)) {
191
+ {
192
+ switch (type) {
193
+ case 'object':
194
+ if (value !== null) {
195
+ throw new Error('"' + field.alias + '" must be string')
196
+ }
197
+ break
198
+ case 'string':
199
+ if (value === 'null') {
200
+ value = null
201
+ } else if (!['true', 'false'].includes(value)) {
202
+ throw new Error('"' + field.alias + '" must be true or false')
203
+ }
204
+ break
205
+ case 'number':
206
+ if (![0, 1].includes(value)) {
207
+ throw new Error('"' + field.alias + '" must be true or false')
208
+ }
209
+ break
210
+ case 'boolean':
211
+ break
212
+ default:
199
213
  throw new Error('"' + field.alias + '" must be true or false')
200
- }
201
- break
202
- case 'boolean':
203
- break
204
- default:
205
- throw new Error('"' + field.alias + '" must be true or false')
214
+ }
206
215
  }
207
216
  break
208
217
  default:
package/tsconfig.json CHANGED
@@ -8,13 +8,14 @@
8
8
  "allowSyntheticDefaultImports": true,
9
9
  "target": "ES2021",
10
10
  "sourceMap": true,
11
- "outDir": "./dist",
12
- "baseUrl": "./",
11
+ "rootDir": ".",
13
12
  "incremental": true,
14
13
  "skipLibCheck": true,
14
+ "strict": false,
15
15
  "paths": {
16
- "@/*": ["src/*"]
17
- }
16
+ "@/*": ["./src/*"]
17
+ },
18
+ "types": ["node"]
18
19
  },
19
20
  "include": ["src/**/*"],
20
21
  "exclude": ["node_modules", "dist"]