Mark-Lasfar commited on
Commit
b312fa4
ยท
1 Parent(s): 4a8d3ae

Add GraphQL

Browse files
Files changed (1) hide show
  1. 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
- socialLinks: (parent) => parent.socialLinks || {},
342
-
343
- // โœ… storeEnabled - ุชุฌูŠุจ ู…ู† StoreSettings
344
- storeEnabled: async (parent) => {
345
- // parent._id ู‡ูˆ userId ู„ุฃู† Profile ุฌุฒุก ู…ู† User
346
  const userId = parent._id || parent.userId;
347
  if (!userId) return false;
348
- try {
349
- const storeSettings = await StoreSettings.findOne({ userId });
350
- return storeSettings?.enabled || false;
351
- } catch (error) {
352
- console.error('Error fetching storeEnabled:', error);
353
- return false;
354
- }
355
- },
356
-
357
- // โœ… averageRating - ุชุฌูŠุจ ู…ู† StoreSettings
358
- averageRating: async (parent) => {
 
359
  const userId = parent._id || parent.userId;
360
  if (!userId) return 0;
361
- try {
362
- const storeSettings = await StoreSettings.findOne({ userId });
363
- return storeSettings?.averageRating || 0;
364
- } catch (error) {
365
- console.error('Error fetching averageRating:', error);
366
- return 0;
367
- }
368
- },
369
-
370
- // โœ… totalRatings - ุชุฌูŠุจ ู…ู† StoreSettings
371
- totalRatings: async (parent) => {
 
372
  const userId = parent._id || parent.userId;
373
  if (!userId) return 0;
374
- try {
375
- const storeSettings = await StoreSettings.findOne({ userId });
376
- return storeSettings?.totalRatings || 0;
377
- } catch (error) {
378
- console.error('Error fetching totalRatings:', error);
379
- return 0;
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
- hasStory: async (parent, args, context) => {
441
- const userId = parent._id || parent.userId;
442
- if (!userId) return false;
443
- try {
444
- const count = await Story.countDocuments({
445
- userId: userId,
446
- expiresAt: { $gt: new Date() }
447
- });
448
- return count > 0;
449
- } catch (error) {
450
- return false;
451
- }
452
- },
453
-
454
- // โœ… ุงู„ุญู‚ูˆู„ ุงู„ู„ูŠ ู…ูุฑูˆุถ ุชูƒูˆู† Objects
455
- sectionNames: (parent) => parent.sectionNames || {},
456
- sectionVisibility: (parent) => parent.sectionVisibility || {},
457
- sectionStyleSettings: (parent) => parent.sectionStyleSettings || {},
458
- designSettings: (parent) => parent.designSettings || {},
459
- aiBot: (parent) => parent.aiBot || { enabled: false, provider: 'mgzon' },
460
- audio: (parent) => parent.audio || {},
461
- theme: (parent) => parent.theme || {},
462
- layout: (parent) => parent.layout || {},
463
- header: (parent) => parent.header || {},
464
- footer: (parent) => parent.footer || {},
465
- seo: (parent) => parent.seo || {},
466
- schema: (parent) => parent.schema || {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: {