Merge pull request #135 from calcom/feat/availability-teams

Feat/availability teams + pagination for /users
This commit is contained in:
Agusti Fernandez Pardo authored and GitHub committed 2022-07-12 20:16:57 +02:00
commit 2bb6c7de45
19 files changed
+414 -242

No files matched your search

+5
View File
@@ -15,8 +15,13 @@ declare module "next" {
session: { user: { id: number } };
query: Partial<{ [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();
};
+2
View File
@@ -13,6 +13,7 @@ import {
HTTP_GET_DELETE_PATCH,
} from "./httpMethods";
import { verifyApiKey } from "./verifyApiKey";
import { withPagination } from "./withPagination";
const withMiddleware = label(
{
@@ -26,6 +27,7 @@ const withMiddleware = label(
verifyApiKey,
customPrismaClient,
extendRequest,
pagination: withPagination,
sentry: captureErrors,
},
// The order here, determines the order of execution, put customPrismaClient before verifyApiKey always.
+28
View File
@@ -0,0 +1,28 @@
import { NextMiddleware } from "next-api-middleware";
import z from "zod";
const withPage = z.object({
page: z
.string()
.min(1)
.optional()
.default("1")
.transform((n) => parseInt(n)),
take: z
.string()
.min(10)
.max(100)
.optional()
.default("10")
.transform((n) => parseInt(n)),
});
export const withPagination: NextMiddleware = async (req, _, next) => {
const { page, take } = withPage.parse(req.query);
const skip = page * take || 0;
req.pagination = {
take,
skip,
};
await next();
};
+21
View File
@@ -0,0 +1,21 @@
import { withValidation } from "next-validations";
import { z } from "zod";
import { baseApiParams } from "./baseApiParams";
// Extracted out as utility function so can be reused
// at different endpoints that require this validation.
export const schemaQueryTeamId = baseApiParams
.extend({
teamId: z
.string()
.regex(/^\d+$/)
.transform((id) => parseInt(id)),
})
.strict();
export const withValidQueryTeamId = withValidation({
schema: schemaQueryTeamId,
type: "Zod",
mode: "query",
});
+1 -1
View File
@@ -8,4 +8,4 @@ const schemaTeamRequiredParams = z.object({});
export const schemaTeamBodyParams = schemaTeamBaseBodyParams.merge(schemaTeamRequiredParams);
export const schemaTeamPublic = Team.omit({});
export const schemaTeamReadPublic = Team.omit({});
+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);