@comasoft/nestjs 0.0.6 → 0.0.8

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.
@@ -4,3 +4,4 @@ export * from './patch-body.decorator';
4
4
  export * from './user.decorator';
5
5
  export * from './auth.decorator.factory';
6
6
  export * from './cookies.decorator';
7
+ export * from './timestamps.decorator';
@@ -20,3 +20,4 @@ __exportStar(require("./patch-body.decorator"), exports);
20
20
  __exportStar(require("./user.decorator"), exports);
21
21
  __exportStar(require("./auth.decorator.factory"), exports);
22
22
  __exportStar(require("./cookies.decorator"), exports);
23
+ __exportStar(require("./timestamps.decorator"), exports);
@@ -0,0 +1,7 @@
1
+ interface TimestampsOptions {
2
+ created_at?: boolean;
3
+ updated_at?: boolean;
4
+ deleted_at?: boolean;
5
+ }
6
+ export declare function Timestamps(options?: TimestampsOptions): (constructor: new (...args: any[]) => any) => void;
7
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Timestamps = Timestamps;
4
+ const typeorm_1 = require("typeorm");
5
+ function Timestamps(options = {
6
+ created_at: true,
7
+ updated_at: true,
8
+ deleted_at: true,
9
+ }) {
10
+ return function (constructor) {
11
+ if (options.created_at !== false) {
12
+ (0, typeorm_1.CreateDateColumn)({ type: 'timestamp', precision: 3 })(constructor.prototype, 'created_at');
13
+ }
14
+ if (options.updated_at !== false) {
15
+ (0, typeorm_1.Column)({
16
+ type: 'timestamp',
17
+ precision: 3,
18
+ default: null,
19
+ onUpdate: 'now()',
20
+ nullable: true,
21
+ })(constructor.prototype, 'updated_at');
22
+ (0, typeorm_1.BeforeUpdate)()(constructor.prototype, 'updateDate');
23
+ constructor.prototype.updateDate = function () {
24
+ this.updated_at = new Date();
25
+ };
26
+ }
27
+ if (options.deleted_at !== false) {
28
+ (0, typeorm_1.DeleteDateColumn)({ type: 'timestamp', precision: 3, nullable: true })(constructor.prototype, 'deleted_at');
29
+ }
30
+ };
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comasoft/nestjs",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "scripts": {