Update server.js
Browse files
server.js
CHANGED
|
@@ -144,6 +144,13 @@ const excludedPaths = [
|
|
| 144 |
'/api/notifications',
|
| 145 |
'/api/facebook/posts',
|
| 146 |
'/api/github/repos',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
'/api/verify-token'
|
| 148 |
];
|
| 149 |
|
|
@@ -554,7 +561,11 @@ const userSchema = new mongoose.Schema({
|
|
| 554 |
svgColor: { type: String, default: '#000000' },
|
| 555 |
portfolioName: { type: String, default: 'Portfolio' },
|
| 556 |
pushNotifications: { type: Boolean, default: false }
|
| 557 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
});
|
| 559 |
|
| 560 |
// userSchema.index({ username: 1 }, { unique: true, sparse: true });
|
|
@@ -2324,40 +2335,52 @@ app.delete('/api/skills/:skillId', authenticateToken, isAdmin, async (req, res)
|
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
|
|
|
| 2327 |
// تحديث endpoint /api/profile/me
|
| 2328 |
app.get('/api/profile/me', authenticateToken, async (req, res) => {
|
| 2329 |
try {
|
| 2330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2331 |
if (!user) {
|
| 2332 |
return res.status(404).json({ error: 'المستخدم غير موجود' });
|
| 2333 |
}
|
| 2334 |
|
| 2335 |
-
|
| 2336 |
-
|
| 2337 |
-
|
| 2338 |
-
|
| 2339 |
-
|
| 2340 |
-
|
| 2341 |
-
|
| 2342 |
-
|
| 2343 |
-
|
| 2344 |
-
|
| 2345 |
-
|
| 2346 |
-
|
| 2347 |
-
|
| 2348 |
-
|
| 2349 |
-
|
| 2350 |
-
|
| 2351 |
-
|
| 2352 |
-
|
| 2353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2354 |
id: 'default',
|
| 2355 |
primaryColor: '#3b82f6',
|
| 2356 |
secondaryColor: '#8b5cf6',
|
| 2357 |
fontFamily: 'Inter',
|
| 2358 |
borderRadius: '0.5rem',
|
| 2359 |
},
|
| 2360 |
-
layout: {
|
| 2361 |
type: 'grid',
|
| 2362 |
columns: 3,
|
| 2363 |
showProjectImages: true,
|
|
@@ -2365,7 +2388,7 @@ app.get('/api/profile/me', authenticateToken, async (req, res) => {
|
|
| 2365 |
showProjectRatings: true,
|
| 2366 |
showProjectLinks: true,
|
| 2367 |
},
|
| 2368 |
-
header: {
|
| 2369 |
showAvatar: true,
|
| 2370 |
showJobTitle: true,
|
| 2371 |
showBio: true,
|
|
@@ -2373,11 +2396,11 @@ app.get('/api/profile/me', authenticateToken, async (req, res) => {
|
|
| 2373 |
showSocialLinks: true,
|
| 2374 |
layout: 'centered',
|
| 2375 |
},
|
| 2376 |
-
footer: {
|
| 2377 |
showCopyright: true,
|
| 2378 |
customText: '',
|
| 2379 |
},
|
| 2380 |
-
seo: {
|
| 2381 |
title: '',
|
| 2382 |
description: '',
|
| 2383 |
keywords: '',
|
|
@@ -2390,7 +2413,7 @@ app.get('/api/profile/me', authenticateToken, async (req, res) => {
|
|
| 2390 |
noindex: false,
|
| 2391 |
nofollow: false,
|
| 2392 |
},
|
| 2393 |
-
schema: {
|
| 2394 |
type: 'Person',
|
| 2395 |
name: '',
|
| 2396 |
description: '',
|
|
@@ -2401,11 +2424,12 @@ app.get('/api/profile/me', authenticateToken, async (req, res) => {
|
|
| 2401 |
alumniOf: [],
|
| 2402 |
knowsAbout: [],
|
| 2403 |
},
|
|
|
|
| 2404 |
};
|
| 2405 |
|
| 2406 |
res.json({
|
| 2407 |
username: user.username,
|
| 2408 |
-
profile
|
| 2409 |
});
|
| 2410 |
} catch (error) {
|
| 2411 |
logger.error(`Error fetching profile: ${error.message}`);
|
|
|
|
| 144 |
'/api/notifications',
|
| 145 |
'/api/facebook/posts',
|
| 146 |
'/api/github/repos',
|
| 147 |
+
'/api/verify-token',
|
| 148 |
+
// ✅ أضف هذه المسارات الجديدة
|
| 149 |
+
'/api/profile/appearance',
|
| 150 |
+
'/api/profile/seo',
|
| 151 |
+
'/api/profile',
|
| 152 |
+
'/api/refresh-token',
|
| 153 |
+
'/api/logout',
|
| 154 |
'/api/verify-token'
|
| 155 |
];
|
| 156 |
|
|
|
|
| 561 |
svgColor: { type: String, default: '#000000' },
|
| 562 |
portfolioName: { type: String, default: 'Portfolio' },
|
| 563 |
pushNotifications: { type: Boolean, default: false }
|
| 564 |
+
},
|
| 565 |
+
minimize: false,
|
| 566 |
+
toJSON: { getters: false, virtuals: false },
|
| 567 |
+
toObject: { getters: false, virtuals: false }
|
| 568 |
+
|
| 569 |
});
|
| 570 |
|
| 571 |
// userSchema.index({ username: 1 }, { unique: true, sparse: true });
|
|
|
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
+
// تحديث endpoint /api/profile/me
|
| 2339 |
// تحديث endpoint /api/profile/me
|
| 2340 |
app.get('/api/profile/me', authenticateToken, async (req, res) => {
|
| 2341 |
try {
|
| 2342 |
+
// ✅ استخدم lean() لتجنب مشاكل Mongoose getters
|
| 2343 |
+
const user = await User.findById(req.user.userId)
|
| 2344 |
+
.select('username profile')
|
| 2345 |
+
.lean();
|
| 2346 |
+
|
| 2347 |
if (!user) {
|
| 2348 |
return res.status(404).json({ error: 'المستخدم غير موجود' });
|
| 2349 |
}
|
| 2350 |
|
| 2351 |
+
// ✅ تأكد من وجود profile
|
| 2352 |
+
if (!user.profile) {
|
| 2353 |
+
user.profile = {};
|
| 2354 |
+
}
|
| 2355 |
+
|
| 2356 |
+
// ✅ القيم الافتراضية للـ profile
|
| 2357 |
+
const profile = {
|
| 2358 |
+
portfolioName: user.profile.portfolioName || 'Portfolio',
|
| 2359 |
+
nickname: user.profile.nickname || '',
|
| 2360 |
+
jobTitle: user.profile.jobTitle || '',
|
| 2361 |
+
bio: user.profile.bio || '',
|
| 2362 |
+
phone: user.profile.phone || '',
|
| 2363 |
+
isPublic: user.profile.isPublic ?? true,
|
| 2364 |
+
status: user.profile.status || 'Available',
|
| 2365 |
+
socialLinks: user.profile.socialLinks || { linkedin: '', behance: '', github: '', whatsapp: '' },
|
| 2366 |
+
avatar: user.profile.avatar || '',
|
| 2367 |
+
avatarDisplayType: user.profile.avatarDisplayType || 'normal',
|
| 2368 |
+
svgColor: user.profile.svgColor || '#000000',
|
| 2369 |
+
pdfFormat: user.profile.pdfFormat || 'jspdf',
|
| 2370 |
+
education: user.profile.education || [],
|
| 2371 |
+
experience: user.profile.experience || [],
|
| 2372 |
+
certificates: user.profile.certificates || [],
|
| 2373 |
+
skills: user.profile.skills || [],
|
| 2374 |
+
projects: user.profile.projects || [],
|
| 2375 |
+
interests: user.profile.interests || [],
|
| 2376 |
+
theme: user.profile.theme || {
|
| 2377 |
id: 'default',
|
| 2378 |
primaryColor: '#3b82f6',
|
| 2379 |
secondaryColor: '#8b5cf6',
|
| 2380 |
fontFamily: 'Inter',
|
| 2381 |
borderRadius: '0.5rem',
|
| 2382 |
},
|
| 2383 |
+
layout: user.profile.layout || {
|
| 2384 |
type: 'grid',
|
| 2385 |
columns: 3,
|
| 2386 |
showProjectImages: true,
|
|
|
|
| 2388 |
showProjectRatings: true,
|
| 2389 |
showProjectLinks: true,
|
| 2390 |
},
|
| 2391 |
+
header: user.profile.header || {
|
| 2392 |
showAvatar: true,
|
| 2393 |
showJobTitle: true,
|
| 2394 |
showBio: true,
|
|
|
|
| 2396 |
showSocialLinks: true,
|
| 2397 |
layout: 'centered',
|
| 2398 |
},
|
| 2399 |
+
footer: user.profile.footer || {
|
| 2400 |
showCopyright: true,
|
| 2401 |
customText: '',
|
| 2402 |
},
|
| 2403 |
+
seo: user.profile.seo || {
|
| 2404 |
title: '',
|
| 2405 |
description: '',
|
| 2406 |
keywords: '',
|
|
|
|
| 2413 |
noindex: false,
|
| 2414 |
nofollow: false,
|
| 2415 |
},
|
| 2416 |
+
schema: user.profile.schema || {
|
| 2417 |
type: 'Person',
|
| 2418 |
name: '',
|
| 2419 |
description: '',
|
|
|
|
| 2424 |
alumniOf: [],
|
| 2425 |
knowsAbout: [],
|
| 2426 |
},
|
| 2427 |
+
pushNotifications: user.profile.pushNotifications || false
|
| 2428 |
};
|
| 2429 |
|
| 2430 |
res.json({
|
| 2431 |
username: user.username,
|
| 2432 |
+
profile: profile
|
| 2433 |
});
|
| 2434 |
} catch (error) {
|
| 2435 |
logger.error(`Error fetching profile: ${error.message}`);
|