@bearei/server-common 1.2.3 → 1.3.0
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/dist/app.entity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseEntity } from 'typeorm';
|
|
1
|
+
import { BaseEntity, EntitySubscriberInterface, InsertEvent } from 'typeorm';
|
|
2
2
|
import type { EntityStatus } from './app.interface';
|
|
3
3
|
export declare class CommonEntity extends BaseEntity {
|
|
4
4
|
primaryId: number;
|
|
@@ -10,8 +10,12 @@ export declare class CommonEntity extends BaseEntity {
|
|
|
10
10
|
sort: number;
|
|
11
11
|
deletedAt: Date;
|
|
12
12
|
beforeInsert(): void;
|
|
13
|
-
afterInsert():
|
|
13
|
+
afterInsert(): void;
|
|
14
14
|
beforeUpdate(): void;
|
|
15
15
|
beforeSoftRemove(): void;
|
|
16
16
|
beforeRecover(): void;
|
|
17
17
|
}
|
|
18
|
+
export declare class CommonEntitySubscriber implements EntitySubscriberInterface<CommonEntity> {
|
|
19
|
+
listenTo(): typeof CommonEntity;
|
|
20
|
+
afterInsert(event: InsertEvent<CommonEntity>): void;
|
|
21
|
+
}
|
package/dist/app.entity.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.CommonEntity = void 0;
|
|
15
|
+
exports.CommonEntitySubscriber = exports.CommonEntity = void 0;
|
|
16
16
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
17
17
|
const nanoid_1 = require("nanoid");
|
|
18
18
|
const typeorm_1 = require("typeorm");
|
|
@@ -30,9 +30,8 @@ let CommonEntity = class CommonEntity extends typeorm_1.BaseEntity {
|
|
|
30
30
|
this.createdAt = dayjs_1.default.utc().toDate();
|
|
31
31
|
this.id = (0, nanoid_1.nanoid)();
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
afterInsert() {
|
|
34
34
|
this.sort = this.primaryId;
|
|
35
|
-
await this.save();
|
|
36
35
|
}
|
|
37
36
|
beforeUpdate() {
|
|
38
37
|
this.updatedAt = dayjs_1.default.utc().toDate();
|
|
@@ -94,7 +93,7 @@ __decorate([
|
|
|
94
93
|
(0, typeorm_1.AfterInsert)(),
|
|
95
94
|
__metadata("design:type", Function),
|
|
96
95
|
__metadata("design:paramtypes", []),
|
|
97
|
-
__metadata("design:returntype",
|
|
96
|
+
__metadata("design:returntype", void 0)
|
|
98
97
|
], CommonEntity.prototype, "afterInsert", null);
|
|
99
98
|
__decorate([
|
|
100
99
|
(0, typeorm_1.BeforeUpdate)(),
|
|
@@ -119,4 +118,19 @@ exports.CommonEntity = CommonEntity = __decorate([
|
|
|
119
118
|
(0, typeorm_1.Index)(['id'], { unique: true }),
|
|
120
119
|
(0, typeorm_1.Index)(['sort'])
|
|
121
120
|
], CommonEntity);
|
|
121
|
+
let CommonEntitySubscriber = class CommonEntitySubscriber {
|
|
122
|
+
listenTo() {
|
|
123
|
+
return CommonEntity;
|
|
124
|
+
}
|
|
125
|
+
afterInsert(event) {
|
|
126
|
+
const { entity, manager } = event;
|
|
127
|
+
if (entity.primaryId) {
|
|
128
|
+
manager.update(CommonEntity, { primaryId: entity.primaryId }, { sort: entity.primaryId });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
exports.CommonEntitySubscriber = CommonEntitySubscriber;
|
|
133
|
+
exports.CommonEntitySubscriber = CommonEntitySubscriber = __decorate([
|
|
134
|
+
(0, typeorm_1.EventSubscriber)()
|
|
135
|
+
], CommonEntitySubscriber);
|
|
122
136
|
//# sourceMappingURL=app.entity.js.map
|
package/dist/app.entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.entity.js","sourceRoot":"","sources":["../src/app.entity.ts"],"names":[],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KAAgC;QAC3C,MAAM,EAAC,MAAM,EAAE,OAAO,EAAC,GAAG,KAAK,CAAA;QAE/B,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAC,SAAS,EAAE,MAAM,CAAC,SAAS,EAAC,EAAE,EAAC,IAAI,EAAE,MAAM,CAAC,SAAS,EAAC,CAAC,CAAA;QACtF,CAAC;IACF,CAAC;CACD,CAAA;AAZY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,yBAAe,GAAE;GACL,sBAAsB,CAYlC"}
|
|
@@ -11,6 +11,7 @@ exports.DatabaseModule = void 0;
|
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const config_1 = require("@nestjs/config");
|
|
13
13
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
14
|
+
const app_entity_1 = require("../app.entity");
|
|
14
15
|
let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
15
16
|
static forRoot(options = {}) {
|
|
16
17
|
return {
|
|
@@ -28,6 +29,7 @@ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
|
28
29
|
logging: false,
|
|
29
30
|
password: configService.get('database.password'),
|
|
30
31
|
port: configService.get('database.port'),
|
|
32
|
+
subscribers: [app_entity_1.CommonEntitySubscriber],
|
|
31
33
|
synchronize: false,
|
|
32
34
|
type: configService.get('database.type'),
|
|
33
35
|
username: configService.get('database.username'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.module.js","sourceRoot":"","sources":["../../src/database/database.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AACpD,2CAA0D;AAC1D,6CAAmE;
|
|
1
|
+
{"version":3,"file":"database.module.js","sourceRoot":"","sources":["../../src/database/database.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AACpD,2CAA0D;AAC1D,6CAAmE;AACnE,8CAAoD;AAG7C,IAAM,cAAc,sBAApB,M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