22 lines
626 B
JavaScript
22 lines
626 B
JavaScript
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;
|