randydev commited on
Commit
8e36dfa
·
verified ·
1 Parent(s): 19eeb57

Update plugins/federations.js

Browse files
Files changed (1) hide show
  1. plugins/federations.js +73 -0
plugins/federations.js CHANGED
@@ -565,4 +565,77 @@ FedsRoutes.post("/api/v2/federation/unsubfed", authenticateApiKey, apiLimiter, a
565
  }
566
  });
567
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  export { FedsRoutes };
 
565
  }
566
  });
567
 
568
+ /**
569
+ * @swagger
570
+ * /api/v2/federation/renamefed:
571
+ * post:
572
+ * summary: Rename a Federation
573
+ * tags: [Federation]
574
+ * description: Change the name of an existing federation.
575
+ * requestBody:
576
+ * required: true
577
+ * content:
578
+ * application/json:
579
+ * schema:
580
+ * type: object
581
+ * properties:
582
+ * federation_uuid:
583
+ * type: string
584
+ * description: UUID of the federation to be renamed.
585
+ * new_name:
586
+ * type: string
587
+ * description: The new name for the federation.
588
+ * parameters:
589
+ * - in: header
590
+ * name: x-api-key
591
+ * required: true
592
+ * description: API key for authentication.
593
+ * schema:
594
+ * type: string
595
+ * responses:
596
+ * 200:
597
+ * description: Federation successfully renamed.
598
+ * content:
599
+ * application/json:
600
+ * schema:
601
+ * type: object
602
+ * properties:
603
+ * message:
604
+ * type: string
605
+ * example: "Federation renamed to NewFedName successfully."
606
+ * 400:
607
+ * description: Missing parameters or federation name already exists.
608
+ * 404:
609
+ * description: Federation not found.
610
+ * 500:
611
+ * description: Internal server error.
612
+ */
613
+ FedsRoutes.post("/api/v2/federation/renamefed", authenticateApiKey, apiLimiter, async (req, res) => {
614
+ try {
615
+ const { federation_uuid, new_name } = req.body;
616
+
617
+ if (!federation_uuid || !new_name) {
618
+ return res.status(400).json({ error: "Federation UUID and new name are required." });
619
+ }
620
+
621
+ const federation = await Federation.findOne({ uuid: federation_uuid });
622
+
623
+ if (!federation) {
624
+ return res.status(404).json({ error: "Federation not found." });
625
+ }
626
+
627
+ const existingFederation = await Federation.findOne({ name: new_name });
628
+ if (existingFederation) {
629
+ return res.status(400).json({ error: "Federation name already exists." });
630
+ }
631
+
632
+ federation.name = new_name;
633
+ await federation.save();
634
+
635
+ res.json({ message: `Federation renamed to ${new_name} successfully.` });
636
+ } catch (error) {
637
+ res.status(500).json({ error: `Failed to rename federation: ${error.message}` });
638
+ }
639
+ });
640
+
641
  export { FedsRoutes };