other
This commit is contained in:
21
backend/routes/invites.routes.js
Normal file
21
backend/routes/invites.routes.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import express from "express";
|
||||
import crypto from "crypto";
|
||||
import { protectStaff } from "../middleware/staffAuthMiddleware.js";
|
||||
import Invitation from "../models/Invitation.model.js";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post("/generate", protectStaff, async (req, res) => {
|
||||
try {
|
||||
const invitationCode = crypto.randomBytes(6).toString("hex");
|
||||
|
||||
const invitation = new Invitation({ code: invitationCode, createdBy: req.user._id });
|
||||
await invitation.save();
|
||||
|
||||
res.status(201).json({ invitationCode });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user