mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from "next";
|
|
import dbConnect from "../../../lib/dbConnect";
|
|
import Pet from "../../../models/Pet";
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse,
|
|
) {
|
|
const {
|
|
query: { id },
|
|
method,
|
|
} = req;
|
|
|
|
await dbConnect();
|
|
|
|
switch (method) {
|
|
case "GET" /* Get a model by its ID */:
|
|
try {
|
|
const pet = await Pet.findById(id);
|
|
if (!pet) {
|
|
return res.status(400).json({ success: false });
|
|
}
|
|
res.status(200).json({ success: true, data: pet });
|
|
} catch (error) {
|
|
res.status(400).json({ success: false });
|
|
}
|
|
break;
|
|
|
|
case "PUT" /* Edit a model by its ID */:
|
|
try {
|
|
const pet = await Pet.findByIdAndUpdate(id, req.body, {
|
|
new: true,
|
|
runValidators: true,
|
|
});
|
|
if (!pet) {
|
|
return res.status(400).json({ success: false });
|
|
}
|
|
res.status(200).json({ success: true, data: pet });
|
|
} catch (error) {
|
|
res.status(400).json({ success: false });
|
|
}
|
|
break;
|
|
|
|
case "DELETE" /* Delete a model by its ID */:
|
|
try {
|
|
const deletedPet = await Pet.deleteOne({ _id: id });
|
|
if (!deletedPet) {
|
|
return res.status(400).json({ success: false });
|
|
}
|
|
res.status(200).json({ success: true, data: {} });
|
|
} catch (error) {
|
|
res.status(400).json({ success: false });
|
|
}
|
|
break;
|
|
|
|
default:
|
|
res.status(400).json({ success: false });
|
|
break;
|
|
}
|
|
}
|