@webtypen/webframez-core 0.3.8 → 0.3.10
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.
|
@@ -65,7 +65,7 @@ class ConsoleCommand {
|
|
|
65
65
|
return this.args.options[name] || null;
|
|
66
66
|
}
|
|
67
67
|
write(message, options) {
|
|
68
|
-
ConsoleOutputHelper_1.ConsoleOutputHelper.
|
|
68
|
+
ConsoleOutputHelper_1.ConsoleOutputHelper.write(message, options);
|
|
69
69
|
return this;
|
|
70
70
|
}
|
|
71
71
|
writeln(message, options) {
|
|
@@ -347,11 +347,11 @@ class DataBuilder {
|
|
|
347
347
|
}
|
|
348
348
|
save(db, req) {
|
|
349
349
|
return __awaiter(this, void 0, void 0, function* () {
|
|
350
|
-
if (!req || !req.body || typeof req.body !== "object"
|
|
351
|
-
throw new Error("Missing
|
|
350
|
+
if (!req || !req.body || typeof req.body !== "object") {
|
|
351
|
+
throw new Error("Missing request-body ...");
|
|
352
352
|
}
|
|
353
353
|
if (typeof req.body.data !== "object") {
|
|
354
|
-
throw new Error("Missing
|
|
354
|
+
throw new Error("Missing request-data ...");
|
|
355
355
|
}
|
|
356
356
|
const type = this.getTypeFromRequest(req.body);
|
|
357
357
|
if (!type || !type.schema || !type.schema.fields) {
|
|
@@ -365,6 +365,39 @@ class DataBuilder {
|
|
|
365
365
|
errors: errors,
|
|
366
366
|
};
|
|
367
367
|
}
|
|
368
|
+
if (type.unmapped) {
|
|
369
|
+
try {
|
|
370
|
+
if (typeof type.schema.afterSave === "function") {
|
|
371
|
+
yield type.schema.beforeSave(req.body.data, req);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
throw e;
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
if (typeof type.schema.afterSave === "function") {
|
|
379
|
+
yield type.schema.afterSave(req.body.data, req);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (e) {
|
|
383
|
+
throw e;
|
|
384
|
+
}
|
|
385
|
+
let redirect = undefined;
|
|
386
|
+
const forms = typeof type.forms === "function" ? yield type.forms(req) : type.forms;
|
|
387
|
+
if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {
|
|
388
|
+
redirect = yield forms.main.onSaveRedirect(req.body.data, req);
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
status: "success",
|
|
392
|
+
data: {
|
|
393
|
+
_id: req.body.data._id ? req.body.data._id : "__unmapped",
|
|
394
|
+
redirect: redirect,
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
if (!req.body.__builder_id || req.body.__builder_id.toString().trim() === "") {
|
|
399
|
+
throw new Error("Missing id ...");
|
|
400
|
+
}
|
|
368
401
|
const collection = type.schema && type.schema.collection ? type.schema.collection : undefined;
|
|
369
402
|
if (!collection || collection.trim() === "") {
|
|
370
403
|
throw new Error("Missing collection ...");
|
package/package.json
CHANGED
|
@@ -24,6 +24,7 @@ export type DataBuilderType = {
|
|
|
24
24
|
plural: string;
|
|
25
25
|
schema: DataBuilderSchema;
|
|
26
26
|
forms?: { [key: string]: any };
|
|
27
|
+
unmapped?: boolean;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
export type DataBuilderFieldType =
|
|
@@ -425,12 +426,12 @@ export class DataBuilder {
|
|
|
425
426
|
}
|
|
426
427
|
|
|
427
428
|
async save(db: any, req: any) {
|
|
428
|
-
if (!req || !req.body || typeof req.body !== "object"
|
|
429
|
-
throw new Error("Missing
|
|
429
|
+
if (!req || !req.body || typeof req.body !== "object") {
|
|
430
|
+
throw new Error("Missing request-body ...");
|
|
430
431
|
}
|
|
431
432
|
|
|
432
433
|
if (typeof req.body.data !== "object") {
|
|
433
|
-
throw new Error("Missing
|
|
434
|
+
throw new Error("Missing request-data ...");
|
|
434
435
|
}
|
|
435
436
|
|
|
436
437
|
const type = this.getTypeFromRequest(req.body);
|
|
@@ -447,6 +448,42 @@ export class DataBuilder {
|
|
|
447
448
|
};
|
|
448
449
|
}
|
|
449
450
|
|
|
451
|
+
if (type.unmapped) {
|
|
452
|
+
try {
|
|
453
|
+
if (typeof type.schema.afterSave === "function") {
|
|
454
|
+
await type.schema.beforeSave(req.body.data, req);
|
|
455
|
+
}
|
|
456
|
+
} catch (e: any) {
|
|
457
|
+
throw e;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
try {
|
|
461
|
+
if (typeof type.schema.afterSave === "function") {
|
|
462
|
+
await type.schema.afterSave(req.body.data, req);
|
|
463
|
+
}
|
|
464
|
+
} catch (e: any) {
|
|
465
|
+
throw e;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
let redirect: any = undefined;
|
|
469
|
+
const forms = typeof type.forms === "function" ? await type.forms(req) : type.forms;
|
|
470
|
+
if (forms && forms.main && forms.main.onSaveRedirect && typeof forms.main.onSaveRedirect === "function") {
|
|
471
|
+
redirect = await forms.main.onSaveRedirect(req.body.data, req);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
return {
|
|
475
|
+
status: "success",
|
|
476
|
+
data: {
|
|
477
|
+
_id: req.body.data._id ? req.body.data._id : "__unmapped",
|
|
478
|
+
redirect: redirect,
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (!req.body.__builder_id || req.body.__builder_id.toString().trim() === "") {
|
|
484
|
+
throw new Error("Missing id ...");
|
|
485
|
+
}
|
|
486
|
+
|
|
450
487
|
const collection = type.schema && type.schema.collection ? type.schema.collection : undefined;
|
|
451
488
|
if (!collection || collection.trim() === "") {
|
|
452
489
|
throw new Error("Missing collection ...");
|