re-unify into one route all id ops for teams and users
This commit is contained in:
1 parent
a2b8b85de4
commit
5233dad5f9
11 files changed
+332
-587
No files matched your search
@@ -11,7 +11,19 @@ export const httpMethod = (allowedHttpMethod: "GET" | "POST" | "PATCH" | "DELETE
|
||||
};
|
||||
};
|
||||
|
||||
export const httpMethods = (allowedHttpMethod: string[]): NextMiddleware => {
|
||||
return async function (req, res, next) {
|
||||
if (allowedHttpMethod.map((method) => method === req.method)) {
|
||||
await next();
|
||||
} else {
|
||||
res.status(405).json({ message: `Only ${allowedHttpMethod} Method allowed` });
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const HTTP_POST = httpMethod("POST");
|
||||
export const HTTP_GET = httpMethod("GET");
|
||||
export const HTTP_PATCH = httpMethod("PATCH");
|
||||
export const HTTP_DELETE = httpMethod("DELETE");
|
||||
export const HTTP_GET_DELETE_PATCH = httpMethods(["GET", "DELETE", "PATCH"]);
|
||||
@@ -2,11 +2,12 @@ import { label } from "next-api-middleware";
|
||||
|
||||
import { addRequestId } from "./addRequestid";
|
||||
import { captureErrors } from "./captureErrors";
|
||||
import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET } from "./httpMethods";
|
||||
import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET, HTTP_GET_DELETE_PATCH } from "./httpMethods";
|
||||
import { verifyApiKey } from "./verifyApiKey";
|
||||
|
||||
const withMiddleware = label(
|
||||
{
|
||||
HTTP_GET_DELETE_PATCH,
|
||||
HTTP_GET,
|
||||
HTTP_PATCH,
|
||||
HTTP_POST,
|
||||
|
||||
Reference in new issue
Block a user