Files
StevenandGitHub 4466ba436b chore(examples): use default prettier for examples/templates (#60530)
## 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
2024-01-11 16:01:44 -07:00

45 lines
1.0 KiB
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { client, e } from "../../../client";
// PATCH /api/post/:id
async function updatePost(
postId: string,
data: { title?: string; content?: string },
) {
return await e
.update(e.Post, (post) => ({
filter: e.op(post.id, "=", e.uuid(postId)),
set: {
title: data.title,
content: data.content,
},
}))
.run(client);
}
// DELETE /api/post/:id
async function deletePost(postId: string) {
return await e
.delete(e.Post, (post) => ({
filter: e.op(post.id, "=", e.uuid(postId)),
}))
.run(client);
}
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
const postId = req.query.id as string;
if (req.method === "DELETE") {
res.json(await deletePost(postId));
} else if (req.method === "PATCH") {
res.json(await updatePost(postId, req.body));
} else {
throw new Error(
`The HTTP ${req.method} method is not supported at this route.`,
);
}
}