Skip to content

Commit ee29610

Browse files
authored
Merge pull request #29 from kirannagarakanti369-glitch/main
Critical Bug Fixes: Resolved Application Homepage loading error
2 parents 0a674bb + e074563 commit ee29610

3 files changed

Lines changed: 64 additions & 25 deletions

File tree

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
7-
"build": "next build",
6+
"dev": "prisma generate && next dev",
7+
"build": "prisma generate && next build",
88
"start": "next start",
9-
"lint": "next lint"
9+
"lint": "next lint",
10+
"db:generate": "prisma generate",
11+
"db:push": "prisma db push",
12+
"db:studio": "prisma studio"
1013
},
1114
"dependencies": {
1215
"@headlessui/react": "^1.7.18",

server/middleware/requestLogger.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ const errorLogStream = fs.createWriteStream(
2929
);
3030

3131
// Middleware to add request ID
32-
const addRequestId = (req, res, next) => {
33-
req.reqId = require('nanoid').nanoid(8);
34-
res.setHeader('X-Request-ID', req.reqId);
35-
next();
32+
const addRequestId = async (req, res, next) => {
33+
try {
34+
const { nanoid } = await import('nanoid');
35+
req.reqId = nanoid(8);
36+
res.setHeader('X-Request-ID', req.reqId);
37+
next();
38+
} catch (error) {
39+
console.error('Error generating request ID:', error);
40+
// Fallback ID
41+
req.reqId = Math.random().toString(36).substr(2, 8);
42+
res.setHeader('X-Request-ID', req.reqId);
43+
next();
44+
}
3645
};
3746

3847
// Standard request logger

server/utills/notificationHelpers.js

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
const { PrismaClient } = require('@prisma/client');
2-
const { nanoid } = require('nanoid');
32

43
const prisma = new PrismaClient();
54

5+
/**
6+
* Generate ID using nanoid with dynamic import
7+
*/
8+
const generateId = async () => {
9+
try {
10+
const { nanoid } = await import('nanoid');
11+
return nanoid();
12+
} catch (error) {
13+
console.error('Error generating nanoid:', error);
14+
// Fallback ID generation
15+
return Math.random().toString(36).substr(2, 10);
16+
}
17+
};
18+
619
/**
720
* Create an order update notification
821
*/
@@ -47,9 +60,11 @@ const createOrderUpdateNotification = async (userId, orderStatus, orderId, total
4760
priority: 'NORMAL'
4861
};
4962

63+
const notificationId = await generateId();
64+
5065
const notification = await prisma.notification.create({
5166
data: {
52-
id: nanoid(),
67+
id: notificationId,
5368
userId: userId,
5469
title: statusInfo.title,
5570
message: statusInfo.message,
@@ -101,9 +116,11 @@ const createPaymentNotification = async (userId, paymentStatus, amount, orderId)
101116
priority: 'NORMAL'
102117
};
103118

119+
const notificationId = await generateId();
120+
104121
const notification = await prisma.notification.create({
105122
data: {
106-
id: nanoid(),
123+
id: notificationId,
107124
userId: userId,
108125
title: statusInfo.title,
109126
message: statusInfo.message,
@@ -131,9 +148,11 @@ const createPaymentNotification = async (userId, paymentStatus, amount, orderId)
131148
*/
132149
const createPromotionNotification = async (userId, title, message, promoCode = null, discount = null) => {
133150
try {
151+
const notificationId = await generateId();
152+
134153
const notification = await prisma.notification.create({
135154
data: {
136-
id: nanoid(),
155+
id: notificationId,
137156
userId: userId,
138157
title: title,
139158
message: message,
@@ -160,9 +179,11 @@ const createPromotionNotification = async (userId, title, message, promoCode = n
160179
*/
161180
const createSystemAlertNotification = async (userId, title, message, priority = 'HIGH') => {
162181
try {
182+
const notificationId = await generateId();
183+
163184
const notification = await prisma.notification.create({
164185
data: {
165-
id: nanoid(),
186+
id: notificationId,
166187
userId: userId,
167188
title: title,
168189
message: message,
@@ -188,23 +209,29 @@ const createSystemAlertNotification = async (userId, title, message, priority =
188209
*/
189210
const createBulkNotifications = async (userIds, title, message, type = 'SYSTEM_ALERT', priority = 'NORMAL', metadata = {}) => {
190211
try {
191-
const notifications = userIds.map(userId => ({
192-
id: nanoid(),
193-
userId: userId,
194-
title: title,
195-
message: message,
196-
type: type,
197-
priority: priority,
198-
isRead: false,
199-
metadata: metadata
200-
}));
212+
// Generate all IDs first
213+
const notificationData = await Promise.all(
214+
userIds.map(async (userId) => {
215+
const notificationId = await generateId();
216+
return {
217+
id: notificationId,
218+
userId: userId,
219+
title: title,
220+
message: message,
221+
type: type,
222+
priority: priority,
223+
isRead: false,
224+
metadata: metadata
225+
};
226+
})
227+
);
201228

202229
await prisma.notification.createMany({
203-
data: notifications
230+
data: notificationData
204231
});
205232

206233
console.log(`✅ Bulk notifications created for ${userIds.length} users: ${title}`);
207-
return notifications.length;
234+
return notificationData.length;
208235
} catch (error) {
209236
console.error('❌ Error creating bulk notifications:', error);
210237
throw error;
@@ -217,4 +244,4 @@ module.exports = {
217244
createPromotionNotification,
218245
createSystemAlertNotification,
219246
createBulkNotifications
220-
};
247+
};

0 commit comments

Comments
 (0)