everydaycats commited on
Commit
202c817
Β·
verified Β·
1 Parent(s): d253e8e

Update apps/storylines.js

Browse files
Files changed (1) hide show
  1. apps/storylines.js +27 -0
apps/storylines.js CHANGED
@@ -349,6 +349,33 @@ router.post('/admin/chapters', adminOnly, async (req, res) => {
349
  }
350
  });
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  // ─────────────────────────────────────────────
353
  // ADMIN: DELETE /storyline/admin/chapters/:id
354
  // ─────────────────────────────────────────────
 
349
  }
350
  });
351
 
352
+
353
+ router.patch('/admin/chapters/:id', adminOnly, async (req, res) => {
354
+ try {
355
+ const { id } = req.params;
356
+ const { title, order, content, context, characters } = req.body;
357
+ const { data: chapter, error } = await supabase
358
+ .from('storyline_chapters')
359
+ .update({ title, order, content, context })
360
+ .eq('id', id)
361
+ .select()
362
+ .single();
363
+ if (error) throw error;
364
+
365
+ if (characters) {
366
+ await supabase.from('storyline_characters').delete().eq('chapter_id', id);
367
+ if (characters.length > 0) {
368
+ const rows = characters.map(c => ({ ...c, chapter_id: id, story_id: chapter.story_id }));
369
+ await supabase.from('storyline_characters').insert(rows);
370
+ }
371
+ }
372
+ res.json({ success: true, data: chapter });
373
+ } catch (err) {
374
+ res.status(500).json({ success: false, error: err.message });
375
+ }
376
+ });
377
+
378
+
379
  // ─────────────────────────────────────────────
380
  // ADMIN: DELETE /storyline/admin/chapters/:id
381
  // ─────────────────────────────────────────────