Mark-Lasfar commited on
Commit ยท
b312fa4
1
Parent(s): 4a8d3ae
Add GraphQL
Browse files- graphql/resolvers.js +123 -119
graphql/resolvers.js
CHANGED
|
@@ -335,135 +335,139 @@ const resolvers = {
|
|
| 335 |
},
|
| 336 |
|
| 337 |
// ============================================
|
| 338 |
-
// ๐น PROFILE RESOLVERS
|
| 339 |
// ============================================
|
| 340 |
Profile: {
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
// parent._id ูู userId ูุฃู Profile ุฌุฒุก ู
ู User
|
| 346 |
const userId = parent._id || parent.userId;
|
| 347 |
if (!userId) return false;
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
|
|
|
| 359 |
const userId = parent._id || parent.userId;
|
| 360 |
if (!userId) return 0;
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
| 372 |
const userId = parent._id || parent.userId;
|
| 373 |
if (!userId) return 0;
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
}
|
|
|
|
| 382 |
|
| 383 |
-
// โ
ุชุญููู Object ุฅูู Array ูุฌู
ูุน ุงูุญููู ุงูุชู ูุฏ ุชููู Object
|
| 384 |
-
education: (parent) => {
|
| 385 |
-
if (!parent.education) return [];
|
| 386 |
-
if (Array.isArray(parent.education)) return parent.education;
|
| 387 |
-
if (typeof parent.education === 'object') return Object.values(parent.education);
|
| 388 |
-
return [];
|
| 389 |
-
},
|
| 390 |
-
|
| 391 |
-
experience: (parent) => {
|
| 392 |
-
if (!parent.experience) return [];
|
| 393 |
-
if (Array.isArray(parent.experience)) return parent.experience;
|
| 394 |
-
if (typeof parent.experience === 'object') return Object.values(parent.experience);
|
| 395 |
-
return [];
|
| 396 |
-
},
|
| 397 |
-
|
| 398 |
-
certificates: (parent) => {
|
| 399 |
-
if (!parent.certificates) return [];
|
| 400 |
-
if (Array.isArray(parent.certificates)) return parent.certificates;
|
| 401 |
-
if (typeof parent.certificates === 'object') return Object.values(parent.certificates);
|
| 402 |
-
return [];
|
| 403 |
-
},
|
| 404 |
-
|
| 405 |
-
skills: (parent) => {
|
| 406 |
-
if (!parent.skills) return [];
|
| 407 |
-
if (Array.isArray(parent.skills)) return parent.skills;
|
| 408 |
-
if (typeof parent.skills === 'object') return Object.values(parent.skills);
|
| 409 |
-
return [];
|
| 410 |
-
},
|
| 411 |
-
|
| 412 |
-
projects: (parent) => {
|
| 413 |
-
if (!parent.projects) return [];
|
| 414 |
-
if (Array.isArray(parent.projects)) return parent.projects;
|
| 415 |
-
if (typeof parent.projects === 'object') return Object.values(parent.projects);
|
| 416 |
-
return [];
|
| 417 |
-
},
|
| 418 |
-
|
| 419 |
-
interests: (parent) => {
|
| 420 |
-
if (!parent.interests) return [];
|
| 421 |
-
if (Array.isArray(parent.interests)) return parent.interests;
|
| 422 |
-
if (typeof parent.interests === 'object') return Object.values(parent.interests);
|
| 423 |
-
return [];
|
| 424 |
-
},
|
| 425 |
-
|
| 426 |
-
customSections: (parent) => {
|
| 427 |
-
if (!parent.customSections) return [];
|
| 428 |
-
if (Array.isArray(parent.customSections)) return parent.customSections;
|
| 429 |
-
if (typeof parent.customSections === 'object') return Object.values(parent.customSections);
|
| 430 |
-
return [];
|
| 431 |
-
},
|
| 432 |
-
|
| 433 |
-
sectionOrder: (parent) => {
|
| 434 |
-
if (!parent.sectionOrder) return [];
|
| 435 |
-
if (Array.isArray(parent.sectionOrder)) return parent.sectionOrder;
|
| 436 |
-
if (typeof parent.sectionOrder === 'object') return Object.values(parent.sectionOrder);
|
| 437 |
-
return [];
|
| 438 |
-
},
|
| 439 |
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
},
|
| 468 |
|
| 469 |
Project: {
|
|
|
|
| 335 |
},
|
| 336 |
|
| 337 |
// ============================================
|
| 338 |
+
// ๐น PROFILE RESOLVERS - โ
ู
ุน ุชุญููู Object ุฅูู Array
|
| 339 |
// ============================================
|
| 340 |
Profile: {
|
| 341 |
+
socialLinks: (parent) => parent.socialLinks || {},
|
| 342 |
+
|
| 343 |
+
storeEnabled: async (parent, args, context) => {
|
| 344 |
+
try {
|
|
|
|
| 345 |
const userId = parent._id || parent.userId;
|
| 346 |
if (!userId) return false;
|
| 347 |
+
|
| 348 |
+
const storeSettings = await StoreSettings.findOne({ userId });
|
| 349 |
+
return storeSettings?.enabled || false;
|
| 350 |
+
} catch (error) {
|
| 351 |
+
console.error('Error loading storeEnabled:', error);
|
| 352 |
+
return false;
|
| 353 |
+
}
|
| 354 |
+
},
|
| 355 |
+
|
| 356 |
+
// โ
averageRating
|
| 357 |
+
averageRating: async (parent, args, context) => {
|
| 358 |
+
try {
|
| 359 |
const userId = parent._id || parent.userId;
|
| 360 |
if (!userId) return 0;
|
| 361 |
+
|
| 362 |
+
const storeSettings = await StoreSettings.findOne({ userId });
|
| 363 |
+
return storeSettings?.averageRating || 0;
|
| 364 |
+
} catch (error) {
|
| 365 |
+
console.error('Error loading averageRating:', error);
|
| 366 |
+
return 0;
|
| 367 |
+
}
|
| 368 |
+
},
|
| 369 |
+
|
| 370 |
+
// โ
totalRatings
|
| 371 |
+
totalRatings: async (parent, args, context) => {
|
| 372 |
+
try {
|
| 373 |
const userId = parent._id || parent.userId;
|
| 374 |
if (!userId) return 0;
|
| 375 |
+
|
| 376 |
+
// ุฌูุจ ุนุฏุฏ ุงูุชูููู
ุงุช ู
ู Rating model
|
| 377 |
+
const count = await Rating.countDocuments({ targetUserId: userId });
|
| 378 |
+
return count || 0;
|
| 379 |
+
} catch (error) {
|
| 380 |
+
console.error('Error loading totalRatings:', error);
|
| 381 |
+
return 0;
|
| 382 |
+
}
|
| 383 |
+
},
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
+
// โ
ุชุญููู Object ุฅูู Array ูุฌู
ูุน ุงูุญููู ุงูุชู ูุฏ ุชููู Object
|
| 387 |
+
education: (parent) => {
|
| 388 |
+
if (!parent.education) return [];
|
| 389 |
+
if (Array.isArray(parent.education)) return parent.education;
|
| 390 |
+
if (typeof parent.education === 'object') return Object.values(parent.education);
|
| 391 |
+
return [];
|
| 392 |
+
},
|
| 393 |
+
|
| 394 |
+
experience: (parent) => {
|
| 395 |
+
if (!parent.experience) return [];
|
| 396 |
+
if (Array.isArray(parent.experience)) return parent.experience;
|
| 397 |
+
if (typeof parent.experience === 'object') return Object.values(parent.experience);
|
| 398 |
+
return [];
|
| 399 |
+
},
|
| 400 |
+
|
| 401 |
+
certificates: (parent) => {
|
| 402 |
+
if (!parent.certificates) return [];
|
| 403 |
+
if (Array.isArray(parent.certificates)) return parent.certificates;
|
| 404 |
+
if (typeof parent.certificates === 'object') return Object.values(parent.certificates);
|
| 405 |
+
return [];
|
| 406 |
+
},
|
| 407 |
+
|
| 408 |
+
skills: (parent) => {
|
| 409 |
+
if (!parent.skills) return [];
|
| 410 |
+
if (Array.isArray(parent.skills)) return parent.skills;
|
| 411 |
+
if (typeof parent.skills === 'object') return Object.values(parent.skills);
|
| 412 |
+
return [];
|
| 413 |
+
},
|
| 414 |
+
|
| 415 |
+
projects: (parent) => {
|
| 416 |
+
if (!parent.projects) return [];
|
| 417 |
+
if (Array.isArray(parent.projects)) return parent.projects;
|
| 418 |
+
if (typeof parent.projects === 'object') return Object.values(parent.projects);
|
| 419 |
+
return [];
|
| 420 |
+
},
|
| 421 |
+
|
| 422 |
+
interests: (parent) => {
|
| 423 |
+
if (!parent.interests) return [];
|
| 424 |
+
if (Array.isArray(parent.interests)) return parent.interests;
|
| 425 |
+
if (typeof parent.interests === 'object') return Object.values(parent.interests);
|
| 426 |
+
return [];
|
| 427 |
+
},
|
| 428 |
+
|
| 429 |
+
customSections: (parent) => {
|
| 430 |
+
if (!parent.customSections) return [];
|
| 431 |
+
if (Array.isArray(parent.customSections)) return parent.customSections;
|
| 432 |
+
if (typeof parent.customSections === 'object') return Object.values(parent.customSections);
|
| 433 |
+
return [];
|
| 434 |
+
},
|
| 435 |
+
|
| 436 |
+
sectionOrder: (parent) => {
|
| 437 |
+
if (!parent.sectionOrder) return [];
|
| 438 |
+
if (Array.isArray(parent.sectionOrder)) return parent.sectionOrder;
|
| 439 |
+
if (typeof parent.sectionOrder === 'object') return Object.values(parent.sectionOrder);
|
| 440 |
+
return [];
|
| 441 |
+
},
|
| 442 |
+
|
| 443 |
+
hasStory: async (parent, args, context) => {
|
| 444 |
+
// ูู ุงูู Profile ุฌุงู ู
ู Userุ ุงุณุชุฎุฏู
ุงูู userId
|
| 445 |
+
const userId = parent._id || parent.userId;
|
| 446 |
+
if (!userId) return false;
|
| 447 |
+
try {
|
| 448 |
+
const count = await Story.countDocuments({
|
| 449 |
+
userId: userId,
|
| 450 |
+
expiresAt: { $gt: new Date() }
|
| 451 |
+
});
|
| 452 |
+
return count > 0;
|
| 453 |
+
} catch (error) {
|
| 454 |
+
return false;
|
| 455 |
+
}
|
| 456 |
+
},
|
| 457 |
+
|
| 458 |
+
// โ
ุงูุญููู ุงููู ู
ูุฑูุถ ุชููู Objects
|
| 459 |
+
sectionNames: (parent) => parent.sectionNames || {},
|
| 460 |
+
sectionVisibility: (parent) => parent.sectionVisibility || {},
|
| 461 |
+
sectionStyleSettings: (parent) => parent.sectionStyleSettings || {},
|
| 462 |
+
designSettings: (parent) => parent.designSettings || {},
|
| 463 |
+
aiBot: (parent) => parent.aiBot || { enabled: false, provider: 'mgzon' },
|
| 464 |
+
audio: (parent) => parent.audio || {},
|
| 465 |
+
theme: (parent) => parent.theme || {},
|
| 466 |
+
layout: (parent) => parent.layout || {},
|
| 467 |
+
header: (parent) => parent.header || {},
|
| 468 |
+
footer: (parent) => parent.footer || {},
|
| 469 |
+
seo: (parent) => parent.seo || {},
|
| 470 |
+
schema: (parent) => parent.schema || {},
|
| 471 |
},
|
| 472 |
|
| 473 |
Project: {
|