2025.11.27.17.50

This commit is contained in:
RUI
2025-11-27 17:50:44 +08:00
commit 5dbb30b32c
111 changed files with 18320 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { MembershipPlan } from '@/models';
import withDatabase from '@/lib/withDatabase';
async function handler(req: NextApiRequest, res: NextApiResponse) {
const { id } = req.query;
if (req.method === 'GET') {
try {
const plan = await MembershipPlan.findById(id);
if (!plan) return res.status(404).json({ message: 'Plan not found' });
return res.status(200).json(plan);
} catch (error) {
return res.status(500).json({ message: 'Failed to fetch plan' });
}
} else if (req.method === 'PUT') {
try {
const plan = await MembershipPlan.findByIdAndUpdate(id, req.body, { new: true });
if (!plan) return res.status(404).json({ message: 'Plan not found' });
return res.status(200).json(plan);
} catch (error) {
return res.status(500).json({ message: 'Failed to update plan' });
}
} else if (req.method === 'DELETE') {
try {
const plan = await MembershipPlan.findByIdAndDelete(id);
if (!plan) return res.status(404).json({ message: 'Plan not found' });
return res.status(200).json({ message: 'Plan deleted' });
} catch (error) {
return res.status(500).json({ message: 'Failed to delete plan' });
}
} else {
return res.status(405).json({ message: 'Method not allowed' });
}
}
export default withDatabase(handler);