database-connector 2.1.3 → 2.2.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/models/Payment.js CHANGED
@@ -13,7 +13,6 @@ const mongoose = require('mongoose');
13
13
  * - paymentStatus
14
14
  * - paymentAmount
15
15
  * - paymentCurrency
16
- * - paymentMethod
17
16
  * - paymentDate
18
17
  * - paymentTime
19
18
  * - paymentDetails
@@ -40,9 +39,10 @@ const mongoose = require('mongoose');
40
39
  * paymentCurrency:
41
40
  * type: string
42
41
  * description: Currency of payment
43
- * paymentMethod:
42
+ * paymentMethodId:
44
43
  * type: string
45
- * description: Payment method
44
+ * nullable: true
45
+ * description: Reference to payment method type (PaymentType)
46
46
  * paymentDate:
47
47
  * type: string
48
48
  * format: date
@@ -55,6 +55,11 @@ const mongoose = require('mongoose');
55
55
  * type: number
56
56
  * default: 0
57
57
  * description: Total price
58
+ * transactions:
59
+ * type: array
60
+ * items:
61
+ * type: string
62
+ * description: References to related transactions
58
63
  * token:
59
64
  * type: string
60
65
  * description: Payment token
@@ -72,8 +77,9 @@ const mongoose = require('mongoose');
72
77
  * paymentStatus: "succeeded"
73
78
  * paymentAmount: 150.00
74
79
  * paymentCurrency: "USD"
75
- * paymentMethod: "card"
80
+ * paymentMethodId: "507f1f77bcf86cd799439020"
76
81
  * totalPrice: 150.00
82
+ * transactions: ["507f1f77bcf86cd799439111", "507f1f77bcf86cd799439112"]
77
83
  * createdAt: "2025-12-07T10:30:00.000Z"
78
84
  * updatedAt: "2025-12-07T10:30:00.000Z"
79
85
  */
@@ -106,9 +112,11 @@ const paymentSchema = new mongoose.Schema(
106
112
  type: String,
107
113
  required: true,
108
114
  },
109
- paymentMethod: {
110
- type: String,
111
- required: true,
115
+ paymentMethodId: {
116
+ type: mongoose.Schema.Types.ObjectId,
117
+ required: false,
118
+ default: null,
119
+ ref: 'PaymentType',
112
120
  },
113
121
  paymentDate: {
114
122
  type: Date,
@@ -127,57 +135,13 @@ const paymentSchema = new mongoose.Schema(
127
135
  required: true,
128
136
  default: 0,
129
137
  },
130
- card: {
131
- brand: {
132
- type: String,
133
- required: true,
134
- },
135
- last4: {
136
- type: String,
137
- required: true,
138
- },
139
- exp_month: {
140
- type: Number,
141
- required: true,
142
- },
143
- exp_year: {
144
- type: Number,
145
- required: true,
146
- },
147
- funding: {
148
- type: String,
149
- required: true,
150
- },
151
- country: {
152
- type: String,
153
- required: true,
154
- },
155
- name: {
156
- type: String,
157
- required: true,
158
- },
159
- address_line1: {
160
- type: String,
161
- required: true,
162
- },
163
- address_line2: {
164
- type: String,
165
- required: true,
166
- },
167
- address_city: {
168
- type: String,
169
- required: true,
170
- },
171
- ccvVerified: {
172
- type: Boolean,
173
- required: true,
174
- default: false,
175
- },
176
- ccv: {
177
- type: String,
178
- required: true
138
+ transactions: [
139
+ {
140
+ type: mongoose.Schema.Types.ObjectId,
141
+ ref: 'Transaction',
142
+ required: false,
179
143
  }
180
- },
144
+ ],
181
145
  timestamps: {
182
146
  type: Date,
183
147
  required: true,
@@ -33,6 +33,10 @@ const mongoose = require('mongoose');
33
33
  * paymentTypeId:
34
34
  * type: string
35
35
  * description: Reference to payment type
36
+ * paymentIntentId:
37
+ * type: string
38
+ * nullable: true
39
+ * description: Reference to payment intent (can be null)
36
40
  * reductionOfferId:
37
41
  * type: string
38
42
  * description: Reference to reduction offer
@@ -59,6 +63,7 @@ const mongoose = require('mongoose');
59
63
  * storeId: "507f1f77bcf86cd799439012"
60
64
  * planId: "507f1f77bcf86cd799439013"
61
65
  * paymentAmount: 99.99
66
+ * paymentIntentId: "507f1f77bcf86cd799439099"
62
67
  * status: "active"
63
68
  * startDate: "2025-12-01T00:00:00.000Z"
64
69
  * endDate: "2026-12-01T00:00:00.000Z"
@@ -94,6 +99,12 @@ const subscriptionSchema = new mongoose.Schema(
94
99
  required: false,
95
100
  ref: 'PaymentType',
96
101
  },
102
+ paymentIntentId: {
103
+ type: mongoose.Schema.Types.ObjectId,
104
+ required: false,
105
+ ref: 'Payment',
106
+ default: null,
107
+ },
97
108
  reductionOfferId: {
98
109
  type: mongoose.Schema.Types.ObjectId,
99
110
  required: false,
@@ -15,6 +15,10 @@ const mongoose = require('mongoose');
15
15
  * discount:
16
16
  * type: number
17
17
  * description: Discount amount or percentage
18
+ * discountType:
19
+ * type: string
20
+ * enum: [percentage, amount]
21
+ * description: Type of discount (percentage or fixed amount)
18
22
  * isActive:
19
23
  * type: boolean
20
24
  * default: false
@@ -28,6 +32,7 @@ const mongoose = require('mongoose');
28
32
  * example:
29
33
  * id: "507f1f77bcf86cd799439011"
30
34
  * discount: 20
35
+ * discountType: "percentage"
31
36
  * isActive: true
32
37
  * createdAt: "2025-11-01T10:30:00.000Z"
33
38
  * updatedAt: "2025-12-01T15:45:00.000Z"
@@ -38,6 +43,11 @@ const subscriptionOfferSchema = new mongoose.Schema(
38
43
  type: Number,
39
44
  required: true,
40
45
  },
46
+ discountType: {
47
+ type: String,
48
+ required: true,
49
+ enum: ['percentage', 'amount'],
50
+ },
41
51
  isActive: {
42
52
  type: Boolean,
43
53
  required: true,
@@ -0,0 +1,105 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Transaction:
8
+ * type: object
9
+ * required:
10
+ * - paymentId
11
+ * - amount
12
+ * - status
13
+ * properties:
14
+ * id:
15
+ * type: string
16
+ * description: The transaction identifier
17
+ * paymentId:
18
+ * type: string
19
+ * description: Reference to the payment
20
+ * amount:
21
+ * type: number
22
+ * description: Transaction amount
23
+ * paymentMethodId:
24
+ * type: string
25
+ * nullable: true
26
+ * description: Reference to payment method type (PaymentType)
27
+ * status:
28
+ * type: string
29
+ * enum: [pending, succeeded, failed, refunded, canceled]
30
+ * description: Transaction status
31
+ * gatewayTransactionId:
32
+ * type: string
33
+ * nullable: true
34
+ * description: Provider transaction identifier (can be null)
35
+ * transactionDate:
36
+ * type: string
37
+ * format: date-time
38
+ * description: Date and time of the transaction
39
+ * metadata:
40
+ * type: object
41
+ * nullable: true
42
+ * description: Extra transaction metadata (can be null)
43
+ * createdAt:
44
+ * type: string
45
+ * format: date-time
46
+ * updatedAt:
47
+ * type: string
48
+ * format: date-time
49
+ * example:
50
+ * id: "507f1f77bcf86cd799439111"
51
+ * paymentId: "507f1f77bcf86cd799439011"
52
+ * amount: 100.0
53
+ * currency: "USD"
54
+ * paymentMethodId: "507f1f77bcf86cd799439020"
55
+ * status: "succeeded"
56
+ * gatewayTransactionId: "pi_3QX..."
57
+ * transactionDate: "2025-12-07T10:30:00.000Z"
58
+ */
59
+ const transactionSchema = new mongoose.Schema(
60
+ {
61
+ paymentId: {
62
+ type: mongoose.Schema.Types.ObjectId,
63
+ ref: 'Payment',
64
+ required: true,
65
+ },
66
+ amount: {
67
+ type: Number,
68
+ required: true,
69
+ },
70
+ paymentMethodId: {
71
+ type: mongoose.Schema.Types.ObjectId,
72
+ required: false,
73
+ default: null,
74
+ ref: 'PaymentType',
75
+ },
76
+ status: {
77
+ type: String,
78
+ enum: ['pending', 'succeeded', 'failed', 'refunded', 'canceled'],
79
+ required: true,
80
+ default: 'pending',
81
+ },
82
+ gatewayTransactionId: {
83
+ type: String,
84
+ required: false,
85
+ default: null,
86
+ },
87
+ transactionDate: {
88
+ type: Date,
89
+ required: true,
90
+ default: Date.now,
91
+ },
92
+ metadata: {
93
+ type: Object,
94
+ required: false,
95
+ default: null,
96
+ },
97
+ },
98
+ { timestamps: true }
99
+ );
100
+
101
+ // Indexes for performance optimization
102
+ transactionSchema.index({ paymentId: 1, createdAt: -1 });
103
+ transactionSchema.index({ status: 1, createdAt: -1 });
104
+
105
+ module.exports = mongoose.model('Transaction', transactionSchema);
package/models/User.js CHANGED
@@ -55,6 +55,13 @@ const { policySchema } = require('database-connector/models/Policy');
55
55
  * email:
56
56
  * type: string
57
57
  * description: User email address
58
+ * isGoogleAuth:
59
+ * type: boolean
60
+ * default: false
61
+ * description: Whether the user authenticated via Google
62
+ * googleUid:
63
+ * type: string
64
+ * description: Google user identifier
58
65
  * favouritsProductst:
59
66
  * type: array
60
67
  * items:
@@ -170,6 +177,13 @@ const userSchema = new mongoose.Schema(
170
177
  type: String,
171
178
  default: null,
172
179
  },
180
+ isGoogleAuth: {
181
+ type: Boolean,
182
+ default: false,
183
+ },
184
+ googleUid: {
185
+ type: String,
186
+ },
173
187
  favouritsProductst: [
174
188
  {
175
189
  productId: { type: String },
package/models/index.js CHANGED
@@ -22,6 +22,7 @@ const User = require('./User');
22
22
  const Order = require('./Order');
23
23
  const Bill = require('./Bill');
24
24
  const Payment = require('./Payment');
25
+ const Transaction = require('./Transaction');
25
26
  const Store = require('./Store');
26
27
  const Offer = require('./Offer');
27
28
  const Category = require('./Category');
@@ -58,6 +59,7 @@ module.exports = {
58
59
  Order,
59
60
  Bill,
60
61
  Payment,
62
+ Transaction,
61
63
  Store,
62
64
  Offer,
63
65
  Category,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.",
5
5
  "main": "models/index.js",
6
6
  "scripts": {