@lenne.tech/nest-server 11.1.1 → 11.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.1.1",
3
+ "version": "11.1.2",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -319,6 +319,11 @@ export async function check(
319
319
  * Check if input is a valid Date format and return a new Date
320
320
  */
321
321
  export function checkAndGetDate(input: any): Date {
322
+ // Get timestamp from string
323
+ if (typeof input === 'string' && /^\d+$/.test(input)) {
324
+ input = parseInt(input, 10);
325
+ }
326
+
322
327
  // Create date from value
323
328
  const date = new Date(input);
324
329
 
@@ -36,6 +36,38 @@ export abstract class CorePersistenceModel extends CoreModel {
36
36
  return new Types.ObjectId(this.id);
37
37
  }
38
38
 
39
+ /**
40
+ * Getter for created date as Unix timestamp
41
+ */
42
+ @UnifiedField({
43
+ description: 'Created date (Unix timestamp)',
44
+ isOptional: true,
45
+ roles: RoleEnum.S_EVERYONE,
46
+ swaggerApiOptions: { example: 1740037703939, format: 'int64', type: Number },
47
+ })
48
+ get createdTs(): number {
49
+ if (this.createdAt instanceof Date) {
50
+ return this.createdAt.getTime();
51
+ }
52
+ return this.createdAt;
53
+ }
54
+
55
+ /**
56
+ * Getter for updated date as Unix timestamp
57
+ */
58
+ @UnifiedField({
59
+ description: 'Updated date (Unix timestamp)',
60
+ isOptional: true,
61
+ roles: RoleEnum.S_EVERYONE,
62
+ swaggerApiOptions: { example: 1740037703939, format: 'int64', type: Date },
63
+ })
64
+ get updatedTs(): number {
65
+ if (this.updatedAt instanceof Date) {
66
+ return this.updatedAt.getTime();
67
+ }
68
+ return this.updatedAt;
69
+ }
70
+
39
71
  // ===========================================================================
40
72
  // Properties
41
73
  // ===========================================================================
@@ -53,7 +85,7 @@ export abstract class CorePersistenceModel extends CoreModel {
53
85
  /**
54
86
  * Created date, is set automatically by mongoose
55
87
  */
56
- @Prop({ onCreate: () => new Date() })
88
+ @Prop()
57
89
  @UnifiedField({
58
90
  description: 'Created date',
59
91
  isOptional: true,
@@ -63,18 +95,10 @@ export abstract class CorePersistenceModel extends CoreModel {
63
95
  })
64
96
  createdAt: Date = undefined;
65
97
 
66
- @Prop({ onCreate: () => Date.now() })
67
- @UnifiedField({
68
- description: 'Created date (Unix timestamp)',
69
- roles: RoleEnum.S_EVERYONE,
70
- swaggerApiOptions: { example: 1740037703939, format: 'int64', type: Date },
71
- })
72
- createdTs: number = undefined;
73
-
74
98
  /**
75
99
  * Updated date is set automatically by mongoose
76
100
  */
77
- @Prop({ onUpdate: () => new Date() })
101
+ @Prop()
78
102
  @UnifiedField({
79
103
  description: 'Updated date',
80
104
  isOptional: true,
@@ -84,14 +108,6 @@ export abstract class CorePersistenceModel extends CoreModel {
84
108
  })
85
109
  updatedAt: Date = undefined;
86
110
 
87
- @Prop({ onUpdate: () => Date.now() })
88
- @UnifiedField({
89
- description: 'Updated date (Unix timestamp)',
90
- roles: RoleEnum.S_EVERYONE,
91
- swaggerApiOptions: { example: 1740037703939, format: 'int64', type: Date },
92
- })
93
- updatedTs: number = undefined;
94
-
95
111
  // ===========================================================================
96
112
  // Methods
97
113
  // ===========================================================================
@@ -103,9 +119,6 @@ export abstract class CorePersistenceModel extends CoreModel {
103
119
  super.init();
104
120
  this.createdAt = this.createdAt === undefined ? new Date() : this.createdAt;
105
121
  this.updatedAt = this.updatedAt === undefined ? this.createdAt : this.updatedAt;
106
-
107
- this.createdTs = this.createdTs === undefined ? Date.now() : this.createdTs;
108
- this.updatedTs = this.updatedTs === undefined ? this.createdTs : this.updatedTs;
109
122
  return this;
110
123
  }
111
124
 
@@ -116,8 +116,6 @@ export class User extends CoreUserModel implements PersistenceModel {
116
116
  this.createdBy = null;
117
117
  this.updatedAt = null;
118
118
  this.updatedBy = null;
119
- this.createdTs = null;
120
- this.updatedAt = null;
121
119
  }
122
120
 
123
121
  // Return prepared user