@comasoft/nestjs 0.0.93 → 0.0.94

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.
@@ -0,0 +1 @@
1
+ export declare function DeleteColumns(): (constructor: new (...args: any[]) => any) => void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeleteColumns = DeleteColumns;
4
+ const typeorm_1 = require("typeorm");
5
+ function DeleteColumns() {
6
+ return function (constructor) {
7
+ (0, typeorm_1.Column)({
8
+ type: 'boolean',
9
+ default: false,
10
+ })(constructor.prototype, 'is_deleted');
11
+ (0, typeorm_1.Column)({
12
+ type: 'int',
13
+ nullable: true,
14
+ })(constructor.prototype, 'deleted_by');
15
+ (0, typeorm_1.Column)({
16
+ type: 'timestamp',
17
+ precision: 3,
18
+ nullable: true,
19
+ })(constructor.prototype, 'deleted_at');
20
+ Object.defineProperty(constructor.prototype, 'deleted_by', {
21
+ set(value) {
22
+ this._deleted_by = value;
23
+ if (value !== null) {
24
+ this.is_deleted = true;
25
+ this.deleted_at = new Date();
26
+ }
27
+ },
28
+ get() {
29
+ return this._deleted_by;
30
+ },
31
+ });
32
+ };
33
+ }
@@ -5,3 +5,4 @@ export * from './user.decorator';
5
5
  export * from './auth.decorator.factory';
6
6
  export * from './cookies.decorator';
7
7
  export * from './timestamps.decorator';
8
+ export * from './soft-delete.decorator';
@@ -21,3 +21,4 @@ __exportStar(require("./user.decorator"), exports);
21
21
  __exportStar(require("./auth.decorator.factory"), exports);
22
22
  __exportStar(require("./cookies.decorator"), exports);
23
23
  __exportStar(require("./timestamps.decorator"), exports);
24
+ __exportStar(require("./soft-delete.decorator"), exports);
@@ -0,0 +1 @@
1
+ export declare function SoftDelete(): (constructor: new (...args: any[]) => any) => void;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SoftDelete = SoftDelete;
4
+ const typeorm_1 = require("typeorm");
5
+ function SoftDelete() {
6
+ return function (constructor) {
7
+ (0, typeorm_1.Column)({
8
+ type: 'boolean',
9
+ default: false,
10
+ })(constructor.prototype, 'is_deleted');
11
+ (0, typeorm_1.Index)('idx_deleted_id', ['is_deleted', 'id'])(constructor);
12
+ (0, typeorm_1.Column)({
13
+ type: 'int',
14
+ nullable: true,
15
+ unsigned: true,
16
+ })(constructor.prototype, 'deleted_by');
17
+ (0, typeorm_1.Column)({
18
+ type: 'timestamp',
19
+ precision: 3,
20
+ nullable: true,
21
+ })(constructor.prototype, 'deleted_at');
22
+ Object.defineProperty(constructor.prototype, 'deleted_by', {
23
+ set(value) {
24
+ this._deleted_by = value;
25
+ if (value !== null) {
26
+ this.is_deleted = true;
27
+ this.deleted_at = new Date();
28
+ }
29
+ },
30
+ get() {
31
+ return this._deleted_by;
32
+ },
33
+ });
34
+ };
35
+ }
@@ -1,7 +1,6 @@
1
1
  interface TimestampsOptions {
2
2
  created_at?: boolean;
3
3
  updated_at?: boolean;
4
- deleted_at?: boolean;
5
4
  }
6
5
  export declare function Timestamps(options?: TimestampsOptions): (constructor: new (...args: any[]) => any) => void;
7
6
  export {};
@@ -5,18 +5,21 @@ const typeorm_1 = require("typeorm");
5
5
  function Timestamps(options = {
6
6
  created_at: true,
7
7
  updated_at: true,
8
- deleted_at: true,
9
8
  }) {
10
9
  return function (constructor) {
11
10
  if (options.created_at !== false) {
12
- (0, typeorm_1.CreateDateColumn)({ type: 'timestamp', precision: 3 })(constructor.prototype, 'created_at');
11
+ (0, typeorm_1.CreateDateColumn)({
12
+ type: 'timestamp',
13
+ precision: 3,
14
+ default: () => 'CURRENT_TIMESTAMP(3)',
15
+ })(constructor.prototype, 'created_at');
13
16
  }
14
17
  if (options.updated_at !== false) {
15
18
  (0, typeorm_1.Column)({
16
19
  type: 'timestamp',
17
20
  precision: 3,
18
21
  default: null,
19
- onUpdate: 'now()',
22
+ onUpdate: 'CURRENT_TIMESTAMP(3)',
20
23
  nullable: true,
21
24
  })(constructor.prototype, 'updated_at');
22
25
  (0, typeorm_1.BeforeUpdate)()(constructor.prototype, 'updateDate');
@@ -146,6 +146,6 @@ function applySorting(queryBuilder, sort, aliasName) {
146
146
  });
147
147
  }
148
148
  else {
149
- queryBuilder.orderBy(`${aliasName}.id`, 'DESC');
149
+ queryBuilder.orderBy(`${aliasName}.created_at`, 'DESC');
150
150
  }
151
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comasoft/nestjs",
3
- "version": "0.0.93",
3
+ "version": "0.0.94",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "scripts": {