2023-10-22 23:28:39 -05:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import updateCollectionById from "@/lib/api/controllers/collections/collectionId/updateCollectionById";
|
|
|
|
import deleteCollectionById from "@/lib/api/controllers/collections/collectionId/deleteCollectionById";
|
2023-11-06 07:25:57 -06:00
|
|
|
import verifyUser from "@/lib/api/verifyUser";
|
2023-10-22 23:28:39 -05:00
|
|
|
|
|
|
|
export default async function collections(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse
|
|
|
|
) {
|
2023-11-06 07:25:57 -06:00
|
|
|
const user = await verifyUser({ req, res });
|
|
|
|
if (!user) return;
|
2023-10-22 23:28:39 -05:00
|
|
|
|
|
|
|
if (req.method === "PUT") {
|
|
|
|
const updated = await updateCollectionById(
|
2023-11-02 13:59:31 -05:00
|
|
|
user.id,
|
2023-10-22 23:28:39 -05:00
|
|
|
Number(req.query.id) as number,
|
|
|
|
req.body
|
|
|
|
);
|
|
|
|
return res.status(updated.status).json({ response: updated.response });
|
|
|
|
} else if (req.method === "DELETE") {
|
|
|
|
const deleted = await deleteCollectionById(
|
2023-11-02 13:59:31 -05:00
|
|
|
user.id,
|
2023-10-22 23:28:39 -05:00
|
|
|
Number(req.query.id) as number
|
|
|
|
);
|
|
|
|
return res.status(deleted.status).json({ response: deleted.response });
|
|
|
|
}
|
|
|
|
}
|