feat: teamId availability in API

This commit is contained in:
Agusti Fernandez Pardo committed 2022-07-05 20:12:14 +02:00
1 parent be2647790c
commit a63b623a7d
7 files changed
+63 -12

No files matched your search

+5
View File
@@ -15,8 +15,13 @@ declare module "next" {
session: { user: { id: number } };
query: { [key: string]: string | string[] };
isAdmin: boolean;
pagination: { take: number; skip: number };
}
}
export const extendRequest: NextMiddleware = async (req, res, next) => {
req.pagination = {
take: 100,
skip: 0,
};
await next();
};
+3
View File
@@ -1,4 +1,5 @@
import { label } from "next-api-middleware";
import PagesManifestPlugin from "next/dist/build/webpack/plugins/pages-manifest-plugin";
import { addRequestId } from "./addRequestid";
import { captureErrors } from "./captureErrors";
@@ -13,6 +14,7 @@ import {
HTTP_GET_DELETE_PATCH,
} from "./httpMethods";
import { verifyApiKey } from "./verifyApiKey";
import { withPagination } from "./withPagination";
const withMiddleware = label(
{
@@ -26,6 +28,7 @@ const withMiddleware = label(
verifyApiKey,
customPrismaClient,
extendRequest,
pagination: withPagination,
sentry: captureErrors,
},
// The order here, determines the order of execution, put customPrismaClient before verifyApiKey always.
+12
View File
@@ -0,0 +1,12 @@
import { NextMiddleware } from "next-api-middleware";
export const withPagination: NextMiddleware = async (req, res, next) => {
const { page } = req.query;
const pageNumber = parseInt(page as string);
const skip = pageNumber * 10;
req.pagination = {
take: 10,
skip: skip || 0,
};
await next();
};
+1
View File
@@ -153,6 +153,7 @@ export const schemaUserReadPublic = User.pick({
createdDate: true,
verified: true,
invitedTo: true,
role: true,
});
export const schemaUsersReadPublic = z.array(schemaUserReadPublic);