@atlantjs/backend 5.0.3 → 5.0.4
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.delete.failure.d.ts +4 -0
- package/backend/application/databases/database.helper.abstract.delete.failure.js +14 -0
- package/backend/application/databases/database.helper.abstract.js +16 -6
- package/backend/infrastructure/repositories/schemas/schema.abstract.d.ts +4 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -20,9 +20,9 @@ export declare abstract class DatabaseHelperAbstract {
|
|
|
20
20
|
[K in keyof InstanceType<T>]?: InstanceType<T>[K];
|
|
21
21
|
}, relations: FindOptionsRelations<E>): Promise<Return<Optional<InstanceType<T>[]>, FailureAbstract>>;
|
|
22
22
|
write(schemaEntities: SchemaEntity[]): Promise<Return<SchemaEntityReturn[], FailureAbstract>>;
|
|
23
|
-
delete<T extends Newable<ObjectLiteral>>(
|
|
23
|
+
delete<T extends Newable<ObjectLiteral>>(schema: T, condition: {
|
|
24
24
|
[K in keyof InstanceType<T>]?: InstanceType<T>[K];
|
|
25
|
-
}): Promise<Return<undefined,
|
|
25
|
+
}, isSoft?: boolean): Promise<Return<undefined, FailureAbstract>>;
|
|
26
26
|
private getManager;
|
|
27
27
|
private openTransaction;
|
|
28
28
|
private commit;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseHelperAbstractDeleteFailure = void 0;
|
|
4
|
+
const arch_1 = require("@atlantjs/arch");
|
|
5
|
+
class DatabaseHelperAbstractDeleteFailure extends arch_1.FailureAbstract {
|
|
6
|
+
constructor(isSoft, error) {
|
|
7
|
+
super({
|
|
8
|
+
className: DatabaseHelperAbstractDeleteFailure.name,
|
|
9
|
+
message: `Failed to ${arch_1._.isTruthy(isSoft) ? "soft" : "hard"} delete the record in the database`,
|
|
10
|
+
error,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.DatabaseHelperAbstractDeleteFailure = DatabaseHelperAbstractDeleteFailure;
|
|
@@ -6,6 +6,7 @@ const database_helper_abstract_commit_failure_1 = require("./database.helper.abs
|
|
|
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
8
|
const database_helper_abstract_write_failure_1 = require("./database.helper.abstract.write.failure");
|
|
9
|
+
const database_helper_abstract_delete_failure_1 = require("./database.helper.abstract.delete.failure");
|
|
9
10
|
class DatabaseHelperAbstract {
|
|
10
11
|
constructor() {
|
|
11
12
|
this.database = arch_1.Nothing;
|
|
@@ -64,14 +65,23 @@ class DatabaseHelperAbstract {
|
|
|
64
65
|
return (0, arch_1.Failure)(new database_helper_abstract_write_failure_1.DatabaseHelperAbstractWriteFailure(error));
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
|
-
async delete(
|
|
68
|
+
async delete(schema, condition, isSoft = true) {
|
|
68
69
|
const client = await this.openTransaction();
|
|
69
|
-
const repository = client.getRepository(
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
return (0, arch_1.Failure)();
|
|
70
|
+
const repository = client.getRepository(schema);
|
|
71
|
+
const registriesPacked = (0, arch_1.Optional)(await repository.find({ where: condition }));
|
|
72
|
+
if (registriesPacked.hasNothing()) {
|
|
73
|
+
return (0, arch_1.Failure)(new database_helper_abstract_delete_failure_1.DatabaseHelperAbstractDeleteFailure(isSoft));
|
|
74
|
+
}
|
|
75
|
+
if (arch_1._.isFalsy(isSoft)) {
|
|
76
|
+
repository.delete(condition);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const registries = registriesPacked.unpack();
|
|
80
|
+
for (const registry of registries) {
|
|
81
|
+
registry.deleted = true;
|
|
82
|
+
await repository.update({ id: registry.id.toString() }, registry);
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
|
-
repository.delete(condition);
|
|
75
85
|
return (0, arch_1.Success)();
|
|
76
86
|
}
|
|
77
87
|
getManager() {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { EntityAbstract } from "../../../domain/entities/entity.abstract";
|
|
2
2
|
export declare abstract class SchemaAbstract {
|
|
3
|
+
abstract id: string;
|
|
4
|
+
abstract deleted: boolean;
|
|
5
|
+
abstract createdAt: string;
|
|
6
|
+
abstract updatedAt: string;
|
|
3
7
|
abstract toSolid(): EntityAbstract;
|
|
4
8
|
}
|