@webtypen/webframez-core 0.2.26 → 0.2.28

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.
@@ -215,15 +215,42 @@ class DataBuilder {
215
215
  }
216
216
  }
217
217
  else {
218
- lodash_1.default.set(element, fieldPath, value === undefined || value === null || (typeof value === "string" && value.trim() === "")
219
- ? null
220
- : customType && typeof customType.onSave === "function"
221
- ? yield customType.onSave(value, Object.assign(Object.assign({}, payload), fields[key].payload))
222
- : fields[key].type === "currency" || fields[key].type === "float"
223
- ? parseFloat(value.toString().replace(",", "."))
224
- : fields[key].type === "integer"
225
- ? parseInt(value)
226
- : value);
218
+ let elementVal = null;
219
+ if (value !== undefined &&
220
+ value !== null &&
221
+ !(typeof value === "string" && value.trim() === "") &&
222
+ !(typeof value === "number" && value.toString().trim() === "")) {
223
+ // Custom field onSave
224
+ if (customType && typeof customType.onSave === "function") {
225
+ elementVal = yield customType.onSave(value, Object.assign(Object.assign({}, payload), fields[key].payload));
226
+ }
227
+ // Float or currency fields
228
+ else if (fields[key].type === "currency" || fields[key].type === "float") {
229
+ elementVal = parseFloat(value.toString().replace(",", "."));
230
+ }
231
+ // Integer field
232
+ else if (fields[key].type === "integer") {
233
+ elementVal = parseInt(value);
234
+ }
235
+ // Standard
236
+ else {
237
+ elementVal = value;
238
+ }
239
+ }
240
+ lodash_1.default.set(element, fieldPath, elementVal);
241
+ // lodash.set(
242
+ // element,
243
+ // fieldPath,
244
+ // value === undefined || value === null || (typeof value === "string" && value.trim() === "")
245
+ // ? null
246
+ // : customType && typeof customType.onSave === "function"
247
+ // ? await customType.onSave(value, { ...payload, ...fields[key].payload })
248
+ // : fields[key].type === "currency" || fields[key].type === "float"
249
+ // ? parseFloat(value.toString().replace(",", "."))
250
+ // : fields[key].type === "integer"
251
+ // ? parseInt(value)
252
+ // : value
253
+ // );
227
254
  }
228
255
  }
229
256
  return element;
@@ -307,14 +334,6 @@ class DataBuilder {
307
334
  catch (e) {
308
335
  throw e;
309
336
  }
310
- try {
311
- if (typeof type.schema.afterSave === "function") {
312
- yield type.schema.afterSave(element, req);
313
- }
314
- }
315
- catch (e) {
316
- throw e;
317
- }
318
337
  let changedId = null;
319
338
  if (updateId) {
320
339
  delete element[type.schema.primaryKey ? type.schema.primaryKey : "_id"];
@@ -339,6 +358,14 @@ class DataBuilder {
339
358
  : changedId;
340
359
  }
341
360
  }
361
+ try {
362
+ if (typeof type.schema.afterSave === "function") {
363
+ yield type.schema.afterSave(element, req);
364
+ }
365
+ }
366
+ catch (e) {
367
+ throw e;
368
+ }
342
369
  let redirect = undefined;
343
370
  const forms = typeof type.forms === "function" ? yield type.forms(req) : type.forms;
344
371
  if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -276,19 +276,48 @@ export class DataBuilder {
276
276
  );
277
277
  }
278
278
  } else {
279
- lodash.set(
280
- element,
281
- fieldPath,
282
- value === undefined || value === null || (typeof value === "string" && value.trim() === "")
283
- ? null
284
- : customType && typeof customType.onSave === "function"
285
- ? await customType.onSave(value, { ...payload, ...fields[key].payload })
286
- : fields[key].type === "currency" || fields[key].type === "float"
287
- ? parseFloat(value.toString().replace(",", "."))
288
- : fields[key].type === "integer"
289
- ? parseInt(value)
290
- : value
291
- );
279
+ let elementVal = null;
280
+ if (
281
+ value !== undefined &&
282
+ value !== null &&
283
+ !(typeof value === "string" && value.trim() === "") &&
284
+ !(typeof value === "number" && value.toString().trim() === "")
285
+ ) {
286
+ // Custom field onSave
287
+ if (customType && typeof customType.onSave === "function") {
288
+ elementVal = await customType.onSave(value, { ...payload, ...fields[key].payload });
289
+ }
290
+
291
+ // Float or currency fields
292
+ else if (fields[key].type === "currency" || fields[key].type === "float") {
293
+ elementVal = parseFloat(value.toString().replace(",", "."));
294
+ }
295
+
296
+ // Integer field
297
+ else if (fields[key].type === "integer") {
298
+ elementVal = parseInt(value);
299
+ }
300
+
301
+ // Standard
302
+ else {
303
+ elementVal = value;
304
+ }
305
+ }
306
+
307
+ lodash.set(element, fieldPath, elementVal);
308
+ // lodash.set(
309
+ // element,
310
+ // fieldPath,
311
+ // value === undefined || value === null || (typeof value === "string" && value.trim() === "")
312
+ // ? null
313
+ // : customType && typeof customType.onSave === "function"
314
+ // ? await customType.onSave(value, { ...payload, ...fields[key].payload })
315
+ // : fields[key].type === "currency" || fields[key].type === "float"
316
+ // ? parseFloat(value.toString().replace(",", "."))
317
+ // : fields[key].type === "integer"
318
+ // ? parseInt(value)
319
+ // : value
320
+ // );
292
321
  }
293
322
  }
294
323
 
@@ -382,14 +411,6 @@ export class DataBuilder {
382
411
  throw e;
383
412
  }
384
413
 
385
- try {
386
- if (typeof type.schema.afterSave === "function") {
387
- await type.schema.afterSave(element, req);
388
- }
389
- } catch (e: any) {
390
- throw e;
391
- }
392
-
393
414
  let changedId: any = null;
394
415
  if (updateId) {
395
416
  delete element[type.schema.primaryKey ? type.schema.primaryKey : "_id"];
@@ -418,6 +439,14 @@ export class DataBuilder {
418
439
  }
419
440
  }
420
441
 
442
+ try {
443
+ if (typeof type.schema.afterSave === "function") {
444
+ await type.schema.afterSave(element, req);
445
+ }
446
+ } catch (e: any) {
447
+ throw e;
448
+ }
449
+
421
450
  let redirect: any = undefined;
422
451
  const forms = typeof type.forms === "function" ? await type.forms(req) : type.forms;
423
452
  if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {