@webtypen/webframez-core 0.2.26 → 0.2.27

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,43 @@ 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
+ console.log("applyField ->", fieldPath, elementVal);
241
+ lodash_1.default.set(element, fieldPath, elementVal);
242
+ // lodash.set(
243
+ // element,
244
+ // fieldPath,
245
+ // value === undefined || value === null || (typeof value === "string" && value.trim() === "")
246
+ // ? null
247
+ // : customType && typeof customType.onSave === "function"
248
+ // ? await customType.onSave(value, { ...payload, ...fields[key].payload })
249
+ // : fields[key].type === "currency" || fields[key].type === "float"
250
+ // ? parseFloat(value.toString().replace(",", "."))
251
+ // : fields[key].type === "integer"
252
+ // ? parseInt(value)
253
+ // : value
254
+ // );
227
255
  }
228
256
  }
229
257
  return element;
@@ -307,14 +335,6 @@ class DataBuilder {
307
335
  catch (e) {
308
336
  throw e;
309
337
  }
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
338
  let changedId = null;
319
339
  if (updateId) {
320
340
  delete element[type.schema.primaryKey ? type.schema.primaryKey : "_id"];
@@ -339,6 +359,14 @@ class DataBuilder {
339
359
  : changedId;
340
360
  }
341
361
  }
362
+ try {
363
+ if (typeof type.schema.afterSave === "function") {
364
+ yield type.schema.afterSave(element, req);
365
+ }
366
+ }
367
+ catch (e) {
368
+ throw e;
369
+ }
342
370
  let redirect = undefined;
343
371
  const forms = typeof type.forms === "function" ? yield type.forms(req) : type.forms;
344
372
  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.27",
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,49 @@ 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
+ console.log("applyField ->", fieldPath, elementVal);
308
+ lodash.set(element, fieldPath, elementVal);
309
+ // lodash.set(
310
+ // element,
311
+ // fieldPath,
312
+ // value === undefined || value === null || (typeof value === "string" && value.trim() === "")
313
+ // ? null
314
+ // : customType && typeof customType.onSave === "function"
315
+ // ? await customType.onSave(value, { ...payload, ...fields[key].payload })
316
+ // : fields[key].type === "currency" || fields[key].type === "float"
317
+ // ? parseFloat(value.toString().replace(",", "."))
318
+ // : fields[key].type === "integer"
319
+ // ? parseInt(value)
320
+ // : value
321
+ // );
292
322
  }
293
323
  }
294
324
 
@@ -382,14 +412,6 @@ export class DataBuilder {
382
412
  throw e;
383
413
  }
384
414
 
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
415
  let changedId: any = null;
394
416
  if (updateId) {
395
417
  delete element[type.schema.primaryKey ? type.schema.primaryKey : "_id"];
@@ -418,6 +440,14 @@ export class DataBuilder {
418
440
  }
419
441
  }
420
442
 
443
+ try {
444
+ if (typeof type.schema.afterSave === "function") {
445
+ await type.schema.afterSave(element, req);
446
+ }
447
+ } catch (e: any) {
448
+ throw e;
449
+ }
450
+
421
451
  let redirect: any = undefined;
422
452
  const forms = typeof type.forms === "function" ? await type.forms(req) : type.forms;
423
453
  if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {