@atlantjs/backend 4.0.17 → 4.0.19
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/backend/application/databases/database.helper.abstract.d.ts +2 -2
- package/backend/application/databases/database.helper.abstract.js +8 -8
- package/backend/application/databases/database.helper.abstract.write.failure.d.ts +4 -0
- package/backend/application/databases/database.helper.abstract.write.failure.js +14 -0
- package/package.json +1 -1
- package/setup/server/default-error-handler-middleware.js +3 -3
- package/setup/server/server.js +1 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FailureAbstract, Newable, Optional, Return } from "@atlantjs/arch";
|
|
1
|
+
import { FailureAbstract, Newable, Optional, Return, UuidAbstract } from "@atlantjs/arch";
|
|
2
2
|
import { DataSource, FindOptionsRelations, ObjectLiteral } from "typeorm";
|
|
3
3
|
import { DatabaseLiteConfigAbstract } from "./database-lite.config";
|
|
4
4
|
import { DatabaseConfigAbstract } from "./database.config";
|
|
@@ -11,7 +11,7 @@ export declare abstract class DatabaseHelperAbstract {
|
|
|
11
11
|
read<T extends Newable<ObjectLiteral>, E extends ObjectLiteral>(schema: T, condition: {
|
|
12
12
|
[K in keyof InstanceType<T>]?: InstanceType<T>[K];
|
|
13
13
|
}, relations: FindOptionsRelations<E>): Promise<Return<Optional<InstanceType<T>[]>, FailureAbstract>>;
|
|
14
|
-
write<T extends Newable<ObjectLiteral>>(schema: T, entity: EntityAbstract): Promise<Return<
|
|
14
|
+
write<T extends Newable<ObjectLiteral>>(schema: T, entity: EntityAbstract): Promise<Return<UuidAbstract, FailureAbstract>>;
|
|
15
15
|
delete<T extends Newable<ObjectLiteral>>(entity: T, condition: {
|
|
16
16
|
[K in keyof InstanceType<T>]?: InstanceType<T>[K];
|
|
17
17
|
}): Promise<Return<undefined, undefined>>;
|
|
@@ -5,6 +5,7 @@ const arch_1 = require("@atlantjs/arch");
|
|
|
5
5
|
const database_helper_abstract_commit_failure_1 = require("./database.helper.abstract.commit.failure");
|
|
6
6
|
const database_helper_abstract_get_manager_failure_1 = require("./database.helper.abstract.get-manager.failure");
|
|
7
7
|
const database_helper_abstract_rollback_failure_1 = require("./database.helper.abstract.rollback.failure");
|
|
8
|
+
const database_helper_abstract_write_failure_1 = require("./database.helper.abstract.write.failure");
|
|
8
9
|
class DatabaseHelperAbstract {
|
|
9
10
|
constructor() {
|
|
10
11
|
this.database = arch_1.Nothing;
|
|
@@ -35,25 +36,24 @@ class DatabaseHelperAbstract {
|
|
|
35
36
|
try {
|
|
36
37
|
const client = await this.openTransaction();
|
|
37
38
|
const repository = client.getRepository(schema);
|
|
38
|
-
if (arch_1._.isUndefined(entity.toSchema) ||
|
|
39
|
-
arch_1.
|
|
40
|
-
return (0, arch_1.Failure)();
|
|
39
|
+
if (arch_1._.isUndefined(entity.toSchema) || arch_1._.isUndefined(entity.id)) {
|
|
40
|
+
return (0, arch_1.Failure)(new database_helper_abstract_write_failure_1.DatabaseHelperAbstractWriteFailure());
|
|
41
41
|
}
|
|
42
|
-
const
|
|
42
|
+
const registryFoundedPacked = (0, arch_1.Optional)(await repository.findOne({
|
|
43
43
|
where: { id: entity.id.toString() },
|
|
44
44
|
}));
|
|
45
|
-
if (
|
|
45
|
+
if (registryFoundedPacked.hasNothing()) {
|
|
46
46
|
await repository.save(entity.toSchema());
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
await repository.update({ id: entity.id.toString() }, entity.toSchema());
|
|
50
50
|
}
|
|
51
51
|
await this.commit();
|
|
52
|
-
return (0, arch_1.Success)();
|
|
52
|
+
return (0, arch_1.Success)(entity.id);
|
|
53
53
|
}
|
|
54
|
-
catch {
|
|
54
|
+
catch (error) {
|
|
55
55
|
await this.rollback();
|
|
56
|
-
return (0, arch_1.Failure)();
|
|
56
|
+
return (0, arch_1.Failure)(new database_helper_abstract_write_failure_1.DatabaseHelperAbstractWriteFailure(error));
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
async delete(entity, condition) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseHelperAbstractWriteFailure = void 0;
|
|
4
|
+
const arch_1 = require("@atlantjs/arch");
|
|
5
|
+
class DatabaseHelperAbstractWriteFailure extends arch_1.FailureAbstract {
|
|
6
|
+
constructor(error) {
|
|
7
|
+
super({
|
|
8
|
+
className: DatabaseHelperAbstractWriteFailure.name,
|
|
9
|
+
message: "Failed to insert or update the record in the database",
|
|
10
|
+
error,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DatabaseHelperAbstractWriteFailure = DatabaseHelperAbstractWriteFailure;
|
package/package.json
CHANGED
|
@@ -22,11 +22,11 @@ class DefaultErrorHandlerMiddleware {
|
|
|
22
22
|
}
|
|
23
23
|
handleError(error, res) {
|
|
24
24
|
if (!(error instanceof routing_controllers_1.HttpError)) {
|
|
25
|
-
|
|
26
|
-
return
|
|
25
|
+
this.handleExceptions(error, res);
|
|
26
|
+
return;
|
|
27
27
|
}
|
|
28
28
|
if (error.httpCode < arch_1.HttpStatusCodes.INTERNAL_SERVER_ERROR) {
|
|
29
|
-
res.status(error.httpCode).send(lodash_1.default.omit(error, "httpCode"));
|
|
29
|
+
res.status(error.httpCode).send(lodash_1.default.omit(error, "httpCode", "stack"));
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
res.status(error.httpCode).send({
|
package/setup/server/server.js
CHANGED
|
@@ -49,11 +49,10 @@ class Server {
|
|
|
49
49
|
exports.Server = Server;
|
|
50
50
|
Server.instance = (0, express_1.default)();
|
|
51
51
|
Server.routingOptions = {
|
|
52
|
-
routePrefix: "/",
|
|
53
52
|
validation: true,
|
|
54
53
|
classTransformer: true,
|
|
55
54
|
plainToClassTransformOptions: {
|
|
56
55
|
enableImplicitConversion: false,
|
|
57
56
|
},
|
|
58
|
-
defaultErrorHandler:
|
|
57
|
+
defaultErrorHandler: true,
|
|
59
58
|
};
|