Mark-Lasfar commited on
Commit
d3d96da
·
1 Parent(s): 5697548

Add GraphQL

Browse files
Files changed (1) hide show
  1. server.js +18 -2
server.js CHANGED
@@ -15511,7 +15511,7 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15511
  body('text').optional().isString(),
15512
  body('backgroundColor').optional().isString(),
15513
  body('textColor').optional().isString(),
15514
- body('textStyle').optional().isObject(), // ✅ أضف هذا
15515
  body('visibility').optional().isIn(['public', 'followers', 'only-me'])
15516
  ], handleUploadError, async (req, res) => {
15517
  const errors = validationResult(req);
@@ -15551,6 +15551,21 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15551
  maxWidth: 90
15552
  };
15553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15554
  const story = new Story({
15555
  userId: req.user.userId,
15556
  media: {
@@ -15561,9 +15576,10 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15561
  text: req.body.text || '',
15562
  backgroundColor: req.body.backgroundColor || '#000000',
15563
  textColor: req.body.textColor || '#ffffff',
15564
- textStyle: req.body.textStyle ? { ...defaultTextStyle, ...req.body.textStyle } : defaultTextStyle,
15565
  visibility: req.body.visibility || 'followers'
15566
  });
 
15567
 
15568
  await story.save();
15569
  await notifyFollowersAboutStory(req.user.userId);
 
15511
  body('text').optional().isString(),
15512
  body('backgroundColor').optional().isString(),
15513
  body('textColor').optional().isString(),
15514
+ body('textStyle').optional().isString(), // ✅ أضف هذا
15515
  body('visibility').optional().isIn(['public', 'followers', 'only-me'])
15516
  ], handleUploadError, async (req, res) => {
15517
  const errors = validationResult(req);
 
15551
  maxWidth: 90
15552
  };
15553
 
15554
+ let textStyleObj = defaultTextStyle;
15555
+ if (req.body.textStyle) {
15556
+ try {
15557
+ // إذا كان String، نحوله إلى Object
15558
+ const parsed = typeof req.body.textStyle === 'string'
15559
+ ? JSON.parse(req.body.textStyle)
15560
+ : req.body.textStyle;
15561
+ textStyleObj = { ...defaultTextStyle, ...parsed };
15562
+ } catch (e) {
15563
+ console.error('Error parsing textStyle:', e);
15564
+ // إذا فشل التحويل، نستخدم الـ default
15565
+ textStyleObj = defaultTextStyle;
15566
+ }
15567
+ }
15568
+
15569
  const story = new Story({
15570
  userId: req.user.userId,
15571
  media: {
 
15576
  text: req.body.text || '',
15577
  backgroundColor: req.body.backgroundColor || '#000000',
15578
  textColor: req.body.textColor || '#ffffff',
15579
+ textStyle: textStyleObj, // ✅ استخدام الكائن المحول
15580
  visibility: req.body.visibility || 'followers'
15581
  });
15582
+
15583
 
15584
  await story.save();
15585
  await notifyFollowersAboutStory(req.user.userId);