Merge pull request #12 from calcom/feat/more-validations
This commit is contained in:
+15
-13
@@ -1,15 +1,17 @@
|
||||
// FIXME: import eslint-config-calcom-base from '@calcom/config/eslint
|
||||
{
|
||||
"root": true,
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@next/next/recommended"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": { "project": ["./tsconfig.json"] },
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"ignorePatterns": ["src/**/*.test.ts", "src/frontend/generated/*"]
|
||||
}
|
||||
"root": true,
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
"plugin:@next/next/recommended"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": { "project": ["./tsconfig.json"] },
|
||||
"plugins": ["@typescript-eslint", "prettier"],
|
||||
"rules": {
|
||||
"prettier/prettier": "error"
|
||||
},
|
||||
"ignorePatterns": ["src/**/*.test.ts", "src/frontend/generated/*"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.next/
|
||||
coverage/
|
||||
node_modules/
|
||||
@@ -15,7 +15,6 @@ It doesn't have react or react-dom as a dependency, and will only be used by a r
|
||||
- `api.cal.com/v1`
|
||||
- `api.cal.com/api/v1`
|
||||
|
||||
|
||||
## API Endpoint Validation
|
||||
|
||||
### Zod
|
||||
@@ -32,7 +31,6 @@ We also use this useful helper library that let's us wrap our endpoints in a val
|
||||
|
||||
We aim to provide a fully tested API for our peace of mind, this is accomplished by using jest + node-mocks-http
|
||||
|
||||
|
||||
## Next.config.js
|
||||
|
||||
### Redirects
|
||||
@@ -40,15 +38,14 @@ We aim to provide a fully tested API for our peace of mind, this is accomplished
|
||||
Since this will only support an API, we redirect the requests to root to the /api folder.
|
||||
We also added a redirect for future-proofing API versioning when we might need it, without having to resort to dirty hacks like a v1/v2 folders with lots of duplicated code, instead we redirect /api/v*/:rest to /api/:rest?version=*
|
||||
|
||||
|
||||
The priority is the booking-related API routes so people can build their own booking flow, then event type management routes, then availability management routes etc
|
||||
|
||||
|
||||
How to add a new model or endpoint
|
||||
|
||||
Basically there's three places of the codebase you need to think about for each feature.
|
||||
|
||||
/pages/api/
|
||||
|
||||
- This is the most important one, and where your endpoint will live. You will leverage nextjs dynamic routes and expose one file for each endpoint you want to support ideally.
|
||||
|
||||
## How the codebase is organized.
|
||||
@@ -66,7 +63,6 @@ GET pages/api/endpoint/[id]/index.ts - Read All of your resource
|
||||
PATCH pages/api/endpoint/[id]/edit.ts - Create new resource
|
||||
DELETE pages/api/endpoint/[id]/delete.ts - Create new resource
|
||||
|
||||
|
||||
## `/tests/`
|
||||
|
||||
This is where all your endpoint's tests live, we mock prisma calls. We aim for at least 50% global coverage. Test each of your endpoints.
|
||||
|
||||
+4
-26
@@ -7,10 +7,8 @@ const config = {
|
||||
clearMocks: true,
|
||||
coverageDirectory: "./coverage",
|
||||
collectCoverage: true,
|
||||
"collectCoverageFrom": [
|
||||
"pages/api/**/*.ts"
|
||||
],
|
||||
|
||||
collectCoverageFrom: ["pages/api/**/*.ts"],
|
||||
|
||||
// An array of regexp pattern strings used to skip coverage collection
|
||||
// coveragePathIgnorePatterns: [
|
||||
// "/node_modules/"
|
||||
@@ -20,12 +18,7 @@ const config = {
|
||||
// coverageProvider: "babel",
|
||||
|
||||
// A list of reporter names that Jest uses when writing coverage reports
|
||||
coverageReporters: [
|
||||
"json",
|
||||
"text",
|
||||
"lcov",
|
||||
"clover"
|
||||
],
|
||||
coverageReporters: ["json", "text", "lcov", "clover"],
|
||||
|
||||
// An object that configures minimum threshold enforcement for coverage results
|
||||
coverageThreshold: {
|
||||
@@ -42,34 +35,19 @@ const config = {
|
||||
// Make calling deprecated APIs throw helpful error messages
|
||||
errorOnDeprecated: true,
|
||||
|
||||
// Force coverage collection from ignored files using an array of glob patterns
|
||||
// forceCoverageMatch: [],
|
||||
|
||||
// A path to a module which exports an async function that is triggered once before all test suites
|
||||
// globalSetup: undefined,
|
||||
|
||||
// A path to a module which exports an async function that is triggered once after all test suites
|
||||
// globalTeardown: undefined,
|
||||
|
||||
// A set of global variables that need to be available in all test environments
|
||||
// globals: {},
|
||||
|
||||
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
||||
maxWorkers: "50%",
|
||||
|
||||
|
||||
|
||||
moduleNameMapper: {
|
||||
"^@lib/(.*)$": "<rootDir>/lib/$1",
|
||||
"^@api/(.*)$": "<rootDir>/pages/api/$1",
|
||||
},
|
||||
|
||||
|
||||
// The paths to modules that run some code to configure or set up the testing environment before each test
|
||||
// setupFiles: [],
|
||||
|
||||
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
||||
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
|
||||
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
|
||||
|
||||
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
||||
slowTestThreshold: 0.1,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
import { nanoid } from "nanoid";
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
export const addRequestId: NextMiddleware = async (_req, res, next) => {
|
||||
// Apply header
|
||||
res.setHeader("X-Response-ID", nanoid());
|
||||
// Let remaining middleware and API route execute
|
||||
await next();
|
||||
};
|
||||
// Apply header
|
||||
res.setHeader("Calcom-Response-ID", nanoid());
|
||||
// Let remaining middleware and API route execute
|
||||
await next();
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
import * as Sentry from "@sentry/nextjs";
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
export const captureErrors: NextMiddleware = async (_req, res, next) => {
|
||||
try {
|
||||
@@ -7,10 +7,8 @@ export const captureErrors: NextMiddleware = async (_req, res, next) => {
|
||||
// middleware and the API route handler
|
||||
await next();
|
||||
} catch (err) {
|
||||
const eventId = Sentry.captureException(err);
|
||||
console.log(eventId)
|
||||
Sentry.captureException(err);
|
||||
res.status(500);
|
||||
res.json({ error: err });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
export const httpMethod = (
|
||||
allowedHttpMethod: "GET" | "POST" | "PATCH" | "DELETE"
|
||||
): NextMiddleware => {
|
||||
export const httpMethod = (allowedHttpMethod: "GET" | "POST" | "PATCH" | "DELETE"): NextMiddleware => {
|
||||
return async function (req, res, next) {
|
||||
if (req.method === allowedHttpMethod || req.method == "OPTIONS") {
|
||||
await next();
|
||||
} else {
|
||||
res.status(404);
|
||||
res.status(405).json({ message: `Only ${allowedHttpMethod} Method allowed` });
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const postOnly = httpMethod("POST");
|
||||
export const getOnly = httpMethod("GET");
|
||||
export const patchOnly = httpMethod("PATCH");
|
||||
export const deleteOnly = httpMethod("DELETE");
|
||||
export const HTTP_POST = httpMethod("POST");
|
||||
export const HTTP_GET = httpMethod("GET");
|
||||
export const HTTP_PATCH = httpMethod("PATCH");
|
||||
export const HTTP_DELETE = httpMethod("DELETE");
|
||||
|
||||
+14
-11
@@ -1,20 +1,23 @@
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
// import { nanoid } from "nanoid";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
const dateInPast = function (firstDate: Date, secondDate: Date) {
|
||||
if (firstDate.setHours(0, 0, 0, 0) <= secondDate.setHours(0, 0, 0, 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (firstDate.setHours(0, 0, 0, 0) <= secondDate.setHours(0, 0, 0, 0)) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
const today = new Date();
|
||||
|
||||
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
||||
const apiKey = await prisma.apiKey.findUnique({ where: { id: req.query.apiKey as string } });
|
||||
if (!apiKey) {
|
||||
res.status(400).json({ error: 'Your api key is not valid' });
|
||||
throw new Error('No api key found');
|
||||
}
|
||||
if (apiKey.expiresAt && dateInPast(apiKey.expiresAt, today)) await next();
|
||||
else res.status(400).json({ error: 'Your api key is not valid' });
|
||||
const apiKey = await prisma.apiKey.findUnique({ where: { id: req.query.apiKey as string } });
|
||||
if (!apiKey) {
|
||||
res.status(400).json({ error: "Your api key is not valid" });
|
||||
throw new Error("No api key found");
|
||||
}
|
||||
if (apiKey.expiresAt && apiKey.userId && dateInPast(apiKey.expiresAt, today)) {
|
||||
res.setHeader("Calcom-User-ID", apiKey.userId);
|
||||
await next();
|
||||
} else res.status(400).json({ error: "Your api key is not valid" });
|
||||
};
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import { label } from "next-api-middleware";
|
||||
|
||||
import { addRequestId } from "./addRequestid";
|
||||
import { captureErrors } from "./captureErrors";
|
||||
import { HTTP_POST, HTTP_DELETE, HTTP_PATCH, HTTP_GET, httpMethod } from "./httpMethods";
|
||||
import { verifyApiKey } from "./verifyApiKey";
|
||||
import { postOnly, deleteOnly, patchOnly, getOnly } from "./httpMethods";
|
||||
|
||||
const withMiddleware = label(
|
||||
{
|
||||
getOnly,
|
||||
patchOnly,
|
||||
postOnly,
|
||||
deleteOnly,
|
||||
HTTP_GET,
|
||||
HTTP_PATCH,
|
||||
HTTP_POST,
|
||||
HTTP_DELETE,
|
||||
addRequestId,
|
||||
verifyApiKey,
|
||||
sentry: captureErrors, // <-- Optionally alias middleware
|
||||
sentry: captureErrors,
|
||||
httpMethod: httpMethod("GET" || "DELETE" || "PATCH" || "POST"),
|
||||
},
|
||||
["sentry","verifyApiKey"] // <-- Provide a list of middleware to call automatically
|
||||
["sentry", "verifyApiKey", "httpMethod", "addRequestId"] // <-- Provide a list of middleware to call automatically
|
||||
);
|
||||
|
||||
export { withMiddleware };
|
||||
export { withMiddleware };
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { User, ApiKey } from "@calcom/prisma/client";
|
||||
|
||||
// Base response, used for all responses
|
||||
export type BaseResponse = {
|
||||
message?: string;
|
||||
error?: Error;
|
||||
};
|
||||
// User
|
||||
export type UserResponse = BaseResponse & {
|
||||
data?: Partial<User>;
|
||||
};
|
||||
export type UsersResponse = BaseResponse & {
|
||||
data?: Partial<User>[];
|
||||
};
|
||||
|
||||
// API Key
|
||||
export type ApiKeyResponse = BaseResponse & {
|
||||
data?: Partial<ApiKey>;
|
||||
};
|
||||
export type ApiKeysResponse = BaseResponse & {
|
||||
data?: Partial<ApiKey>[];
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
export const stringifyISODate = (date: Date|undefined): string => {
|
||||
return `${date?.toISOString()}`
|
||||
}
|
||||
// TODO: create a function that takes an object and returns a stringified version of dates of it.
|
||||
export const stringifyISODate = (date: Date | undefined): string => {
|
||||
return `${date?.toISOString()}`;
|
||||
};
|
||||
// TODO: create a function that takes an object and returns a stringified version of dates of it.
|
||||
|
||||
+11
-14
@@ -1,19 +1,16 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaApiKey = z
|
||||
.object({
|
||||
// We need to cast the date as strings as when we get it from the json response
|
||||
// we serve in api it is a string too (JSON doesn't directly support Date types)
|
||||
createdAt: z.date().optional().or(z.string().optional()),
|
||||
expiresAt: z.date().optional(), // default is 30 days
|
||||
note: z.string().min(1).optional(),
|
||||
})
|
||||
.strict(); // Adding strict so that we can disallow passing in extra fields
|
||||
const withValidApiKey = withValidation({
|
||||
schema: schemaApiKey,
|
||||
import { _ApiKeyModel as ApiKey } from "@calcom/prisma/zod";
|
||||
|
||||
export const schemaApiKeyBodyParams = ApiKey.omit({ id: true, userId: true, createdAt: true });
|
||||
|
||||
export const schemaApiKeyPublic = ApiKey.omit({
|
||||
id: true,
|
||||
userId: true,
|
||||
});
|
||||
|
||||
export const withValidApiKey = withValidation({
|
||||
schema: schemaApiKeyBodyParams,
|
||||
type: "Zod",
|
||||
mode: "body",
|
||||
});
|
||||
|
||||
export { schemaApiKey, withValidApiKey };
|
||||
|
||||
@@ -7,13 +7,13 @@ const schemaAvailability = z
|
||||
userId: z.number(),
|
||||
eventTypeId: z.number(),
|
||||
scheduleId: z.number(),
|
||||
|
||||
|
||||
days: z.array(z.number()),
|
||||
date: z.date().or(z.string()),
|
||||
startTime: z.string(),
|
||||
endTime: z.string(),
|
||||
})
|
||||
.strict();
|
||||
.strict();
|
||||
const withValidAvailability = withValidation({
|
||||
schema: schemaAvailability,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaBookingReference = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaBookingReference = z.object({}).strict();
|
||||
const withValidBookingReference = withValidation({
|
||||
schema: schemaBookingReference,
|
||||
type: "Zod",
|
||||
|
||||
@@ -15,7 +15,7 @@ const schemaBooking = z
|
||||
rejected: z.boolean().default(false),
|
||||
paid: z.boolean().default(false),
|
||||
})
|
||||
.strict();
|
||||
.strict();
|
||||
const withValidBooking = withValidation({
|
||||
schema: schemaBooking,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaCredential = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaCredential = z.object({}).strict();
|
||||
const withValidCredential = withValidation({
|
||||
schema: schemaCredential,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaDailyEventReference = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaDailyEventReference = z.object({}).strict();
|
||||
const withValidDailyEventReference = withValidation({
|
||||
schema: schemaDailyEventReference,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaDestinationCalendar = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaDestinationCalendar = z.object({}).strict();
|
||||
const withValidDestinationCalendar = withValidation({
|
||||
schema: schemaDestinationCalendar,
|
||||
type: "Zod",
|
||||
|
||||
@@ -8,7 +8,7 @@ const schemaEventType = z
|
||||
length: z.number().min(1).max(1440), // max is a full day.
|
||||
description: z.string().min(3).optional(),
|
||||
})
|
||||
.strict();
|
||||
.strict();
|
||||
const withValidEventType = withValidation({
|
||||
schema: schemaEventType,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaMembership = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaMembership = z.object({}).strict();
|
||||
const withValidMembership = withValidation({
|
||||
schema: schemaMembership,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaPayment = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaPayment = z.object({}).strict();
|
||||
const withValidPayment = withValidation({
|
||||
schema: schemaPayment,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaSchedule = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaSchedule = z.object({}).strict();
|
||||
const withValidSchedule = withValidation({
|
||||
schema: schemaSchedule,
|
||||
type: "Zod",
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaSelectedCalendar = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaSelectedCalendar = z.object({}).strict();
|
||||
const withValidSelectedCalendar = withValidation({
|
||||
schema: schemaSelectedCalendar,
|
||||
type: "Zod",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// Extracted out as utility function so can be reused
|
||||
// at different endpoints that require this validation.
|
||||
export const baseApiParams = z
|
||||
.object({
|
||||
// since we added apiKey as query param this is required by next-validations helper
|
||||
// for query params to work properly and not fail.
|
||||
apiKey: z.string().cuid(),
|
||||
// version required for supporting /v1/ redirect to query in api as *?version=1
|
||||
version: z.string().optional(),
|
||||
})
|
||||
.strict();
|
||||
@@ -1,23 +1,18 @@
|
||||
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.
|
||||
const schemaQueryIdAsString = z
|
||||
.object({
|
||||
// since we added apiKey as query param this is required by next-validations helper
|
||||
// for query params to work properly and not fail.
|
||||
apiKey: z.string().cuid(),
|
||||
// since nextjs parses query params as strings,
|
||||
// we need to cast them to numbers using z.transform() and parseInt()
|
||||
id: z.string()
|
||||
export const schemaQueryIdAsString = baseApiParams
|
||||
.extend({
|
||||
id: z.string(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const withValidQueryIdString = withValidation({
|
||||
export const withValidQueryIdString = withValidation({
|
||||
schema: schemaQueryIdAsString,
|
||||
type: "Zod",
|
||||
mode: "query",
|
||||
});
|
||||
|
||||
export { schemaQueryIdAsString, withValidQueryIdString };
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
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.
|
||||
const schemaQueryIdParseInt = z
|
||||
.object({
|
||||
// since we added apiKey as query param this is required by next-validations helper
|
||||
// for query params to work properly and not fail.
|
||||
apiKey: z.string().cuid(),
|
||||
// since nextjs parses query params as strings,
|
||||
// we need to cast them to numbers using z.transform() and parseInt()
|
||||
export const schemaQueryIdParseInt = baseApiParams
|
||||
.extend({
|
||||
id: z
|
||||
.string()
|
||||
.regex(/^\d+$/)
|
||||
@@ -17,10 +14,8 @@ const schemaQueryIdParseInt = z
|
||||
})
|
||||
.strict();
|
||||
|
||||
const withValidQueryIdTransformParseInt = withValidation({
|
||||
export const withValidQueryIdTransformParseInt = withValidation({
|
||||
schema: schemaQueryIdParseInt,
|
||||
type: "Zod",
|
||||
mode: "query",
|
||||
});
|
||||
|
||||
export { schemaQueryIdParseInt, withValidQueryIdTransformParseInt };
|
||||
|
||||
@@ -9,7 +9,7 @@ const schemaTeam = z
|
||||
bio: z.string().min(3).optional(),
|
||||
logo: z.string().optional(),
|
||||
})
|
||||
.strict();
|
||||
.strict();
|
||||
const withValidTeam = withValidation({
|
||||
schema: schemaTeam,
|
||||
type: "Zod",
|
||||
|
||||
+23
-57
@@ -1,63 +1,29 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
import { schemaEventType } from "./eventType";
|
||||
import { schemaApiKey } from "./apiKey";
|
||||
import { schemaDestinationCalendar } from "./destination-calendar";
|
||||
import { schemaWebhook } from "./webhook";
|
||||
import { schemaAvailability } from "./availability";
|
||||
import { schemaSelectedCalendar } from "./selected-calendar";
|
||||
import { schemaBooking } from "./booking";
|
||||
import { schemaMembership } from "./membership";
|
||||
import { schemaSchedule } from "./schedule";
|
||||
import { schemaCredential } from "./credential";
|
||||
import { _UserModel as User } from "@calcom/prisma/zod";
|
||||
|
||||
const schemaUser = z
|
||||
.object({
|
||||
username: z.string().min(3),
|
||||
name: z.string().min(3),
|
||||
email: z.string().email(), // max is a full day.
|
||||
emailVerified: z.date().optional(),
|
||||
password: z.string().optional(),
|
||||
bio: z.string().min(3).optional(),
|
||||
avatar: z.string().optional(),
|
||||
timeZone: z.string().default("Europe/London"),
|
||||
weekStart: z.string().default("Sunday"),
|
||||
bufferTime: z.number().default(0),
|
||||
hideBranding: z.boolean().default(false),
|
||||
theme: z.string().optional(),
|
||||
trialEndsAt: z.date().optional(),
|
||||
eventTypes: z.array((schemaEventType)).optional(),
|
||||
credentials: z.array((schemaCredential)).optional(),
|
||||
teams: z.array((schemaMembership)).optional(),
|
||||
bookings: z.array((schemaBooking)).optional(),
|
||||
schedules: z.array((schemaSchedule)).optional(),
|
||||
defaultScheduleId: z.number().optional(),
|
||||
selectedCalendars: z.array((schemaSelectedCalendar)).optional(),
|
||||
completedOnboarding: z.boolean().default(false),
|
||||
locale: z.string().optional(),
|
||||
timeFormat: z.number().optional().default(12),
|
||||
twoFactorEnabled: z.boolean().default(false),
|
||||
twoFactorSecret: z.string().optional(),
|
||||
identityProvider: z.enum(["CAL", "SAML", "GOOGLE"]).optional().default("CAL"),
|
||||
identityProviderId: z.string().optional(),
|
||||
availability: z.array((schemaAvailability)).optional(),
|
||||
invitedTo: z.number().optional(),
|
||||
plan: z.enum(['FREE', 'TRIAL', 'PRO']).default("TRIAL"),
|
||||
webhooks: z.array((schemaWebhook)).optional(),
|
||||
brandColor: z.string().default("#292929"),
|
||||
darkBrandColor: z.string().default("#fafafa"),
|
||||
destinationCalendar: z.array(schemaDestinationCalendar).optional(), // FIXME: instanceof doesnt work here
|
||||
away: z.boolean().default(false),
|
||||
metadata: z.object({}).optional(),
|
||||
verified: z.boolean().default(false),
|
||||
apiKeys: z.array((schemaApiKey)).optional(),
|
||||
})
|
||||
.strict();
|
||||
const withValidUser = withValidation({
|
||||
schema: schemaUser,
|
||||
export const schemaUserBodyParams = User.omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
password: true,
|
||||
twoFactorEnabled: true,
|
||||
twoFactorSecret: true,
|
||||
});
|
||||
|
||||
export const schemaUserPublic = User.omit({
|
||||
identityProvider: true,
|
||||
identityProviderId: true,
|
||||
plan: true,
|
||||
metadata: true,
|
||||
password: true,
|
||||
twoFactorEnabled: true,
|
||||
twoFactorSecret: true,
|
||||
trialEndsAt: true,
|
||||
completedOnboarding: true,
|
||||
});
|
||||
|
||||
export const withValidUser = withValidation({
|
||||
schema: schemaUserBodyParams,
|
||||
type: "Zod",
|
||||
mode: "body",
|
||||
});
|
||||
|
||||
export { schemaUser, withValidUser };
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { withValidation } from "next-validations";
|
||||
import { z } from "zod";
|
||||
|
||||
const schemaWebhook = z
|
||||
.object({})
|
||||
.strict();
|
||||
const schemaWebhook = z.object({}).strict();
|
||||
|
||||
const withValidWebhook = withValidation({
|
||||
schema: schemaWebhook,
|
||||
|
||||
+1
-3
@@ -1,8 +1,6 @@
|
||||
// https://www.npmjs.com/package/next-transpile-modules
|
||||
// This makes our @calcom/prisma package from the monorepo to be transpiled and usable by API
|
||||
const withTM = require("next-transpile-modules")([
|
||||
"@calcom/prisma",
|
||||
]);
|
||||
const withTM = require("next-transpile-modules")(["@calcom/prisma", "@calcom/lib"]);
|
||||
|
||||
// use something like withPlugins([withTM], {}) if more plugins added later.
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
"start": "next start",
|
||||
"build": "next build",
|
||||
"lint": "next lint",
|
||||
"lint-fix": "next lint --fix",
|
||||
"lint-fix": "next lint --fix && prettier --write .",
|
||||
"test": "jest --detectOpenHandles",
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
||||
|
||||
@@ -3,7 +3,8 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
// Not much useful yet as prisma.client can't be used in the middlewares (client is not available)
|
||||
// For now we just throw early if no apiKey is passed,
|
||||
// but we could also check if the apiKey is valid if we had prisma here.
|
||||
export async function requireApiKeyAsQueryParams({ nextUrl }: NextRequest) {
|
||||
|
||||
export default async function requireApiKeyAsQueryParams({ nextUrl }: NextRequest) {
|
||||
const response = NextResponse.next();
|
||||
const apiKey = nextUrl.searchParams.get("apiKey");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
|
||||
@@ -13,8 +13,7 @@ type ResponseData = {
|
||||
export async function deleteApiKey(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdAsString.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.apiKey
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const data = await prisma.apiKey.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the apiKey type from the database if there's an existing resource.
|
||||
if (data) res.status(200).json({ message: `ApiKey with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.apiKey.delete() if the resource is not found.
|
||||
@@ -22,8 +21,4 @@ export async function deleteApiKey(req: NextApiRequest, res: NextApiResponse<Res
|
||||
}
|
||||
}
|
||||
|
||||
export default withMiddleware("deleteOnly", "addRequestId")(
|
||||
withValidQueryIdString(
|
||||
deleteApiKey
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE", "addRequestId")(withValidQueryIdString(deleteApiKey));
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaApiKey, withValidApiKey } from "@lib/validations/apiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/apiKey";
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -14,23 +14,25 @@ type ResponseData = {
|
||||
};
|
||||
|
||||
export async function editApiKey(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, body, method } = req;
|
||||
const { query, body } = req;
|
||||
const safeQuery = await schemaQueryIdAsString.safeParse(query);
|
||||
const safeBody = await schemaApiKey.safeParse(body);
|
||||
const safeBody = await schemaApiKeyBodyParams.safeParse(body);
|
||||
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.apiKey.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.apiKey.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else (error: unknown) => res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
(error: unknown) =>
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
}
|
||||
}
|
||||
|
||||
export default withMiddleware("patchOnly","addRequestId")(
|
||||
withValidQueryIdString(
|
||||
withValidApiKey(
|
||||
editApiKey)
|
||||
)
|
||||
);
|
||||
export default withMiddleware(
|
||||
"HTTP_PATCH",
|
||||
"addRequestId"
|
||||
)(withValidQueryIdString(withValidApiKey(editApiKey)));
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
|
||||
type ResponseData = {
|
||||
data?: ApiKey;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
};
|
||||
|
||||
@@ -18,13 +17,8 @@ export async function apiKeyById(req: NextApiRequest, res: NextApiResponse<Respo
|
||||
const data = await prisma.apiKey.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: "ApiKey was not found" });
|
||||
else res.status(404).json({ error: { message: "ApiKey was not found" } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(
|
||||
withValidQueryIdString(
|
||||
apiKeyById
|
||||
)
|
||||
);
|
||||
export default withMiddleware("addRequestId", "HTTP_GET")(withValidQueryIdString(apiKeyById));
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
|
||||
type ResponseData = {
|
||||
data?: ApiKey[];
|
||||
error?: unknown;
|
||||
@@ -16,4 +17,4 @@ async function allApiKeys(req: NextApiRequest, res: NextApiResponse<ResponseData
|
||||
else res.status(400).json({ error: "No data found" });
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(allApiKeys);
|
||||
export default withMiddleware("addRequestId", "HTTP_GET")(allApiKeys);
|
||||
|
||||
@@ -2,27 +2,23 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKey } from "@calcom/prisma/client";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaApiKey, withValidApiKey } from "@lib/validations/apiKey";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaApiKeyBodyParams, withValidApiKey } from "@lib/validations/apiKey";
|
||||
|
||||
type ResponseData = {
|
||||
data?: ApiKey;
|
||||
error?: object;
|
||||
error?: unknown;
|
||||
};
|
||||
|
||||
async function createApiKey(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = schemaApiKey.safeParse(req.body);
|
||||
const safe = schemaApiKeyBodyParams.safeParse(req.body);
|
||||
if (safe.success) {
|
||||
const data = await prisma.apiKey
|
||||
.create({ data: safe.data })
|
||||
if (data) res.status(201).json({ data })
|
||||
else (error: unknown) => res.status(400).json({ error: { message: "Could not create apiKey type", error: error } });
|
||||
const data = await prisma.apiKey.create({ data: safe.data });
|
||||
if (data) res.status(201).json({ data });
|
||||
else
|
||||
(error: unknown) => res.status(400).json({ error: { message: "Could not create apiKey type", error } });
|
||||
}
|
||||
}
|
||||
|
||||
export default withMiddleware("addRequestId","postOnly")(
|
||||
withValidApiKey(
|
||||
createApiKey
|
||||
)
|
||||
);
|
||||
export default withMiddleware("addRequestId", "HTTP_POST")(withValidApiKey(createApiKey));
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,11 @@ export async function attendee(req: NextApiRequest, res: NextApiResponse<Respons
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const attendee = await prisma.attendee
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const attendee = await prisma.attendee.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the attendee type from the database if there's an existing resource.
|
||||
if (attendee) res.status(200).json({ message: `attendee with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.attendee.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAttendee, withValidAttendee } from "@lib/validations/attendee";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Attendee;
|
||||
@@ -18,16 +21,21 @@ export async function editAttendee(req: NextApiRequest, res: NextApiResponse<Res
|
||||
const safeBody = await schemaAttendee.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
await prisma.attendee.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(attendee => {
|
||||
res.status(200).json({ data: attendee });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
});
|
||||
await prisma.attendee
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((attendee) => {
|
||||
res.status(200).json({ data: attendee });
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating attendees" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating attendees" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidAttendee(editAttendee));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Attendee;
|
||||
@@ -14,7 +17,7 @@ type ResponseData = {
|
||||
export async function attendee(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
|
||||
if (method === "GET" && safe.success) {
|
||||
const attendee = await prisma.attendee.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Attendee[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Attendee } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAttendee, withValidAttendee } from "@lib/validations/attendee";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -14,13 +14,13 @@ type ResponseData = {
|
||||
async function createAttendee(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { body, method } = req;
|
||||
const safe = schemaAttendee.safeParse(body);
|
||||
|
||||
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.attendee
|
||||
.create({ data: safe.data })
|
||||
.then((attendee) => res.status(201).json({ data: attendee }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create attendee type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.attendee
|
||||
.create({ data: safe.data })
|
||||
.then((attendee) => res.status(201).json({ data: attendee }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create attendee type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -13,12 +16,12 @@ export async function availability(req: NextApiRequest, res: NextApiResponse<Res
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const availability = await prisma.availability
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const availability = await prisma.availability.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the availability type from the database if there's an existing resource.
|
||||
if (availability) res.status(200).json({ message: `availability with id: ${safe.data.id} deleted successfully` });
|
||||
if (availability)
|
||||
res.status(200).json({ message: `availability with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.availability.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaAvailability, withValidAvailability,} from "@lib/validations/availability";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAvailability, withValidAvailability } from "@lib/validations/availability";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Availability;
|
||||
@@ -18,16 +21,21 @@ export async function editAvailability(req: NextApiRequest, res: NextApiResponse
|
||||
const safeBody = await schemaAvailability.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
await prisma.availability.update({
|
||||
await prisma.availability
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(availability => {
|
||||
})
|
||||
.then((availability) => {
|
||||
res.status(200).json({ data: availability });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
// Reject any other HTTP method than PATCH
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating availabilities" });
|
||||
// Reject any other HTTP method than PATCH
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating availabilities" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidAvailability(editAvailability));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Availability;
|
||||
@@ -14,7 +17,7 @@ type ResponseData = {
|
||||
export async function availability(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
|
||||
if (method === "GET" && safe.success) {
|
||||
const availability = await prisma.availability.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
@@ -24,5 +27,4 @@ export async function availability(req: NextApiRequest, res: NextApiResponse<Res
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(availability);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Availability[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaAvailability, withValidAvailability } from "@lib/validations/availability";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -19,7 +19,9 @@ async function createAvailability(req: NextApiRequest, res: NextApiResponse<Resp
|
||||
await prisma.availability
|
||||
.create({ data: safe.data })
|
||||
.then((availability) => res.status(201).json({ data: availability }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create availability type", error: error }));
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create availability type", error: error })
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteBookingReference(req: NextApiRequest, res: NextApiRe
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const bookingReference = await prisma.bookingReference
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const bookingReference = await prisma.bookingReference.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the bookingReference type from the database if there's an existing resource.
|
||||
if (bookingReference) res.status(200).json({ message: `bookingReference with id: ${safe.data.id} deleted successfully` });
|
||||
if (bookingReference)
|
||||
res.status(200).json({ message: `bookingReference with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.bookingReference.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBookingReference, withValidBookingReference } from "@lib/validations/booking-reference";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: BookingReference;
|
||||
@@ -18,15 +21,18 @@ export async function editBookingReference(req: NextApiRequest, res: NextApiResp
|
||||
const safeBody = await schemaBookingReference.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.bookingReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.bookingReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated` })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated` });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating bookingReferences" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating bookingReferences" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidBookingReference(editBookingReference));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: BookingReference;
|
||||
@@ -23,5 +26,4 @@ export async function bookingReference(req: NextApiRequest, res: NextApiResponse
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(bookingReference);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: BookingReference[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingReference } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBookingReference, withValidBookingReference } from "@lib/validations/booking-reference";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,13 @@ async function createBookingReference(req: NextApiRequest, res: NextApiResponse<
|
||||
const { body, method } = req;
|
||||
const safe = schemaBookingReference.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.bookingReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create bookingReference type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.bookingReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create bookingReference type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,14 +16,14 @@ export async function deleteBooking(req: NextApiRequest, res: NextApiResponse<Re
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const booking = await prisma.booking
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const booking = await prisma.booking.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the booking type from the database if there's an existing resource.
|
||||
if (booking) res.status(200).json({ message: `booking with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.booking.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
} else
|
||||
res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(deleteBooking);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBooking, withValidBooking } from "@lib/validations/booking";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Booking;
|
||||
@@ -19,18 +22,23 @@ export async function editBooking(req: NextApiRequest, res: NextApiResponse<Resp
|
||||
|
||||
if (method === "PATCH") {
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
await prisma.booking.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(booking => {
|
||||
res.status(200).json({ data: booking });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
});
|
||||
await prisma.booking
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((booking) => {
|
||||
res.status(200).json({ data: booking });
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating bookings" });
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating bookings" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Booking;
|
||||
@@ -26,5 +29,4 @@ export async function booking(req: NextApiRequest, res: NextApiResponse<Response
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(booking);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Booking[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaBooking, withValidBooking } from "@lib/validations/booking";
|
||||
|
||||
type ResponseData = {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteCredential(req: NextApiRequest, res: NextApiResponse
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const credential = await prisma.credential
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const credential = await prisma.credential.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the credential type from the database if there's an existing resource.
|
||||
if (credential) res.status(200).json({ message: `credential with id: ${safe.data.id} deleted successfully` });
|
||||
if (credential)
|
||||
res.status(200).json({ message: `credential with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.credential.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaCredential, withValidCredential } from "@lib/validations/credential";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Credential;
|
||||
@@ -18,15 +21,18 @@ export async function editCredential(req: NextApiRequest, res: NextApiResponse<R
|
||||
const safeBody = await schemaCredential.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.credential.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.credential.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating credentials" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating credentials" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidCredential(editCredential));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Credential;
|
||||
@@ -23,5 +26,4 @@ export async function credential(req: NextApiRequest, res: NextApiResponse<Respo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(credential);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Credential[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Credential } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaCredential, withValidCredential } from "@lib/validations/credential";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,11 @@ async function createCredential(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
const { body, method } = req;
|
||||
const safe = schemaCredential.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.credential
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create credential type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.credential
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create credential type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,19 +16,17 @@ type ResponseData = {
|
||||
export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const deletedDailyEventReference = await prisma.dailyEventReference
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const deletedDailyEventReference = await prisma.dailyEventReference.delete({
|
||||
where: { id: safe.data.id },
|
||||
});
|
||||
// We only remove the dailyEventReference type from the database if there's an existing resource.
|
||||
if (deletedDailyEventReference) res.status(200).json({ message: `dailyEventReference with id: ${safe.data.id} deleted successfully` });
|
||||
if (deletedDailyEventReference)
|
||||
res.status(200).json({ message: `dailyEventReference with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.dailyEventReference.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
// export default withValidQueryIdTransformParseInt(deleteDailyEventReference);
|
||||
export default withMiddleware("deleteOnly")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
deleteDailyEventReference
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteDailyEventReference));
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDailyEventReference, withValidDailyEventReference } from "@lib/validations/daily-event-reference";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDailyEventReference,
|
||||
withValidDailyEventReference,
|
||||
} from "@lib/validations/daily-event-reference";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference;
|
||||
@@ -18,15 +24,18 @@ export async function editDailyEventReference(req: NextApiRequest, res: NextApiR
|
||||
const safeBody = await schemaDailyEventReference.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.dailyEventReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.dailyEventReference.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating dailyEventReferences" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating dailyEventReferences" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidDailyEventReference(editDailyEventReference));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference;
|
||||
@@ -23,5 +26,4 @@ export async function dailyEventReference(req: NextApiRequest, res: NextApiRespo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(dailyEventReference);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDailyEventReference, withValidDailyEventReference } from "@lib/validations/daily-event-reference";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DailyEventReference } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDailyEventReference,
|
||||
withValidDailyEventReference,
|
||||
} from "@lib/validations/daily-event-reference";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DailyEventReference;
|
||||
@@ -15,11 +18,13 @@ async function createDailyEventReference(req: NextApiRequest, res: NextApiRespon
|
||||
const { body, method } = req;
|
||||
const safe = schemaDailyEventReference.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.dailyEventReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create dailyEventReference type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.dailyEventReference
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create dailyEventReference type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteDestinationCalendar(req: NextApiRequest, res: NextAp
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const destinationCalendar = await prisma.destinationCalendar
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const destinationCalendar = await prisma.destinationCalendar.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the destinationCalendar type from the database if there's an existing resource.
|
||||
if (destinationCalendar) res.status(200).json({ message: `destinationCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
if (destinationCalendar)
|
||||
res.status(200).json({ message: `destinationCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.destinationCalendar.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDestinationCalendar, withValidDestinationCalendar } from "@lib/validations/destination-calendar";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDestinationCalendar,
|
||||
withValidDestinationCalendar,
|
||||
} from "@lib/validations/destination-calendar";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar;
|
||||
@@ -18,15 +24,18 @@ export async function editDestinationCalendar(req: NextApiRequest, res: NextApiR
|
||||
const safeBody = await schemaDestinationCalendar.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.destinationCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.destinationCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating destinationCalendars" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating destinationCalendars" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidDestinationCalendar(editDestinationCalendar));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar;
|
||||
@@ -23,5 +26,4 @@ export async function destinationCalendar(req: NextApiRequest, res: NextApiRespo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(destinationCalendar);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaDestinationCalendar, withValidDestinationCalendar } from "@lib/validations/destination-calendar";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaDestinationCalendar,
|
||||
withValidDestinationCalendar,
|
||||
} from "@lib/validations/destination-calendar";
|
||||
|
||||
type ResponseData = {
|
||||
data?: DestinationCalendar;
|
||||
@@ -15,11 +18,13 @@ async function createDestinationCalendar(req: NextApiRequest, res: NextApiRespon
|
||||
const { body, method } = req;
|
||||
const safe = schemaDestinationCalendar.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.destinationCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create destinationCalendar type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.destinationCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create destinationCalendar type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteEventTypeCustomInput(req: NextApiRequest, res: NextA
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const eventTypeCustomInput = await prisma.eventTypeCustomInput
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const eventTypeCustomInput = await prisma.eventTypeCustomInput.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the eventTypeCustomInput type from the database if there's an existing resource.
|
||||
if (eventTypeCustomInput) res.status(200).json({ message: `eventTypeCustomInput with id: ${safe.data.id} deleted successfully` });
|
||||
if (eventTypeCustomInput)
|
||||
res.status(200).json({ message: `eventTypeCustomInput with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.eventTypeCustomInput.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaEventTypeCustomInput, withValidEventTypeCustomInput } from "@lib/validations/eventTypeCustomInput";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaEventTypeCustomInput,
|
||||
withValidEventTypeCustomInput,
|
||||
} from "@lib/validations/eventTypeCustomInput";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput;
|
||||
@@ -18,15 +24,18 @@ export async function editEventTypeCustomInput(req: NextApiRequest, res: NextApi
|
||||
const safeBody = await schemaEventTypeCustomInput.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.eventTypeCustomInput.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.eventTypeCustomInput.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating eventTypeCustomInputs" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating eventTypeCustomInputs" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidEventTypeCustomInput(editEventTypeCustomInput));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput;
|
||||
@@ -23,5 +26,4 @@ export async function eventTypeCustomInput(req: NextApiRequest, res: NextApiResp
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(eventTypeCustomInput);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaEventTypeCustomInput, withValidEventTypeCustomInput } from "@lib/validations/eventTypeCustomInput";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventTypeCustomInput } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaEventTypeCustomInput,
|
||||
withValidEventTypeCustomInput,
|
||||
} from "@lib/validations/eventTypeCustomInput";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventTypeCustomInput;
|
||||
@@ -15,11 +18,13 @@ async function createEventTypeCustomInput(req: NextApiRequest, res: NextApiRespo
|
||||
const { body, method } = req;
|
||||
const safe = schemaEventTypeCustomInput.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.eventTypeCustomInput
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create eventTypeCustomInput type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.eventTypeCustomInput
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create eventTypeCustomInput type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,14 +16,15 @@ export async function deleteEventType(req: NextApiRequest, res: NextApiResponse<
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const eventType = await prisma.eventType
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const eventType = await prisma.eventType.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the eventType type from the database if there's an existing resource.
|
||||
if (eventType) res.status(200).json({ message: `eventType with id: ${safe.data.id} deleted successfully` });
|
||||
if (eventType)
|
||||
res.status(200).json({ message: `eventType with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.eventType.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
} else
|
||||
res.status(405).json({ message: "Only DELETE Method allowed in /availabilities/[id]/delete endpoint" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(deleteEventType);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaEventType, withValidEventType } from "@lib/validations/eventType";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventType;
|
||||
@@ -19,18 +22,23 @@ export async function editEventType(req: NextApiRequest, res: NextApiResponse<Re
|
||||
|
||||
if (method === "PATCH") {
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
await prisma.eventType.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
}).then(event => {
|
||||
res.status(200).json({ data: event });
|
||||
}).catch(error => {
|
||||
res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
});
|
||||
await prisma.eventType
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((event) => {
|
||||
res.status(200).json({ data: event });
|
||||
})
|
||||
.catch((error) => {
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating event-types" });
|
||||
res.status(405).json({ message: "Only PATCH Method allowed for updating event-types" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventType;
|
||||
@@ -26,5 +29,4 @@ export async function eventType(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(eventType);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: EventType[];
|
||||
message?: string;
|
||||
@@ -15,7 +15,7 @@ export default async function eventType(req: NextApiRequest, res: NextApiRespons
|
||||
const data = await prisma.eventType.findMany();
|
||||
res.status(200).json({ data });
|
||||
} else {
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
// Reject any other HTTP method than POST
|
||||
res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaEventType, withValidEventType } from "@lib/validations/eventType";
|
||||
|
||||
type ResponseData = {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteMembership(req: NextApiRequest, res: NextApiResponse
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const membership = await prisma.membership
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const membership = await prisma.membership.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the membership type from the database if there's an existing resource.
|
||||
if (membership) res.status(200).json({ message: `membership with id: ${safe.data.id} deleted successfully` });
|
||||
if (membership)
|
||||
res.status(200).json({ message: `membership with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.membership.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaMembership, withValidMembership } from "@lib/validations/membership";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Membership;
|
||||
@@ -18,15 +21,18 @@ export async function editMembership(req: NextApiRequest, res: NextApiResponse<R
|
||||
const safeBody = await schemaMembership.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.membership.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.membership.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating memberships" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating memberships" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidMembership(editMembership));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Membership;
|
||||
@@ -23,5 +26,4 @@ export async function membership(req: NextApiRequest, res: NextApiResponse<Respo
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(membership);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Membership[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Membership } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaMembership, withValidMembership } from "@lib/validations/membership";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,11 @@ async function createMembership(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
const { body, method } = req;
|
||||
const safe = schemaMembership.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.membership
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create membership type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.membership
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create membership type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,11 @@ export async function deleteSchedule(req: NextApiRequest, res: NextApiResponse<R
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const schedule = await prisma.schedule
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const schedule = await prisma.schedule.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the schedule type from the database if there's an existing resource.
|
||||
if (schedule) res.status(200).json({ message: `schedule with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.schedule.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSchedule, withValidSchedule } from "@lib/validations/schedule";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Schedule;
|
||||
@@ -18,15 +21,18 @@ export async function editSchedule(req: NextApiRequest, res: NextApiResponse<Res
|
||||
const safeBody = await schemaSchedule.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.schedule.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.schedule.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating schedules" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating schedules" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidSchedule(editSchedule));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Schedule;
|
||||
@@ -23,5 +26,4 @@ export async function schedule(req: NextApiRequest, res: NextApiResponse<Respons
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(schedule);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Schedule[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Schedule } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSchedule, withValidSchedule } from "@lib/validations/schedule";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,11 @@ async function createSchedule(req: NextApiRequest, res: NextApiResponse<Response
|
||||
const { body, method } = req;
|
||||
const safe = schemaSchedule.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.schedule
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create schedule type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.schedule
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create schedule type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
@@ -14,12 +16,12 @@ export async function deleteSelectedCalendar(req: NextApiRequest, res: NextApiRe
|
||||
const { query, method } = req;
|
||||
const safe = await schemaQueryIdParseInt.safeParse(query);
|
||||
if (method === "DELETE" && safe.success && safe.data) {
|
||||
const selectedCalendar = await prisma.selectedCalendar
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
const selectedCalendar = await prisma.selectedCalendar.delete({ where: { id: safe.data.id } });
|
||||
// We only remove the selectedCalendar type from the database if there's an existing resource.
|
||||
if (selectedCalendar) res.status(200).json({ message: `selectedCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
if (selectedCalendar)
|
||||
res.status(200).json({ message: `selectedCalendar with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.selectedCalendar.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found`});
|
||||
else res.status(400).json({ message: `Resource with id:${safe.data.id} was not found` });
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only DELETE Method allowed" });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSelectedCalendar, withValidSelectedCalendar } from "@lib/validations/selected-calendar";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: SelectedCalendar;
|
||||
@@ -18,15 +21,18 @@ export async function editSelectedCalendar(req: NextApiRequest, res: NextApiResp
|
||||
const safeBody = await schemaSelectedCalendar.safeParse(body);
|
||||
|
||||
if (method === "PATCH" && safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.selectedCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
const data = await prisma.selectedCalendar.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
else
|
||||
res
|
||||
.status(404)
|
||||
.json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error });
|
||||
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating selectedCalendars" });
|
||||
} else res.status(405).json({ message: "Only PATCH Method allowed for updating selectedCalendars" });
|
||||
}
|
||||
|
||||
export default withValidQueryIdTransformParseInt(withValidSelectedCalendar(editSelectedCalendar));
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: SelectedCalendar;
|
||||
@@ -23,5 +26,4 @@ export async function selectedCalendar(req: NextApiRequest, res: NextApiResponse
|
||||
} else res.status(405).json({ message: "Only GET Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
export default withValidQueryIdTransformParseInt(selectedCalendar);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
type ResponseData = {
|
||||
data?: SelectedCalendar[];
|
||||
error?: unknown;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SelectedCalendar } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaSelectedCalendar, withValidSelectedCalendar } from "@lib/validations/selected-calendar";
|
||||
|
||||
type ResponseData = {
|
||||
@@ -15,11 +15,13 @@ async function createSelectedCalendar(req: NextApiRequest, res: NextApiResponse<
|
||||
const { body, method } = req;
|
||||
const safe = schemaSelectedCalendar.safeParse(body);
|
||||
if (method === "POST" && safe.success) {
|
||||
await prisma.selectedCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) => res.status(400).json({ message: "Could not create selectedCalendar type", error: error }));
|
||||
// Reject any other HTTP method than POST
|
||||
await prisma.selectedCalendar
|
||||
.create({ data: safe.data })
|
||||
.then((data) => res.status(201).json({ data }))
|
||||
.catch((error) =>
|
||||
res.status(400).json({ message: "Could not create selectedCalendar type", error: error })
|
||||
);
|
||||
// Reject any other HTTP method than POST
|
||||
} else res.status(405).json({ error: "Only POST Method allowed" });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
message: string;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
export async function deleteTeam(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.team
|
||||
.delete({ where: { id: safe.data.id } })
|
||||
// We only remove the team type from the database if there's an existing resource.
|
||||
if (data) res.status(200).json({ message: `Team with id: ${safe.data.id} deleted successfully` });
|
||||
// This catches the error thrown by prisma.team.delete() if the resource is not found.
|
||||
else res.status(400).json({ message: `Team with id: ${safe.data.id} was not able to be processed` });
|
||||
}
|
||||
if (!safe.success) throw new Error("Invalid request query");
|
||||
|
||||
const data = await prisma.team.delete({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ message: `Team with id: ${safe.data.id} deleted successfully` });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: `Team with id: ${safe.data.id} was not able to be processed`,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("deleteOnly", "addRequestId")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
deleteTeam
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_DELETE", "addRequestId")(withValidQueryIdTransformParseInt(deleteTeam));
|
||||
|
||||
@@ -1,36 +1,41 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaTeam, withValidTeam } from "@lib/validations/team";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { schemaTeam, withValidTeam } from "@lib/validations/team";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Team;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
export async function editTeam(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const { query, body, method } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaTeam.safeParse(body);
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safeBody = await schemaTeam.safeParse(req.body);
|
||||
|
||||
if (safeQuery.success && safeBody.success) {
|
||||
const data = await prisma.team.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
if (data) res.status(200).json({ data });
|
||||
else (error: unknown) => res.status(404).json({ message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`, error })
|
||||
}
|
||||
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
|
||||
const data = await prisma.team.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
});
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: `Event type with ID ${safeQuery.data.id} not found and wasn't updated`,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("patchOnly","addRequestId")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
withValidTeam(
|
||||
editTeam)
|
||||
)
|
||||
);
|
||||
export default withMiddleware(
|
||||
"HTTP_PATCH",
|
||||
"addRequestId"
|
||||
)(withValidQueryIdTransformParseInt(withValidTeam(editTeam)));
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
type ResponseData = {
|
||||
data?: Team;
|
||||
message?: string;
|
||||
error?: unknown;
|
||||
error?: object;
|
||||
};
|
||||
|
||||
export async function teamById(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (safe.success) {
|
||||
const data = await prisma.team.findUnique({ where: { id: safe.data.id } });
|
||||
if (!safe.success) throw new Error("Invalid request query");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else res.status(404).json({ message: "Team was not found" });
|
||||
}
|
||||
const data = await prisma.team.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "Team was not found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export default withMiddleware("addRequestId","getOnly")(
|
||||
withValidQueryIdTransformParseInt(
|
||||
teamById
|
||||
)
|
||||
);
|
||||
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(teamById));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user