-
@ Marth
2024-08-18 19:04:33
```js
import { createCourseDraft } from '@/db/models/courseDraftModels';
export default async function handler(req, res) {
if (req.method === 'POST') {
try {
const { userId, title, summary, image, price, topics, resources, drafts } = req.body;
const courseDraft = await createCourseDraft({
userId,
title,
summary,
image,
price,
topics,
resources: {
connect: resources.map(id => ({ id }))
},
drafts: {
connect: drafts.map(id => ({ id }))
}
});
res.status(201).json(courseDraft);
} catch (error) {
res.status(500).json({ error: 'Failed to create course draft' });
}
} else {
res.setHeader('Allow', ['POST']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
```