Skip to content

Commit 76e3102

Browse files
committed
v3
1 parent 1f090fc commit 76e3102

13 files changed

+2786
-10
lines changed

codebase-summary.json

Lines changed: 170 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
{
22
"schemaVersion": "3.0.0",
3-
"generatedAt": "2025-06-13T07:29:02.905Z",
3+
"generatedAt": "2025-06-13T08:17:13.552Z",
44
"git": {
55
"sha": null,
66
"branch": null,
77
"remote": null
88
},
99
"modules": [],
1010
"services": {
11-
"businessServices": [],
11+
"businessServices": [
12+
"NotificationService",
13+
"OrderService",
14+
"PaymentService"
15+
],
1216
"utilityServices": [
1317
"UtilityAnalyzer"
1418
]
1519
},
1620
"apiRoutes": {
17-
"publicRoutes": [],
18-
"internalRoutes": []
21+
"publicRoutes": [
22+
"/orders",
23+
"/orders/:id",
24+
"/orders/:id/cancel",
25+
"/orders/:id/status",
26+
"/orders/my"
27+
],
28+
"internalRoutes": [
29+
"/admin/orders",
30+
"/admin/orders/analytics"
31+
]
1932
},
20-
"dbModels": [],
33+
"dbModels": [
34+
"Order"
35+
],
2136
"utils": {
2237
"byDomain": {
2338
"Date/Time": [
@@ -53,5 +68,154 @@
5368
"Middleware Pattern",
5469
"React Hooks",
5570
"TypeScript Interfaces"
56-
]
71+
],
72+
"serviceDependencies": {
73+
"OrderService": [
74+
"AuditService",
75+
"NotificationService",
76+
"PaymentService",
77+
"auditService",
78+
"notificationService",
79+
"paymentService"
80+
],
81+
"NotificationService": [
82+
"EmailService",
83+
"PushNotificationService",
84+
"PushService",
85+
"SmsService",
86+
"emailService",
87+
"pushService",
88+
"smsService"
89+
],
90+
"PaymentService": [
91+
"AuthService",
92+
"PayPalService",
93+
"PaypalService",
94+
"StripeService",
95+
"authService",
96+
"paypalService",
97+
"stripeService"
98+
]
99+
},
100+
"schemaSnapshots": {
101+
"Order": {
102+
"type": "String",
103+
"required": "true",
104+
"unique": "true"
105+
}
106+
},
107+
"apiPayloads": {
108+
"POST /orders": {
109+
"request": {},
110+
"response": {}
111+
},
112+
"GET /orders/my": {
113+
"request": {},
114+
"response": {}
115+
},
116+
"GET /orders/:orderId": {
117+
"request": {},
118+
"response": {}
119+
},
120+
"PATCH /orders/:orderId/status": {
121+
"request": {},
122+
"response": {}
123+
},
124+
"GET /admin/orders": {
125+
"request": {},
126+
"response": {}
127+
},
128+
"GET /admin/orders/analytics": {
129+
"request": {},
130+
"response": {}
131+
},
132+
"POST /orders/:orderId/cancel": {
133+
"request": {},
134+
"response": {}
135+
}
136+
},
137+
"authPolicies": {},
138+
"businessFlows": {
139+
"NotificationService": {
140+
"sendOrderConfirmation": [
141+
"Call emailService.sendOrderConfirmation()",
142+
"Call smsService.sendOrderSMS()",
143+
"Send notification",
144+
"Handle errors"
145+
],
146+
"catch": [
147+
"Handle errors"
148+
],
149+
"sendStatusUpdate": [
150+
"Call emailService.sendStatusUpdate()",
151+
"Call smsService.sendStatusSMS()",
152+
"Call pushService.sendStatusPush()",
153+
"Send notification"
154+
]
155+
},
156+
"OrderService": {
157+
"createOrder": [
158+
"Validate input data",
159+
"Call paymentService.processPayment()",
160+
"Calculate",
161+
"Process",
162+
"Process payment",
163+
"Handle errors"
164+
],
165+
"catch": [
166+
"Call auditService.logOrderError()"
167+
],
168+
"updateOrderStatus": [
169+
"Call notificationService.sendStatusUpdate()",
170+
"Execute update query",
171+
"Send notification"
172+
],
173+
"validateOrderData": [
174+
"Process payment",
175+
"Handle errors"
176+
]
177+
},
178+
"PaymentService": {
179+
"processPayment": [
180+
"Validate input data",
181+
"Call authService.validatePaymentAuth()",
182+
"Call stripeService.chargeCard()",
183+
"Call paypalService.processPayment()",
184+
"Calculate",
185+
"Process",
186+
"Process payment",
187+
"Handle errors"
188+
],
189+
"switch": [
190+
"Call stripeService.chargeCard()",
191+
"Call paypalService.processPayment()",
192+
"Process",
193+
"Process payment",
194+
"Handle errors"
195+
],
196+
"catch": [
197+
"Process payment"
198+
],
199+
"refundPayment": [
200+
"Process",
201+
"Process payment"
202+
],
203+
"validatePaymentData": [
204+
"Process payment",
205+
"Handle errors"
206+
],
207+
"savePayment": [
208+
"Process payment"
209+
],
210+
"findPaymentById": [
211+
"Process payment"
212+
],
213+
"processRefund": [
214+
"Process payment"
215+
],
216+
"logPaymentError": [
217+
"Process payment"
218+
]
219+
}
220+
}
57221
}

models/Order.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Enhanced test model with comprehensive field definitions
2+
const mongoose = require('mongoose');
3+
4+
const OrderSchema = new mongoose.Schema({
5+
orderId: {
6+
type: String,
7+
required: true,
8+
unique: true,
9+
default: () => 'ORD_' + Date.now()
10+
},
11+
userId: {
12+
type: mongoose.Schema.Types.ObjectId,
13+
required: true,
14+
ref: 'User'
15+
},
16+
customerEmail: {
17+
type: String,
18+
required: true,
19+
lowercase: true
20+
},
21+
totalAmount: {
22+
type: Number,
23+
required: true,
24+
min: 0,
25+
default: 0
26+
},
27+
discountAmount: {
28+
type: Number,
29+
min: 0,
30+
default: 0
31+
},
32+
finalAmount: {
33+
type: Number,
34+
required: true,
35+
min: 0
36+
},
37+
currency: {
38+
type: String,
39+
enum: ['USD', 'EUR', 'GBP', 'CAD'],
40+
default: 'USD'
41+
},
42+
status: {
43+
type: String,
44+
enum: ['pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled', 'refunded'],
45+
default: 'pending'
46+
},
47+
paymentStatus: {
48+
type: String,
49+
enum: ['pending', 'paid', 'failed', 'refunded'],
50+
default: 'pending'
51+
},
52+
shippingAddress: {
53+
street: { type: String, required: true },
54+
city: { type: String, required: true },
55+
state: { type: String, required: true },
56+
zipCode: { type: String, required: true },
57+
country: { type: String, required: true }
58+
},
59+
items: [{
60+
productId: {
61+
type: mongoose.Schema.Types.ObjectId,
62+
required: true,
63+
ref: 'Product'
64+
},
65+
productName: {
66+
type: String,
67+
required: true
68+
},
69+
quantity: {
70+
type: Number,
71+
required: true,
72+
min: 1
73+
},
74+
unitPrice: {
75+
type: Number,
76+
required: true,
77+
min: 0
78+
},
79+
totalPrice: {
80+
type: Number,
81+
required: true,
82+
min: 0
83+
}
84+
}],
85+
notes: {
86+
type: String,
87+
maxlength: 500
88+
},
89+
isGift: {
90+
type: Boolean,
91+
default: false
92+
},
93+
giftMessage: {
94+
type: String,
95+
maxlength: 200
96+
},
97+
estimatedDelivery: {
98+
type: Date
99+
},
100+
actualDelivery: {
101+
type: Date
102+
},
103+
createdAt: {
104+
type: Date,
105+
default: Date.now
106+
},
107+
updatedAt: {
108+
type: Date,
109+
default: Date.now
110+
}
111+
}, {
112+
timestamps: true,
113+
toJSON: { virtuals: true },
114+
toObject: { virtuals: true }
115+
});
116+
117+
// Virtual for order age in days
118+
OrderSchema.virtual('ageInDays').get(function() {
119+
return Math.floor((Date.now() - this.createdAt) / (1000 * 60 * 60 * 24));
120+
});
121+
122+
// Index for performance
123+
OrderSchema.index({ userId: 1, status: 1 });
124+
OrderSchema.index({ createdAt: -1 });
125+
126+
module.exports = mongoose.model('Order', OrderSchema);

0 commit comments

Comments
 (0)