payservedb 6.6.1 → 6.6.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": "payservedb",
3
- "version": "6.6.1",
3
+ "version": "6.6.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -40,7 +40,7 @@ const userDetailsSchema = new mongoose.Schema(
40
40
  required: false,
41
41
  },
42
42
  },
43
- { _id: false }
43
+ { _id: false },
44
44
  );
45
45
 
46
46
  // Main audit trail schema
@@ -125,6 +125,14 @@ const auditTrailSchema = new mongoose.Schema(
125
125
  required: true,
126
126
  },
127
127
 
128
+ // response status
129
+ response_status: {
130
+ type: String,
131
+ required: true,
132
+ enum: ["success", "error", "unknown"],
133
+ default: "unknown",
134
+ },
135
+
128
136
  // Method-specific data
129
137
  previous_data: {
130
138
  type: mongoose.Schema.Types.Mixed,
@@ -149,7 +157,7 @@ const auditTrailSchema = new mongoose.Schema(
149
157
  },
150
158
  {
151
159
  timestamps: true,
152
- }
160
+ },
153
161
  );
154
162
 
155
163
  // Pre-save middleware for data validation and cleanup
@@ -202,7 +210,11 @@ auditTrailSchema.statics.findByActivity = function (activity, limit = 100) {
202
210
  .limit(limit);
203
211
  };
204
212
 
205
- auditTrailSchema.statics.findByFacility = function (facilityId, startDate, endDate) {
213
+ auditTrailSchema.statics.findByFacility = function (
214
+ facilityId,
215
+ startDate,
216
+ endDate,
217
+ ) {
206
218
  const query = { "route_params.facilityId": facilityId };
207
219
  if (startDate || endDate) {
208
220
  query.timestamp = {};
@@ -252,10 +264,12 @@ auditTrailSchema.methods.getActivityType = function () {
252
264
  };
253
265
 
254
266
  auditTrailSchema.methods.isSuccessful = function () {
255
- return this.activity.includes("Success") ||
256
- (!this.activity.includes("Failed") &&
257
- !this.activity.includes("Error") &&
258
- !this.activity.includes("Not Found"));
267
+ return (
268
+ this.activity.includes("Success") ||
269
+ (!this.activity.includes("Failed") &&
270
+ !this.activity.includes("Error") &&
271
+ !this.activity.includes("Not Found"))
272
+ );
259
273
  };
260
274
 
261
275
  auditTrailSchema.methods.hasDataChanges = function () {
@@ -277,9 +291,21 @@ auditTrailSchema.index({ device_type: 1, timestamp: -1 }); // Device type querie
277
291
  auditTrailSchema.index({ browser: 1, timestamp: -1 }); // Browser-based queries
278
292
 
279
293
  // Compound indexes for common query patterns
280
- auditTrailSchema.index({ "user_details.userId": 1, activity: 1, timestamp: -1 }); // User + activity
281
- auditTrailSchema.index({ "route_params.facilityId": 1, method: 1, timestamp: -1 }); // Facility + method
282
- auditTrailSchema.index({ ip_address: 1, "user_details.userId": 1, timestamp: -1 }); // IP + user correlation
294
+ auditTrailSchema.index({
295
+ "user_details.userId": 1,
296
+ activity: 1,
297
+ timestamp: -1,
298
+ }); // User + activity
299
+ auditTrailSchema.index({
300
+ "route_params.facilityId": 1,
301
+ method: 1,
302
+ timestamp: -1,
303
+ }); // Facility + method
304
+ auditTrailSchema.index({
305
+ ip_address: 1,
306
+ "user_details.userId": 1,
307
+ timestamp: -1,
308
+ }); // IP + user correlation
283
309
 
284
310
  // Text search index for searching activities and user details
285
311
  auditTrailSchema.index({
@@ -292,7 +318,7 @@ auditTrailSchema.index({
292
318
  // Activity type constants
293
319
  auditTrailSchema.statics.ACTIVITY_TYPES = {
294
320
  CREATE: "CREATE",
295
- UPDATE: "UPDATE",
321
+ UPDATE: "UPDATE",
296
322
  DELETE: "DELETE",
297
323
  AUTH: "AUTH",
298
324
  OTHER: "OTHER",
@@ -317,4 +343,4 @@ auditTrailSchema.statics.DEVICE_TYPES = {
317
343
  UNKNOWN: "unknown",
318
344
  };
319
345
 
320
- module.exports = mongoose.model("AuditTrail", auditTrailSchema);
346
+ module.exports = mongoose.model("AuditTrail", auditTrailSchema);
@@ -1,83 +0,0 @@
1
- const mongoose = require('mongoose');
2
-
3
- const auditLogSchema = new mongoose.Schema({
4
- action: {
5
- type: String,
6
- required: true,
7
- trim: true
8
- },
9
- page: {
10
- type: String,
11
- required: true,
12
- trim: true
13
- },
14
- userId: {
15
- type: mongoose.Schema.Types.ObjectId,
16
- ref: 'Company',
17
- required: true
18
- },
19
- userInfo: {
20
- type: mongoose.Schema.Types.Mixed,
21
- required: true
22
- },
23
- projectId: {
24
- type: mongoose.Schema.Types.ObjectId,
25
- ref: 'Project',
26
- required: true
27
- },
28
- projectInfo: {
29
- type: mongoose.Schema.Types.Mixed,
30
- required: true
31
- },
32
- computerName: {
33
- type: String,
34
- required: true,
35
- trim: true
36
- },
37
- browser: {
38
- type: String,
39
- required: true,
40
- trim: true
41
- },
42
- ipAddress: {
43
- type: String,
44
- required: true,
45
- trim: true
46
- },
47
- time: {
48
- type: String,
49
- required: true,
50
- trim: true
51
- },
52
- date: {
53
- type: String,
54
- required: true,
55
- trim: true
56
- },
57
- createdOn: {
58
- type: Date,
59
- default: Date.now,
60
- required: true
61
- },
62
- oldData: {
63
- type: mongoose.Schema.Types.Mixed,
64
- default: {}
65
- },
66
- newData: {
67
- type: mongoose.Schema.Types.Mixed,
68
- default: {}
69
- },
70
- deletedData: {
71
- type: mongoose.Schema.Types.Mixed,
72
- default: {}
73
- }
74
- }, {
75
- timestamps: true
76
- });
77
-
78
- auditLogSchema.index({ userId: 1, projectId: 1, createdOn: -1 });
79
- auditLogSchema.index({ action: 1 });
80
- auditLogSchema.index({ page: 1 });
81
- const AuditLog = mongoose.model('AuditLog', auditLogSchema);
82
-
83
- module.exports = AuditLog;