feat: yarn build no errors

This commit is contained in:
Agusti Fernandez Pardo committed 2022-04-02 01:55:41 +02:00
1 parent 1c19032884
commit 9f4a62e2ef
25 files changed
+786 -322

No files matched your search

-2
View File
@@ -3,8 +3,6 @@
// Initially to test out 0,5 cent per booking via API call
// withCost(5)(endpoint)
// Should add a charge of 0.5 cent per booking to the subscription of the user making the request
// Should be called in the middleware of the e
//
import { NextMiddleware } from "next-api-middleware";
export const withCost = (priceInCents: number): NextMiddleware => {
+9
View File
@@ -5,6 +5,7 @@ import {
Credential,
SelectedCalendar,
EventType,
EventTypeCustomInput,
Attendee,
Availability,
BookingReference,
@@ -120,6 +121,14 @@ export type MembershipsResponse = BaseResponse & {
data?: Partial<Membership>[];
};
// EventTypeCustomInput
export type EventTypeCustomInputResponse = BaseResponse & {
data?: Partial<EventTypeCustomInput>;
};
export type EventTypeCustomInputsResponse = BaseResponse & {
data?: Partial<EventTypeCustomInput>[];
};
// EventType
export type EventTypeResponse = BaseResponse & {
data?: Partial<EventType>;
@@ -0,0 +1,29 @@
import { withValidation } from "next-validations";
import { z } from "zod";
import { EventTypeModel, _EventTypeCustomInputModel as EventTypeCustomInput } from "@calcom/prisma/zod";
export const schemaEventTypeCustomInputBaseBodyParams = EventTypeCustomInput.omit({
id: true,
eventTypeId: true,
}).partial();
export const schemaEventTypeCustomInputPublic = EventTypeCustomInput.omit({});
const schemaEventTypeCustomInputRequiredParams = z.object({
label: z.string(),
// uid: z.string(),
eventType: EventTypeModel.optional(),
// eventType: z.instanceof(EventTypeInputModel),
});
export const schemaEventTypeCustomInputBodyParams = schemaEventTypeCustomInputBaseBodyParams.merge(
schemaEventTypeCustomInputRequiredParams
);
export const withValidEventTypeCustomInput = withValidation({
schema: schemaEventTypeCustomInputBodyParams,
type: "Zod",
mode: "body",
});
+11 -1
View File
@@ -1,8 +1,18 @@
import { withValidation } from "next-validations";
import { z } from "zod";
import { _ScheduleModel as Schedule } from "@calcom/prisma/zod";
export const schemaScheduleBodyParams = Schedule.omit({ id: true }).partial();
// import { jsonSchema } from "./shared/jsonSchema";
const schemaScheduleBaseBodyParams = Schedule.omit({ id: true }).partial();
const schemaScheduleRequiredParams = z.object({
userId: z.number(),
name: z.string(),
});
export const schemaScheduleBodyParams = schemaScheduleBaseBodyParams.merge(schemaScheduleRequiredParams);
export const schemaSchedulePublic = Schedule.omit({});
+21 -3
View File
@@ -1,10 +1,28 @@
import { withValidation } from "next-validations";
import { z } from "zod";
import { _SelectedCalendarModel as SelectedCalendar } from "@calcom/prisma/zod";
import { _UserModel, _SelectedCalendarModel as SelectedCalendar } from "@calcom/prisma/zod";
export const schemaSelectedCalendarBodyParams = SelectedCalendar.omit({}).partial();
export const schemaSelectedCalendarBaseBodyParams = SelectedCalendar.omit({ userId: true }).partial();
export const schemaSelectedCalendarPublic = SelectedCalendar.omit({ userId: true });
export const schemaSelectedCalendarPublic = SelectedCalendar.omit({});
const schemaSelectedCalendarRequiredParams = z.object({
externalId: z.string(),
integration: z.string(),
user: z.object({
connect: z.object({
id: z.number().optional(),
username: z.string().optional(),
email: z.string().optional(),
}),
create: z.any(),
}),
});
export const schemaSelectedCalendarBodyParams = schemaSelectedCalendarBaseBodyParams.merge(
schemaSelectedCalendarRequiredParams
);
export const withValidSelectedCalendar = withValidation({
schema: schemaSelectedCalendarBodyParams,
+37 -18
View File
@@ -3,30 +3,49 @@ import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BaseResponse } from "@lib/types";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
message?: string;
error?: unknown;
};
export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
/**
* @swagger
* /api/daily-event-references/{id}/delete:
* delete:
* summary: Remove an existing dailyEventReference
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the dailyEventReference to delete
* tags:
* - dailyEventReferences
* responses:
* 201:
* description: OK, dailyEventReference removed successfuly
* model: DailyEventReference
* 400:
* description: Bad request. DailyEventReference id is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function deleteDailyEventReference(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (safe.success) {
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` });
// 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` });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only DELETE Method allowed" });
if (!safe.success) throw new Error("Invalid request query", safe.error);
const data = await prisma.dailyEventReference.delete({ where: { id: safe.data.id } });
if (data)
res.status(200).json({ message: `DailyEventReference with id: ${safe.data.id} deleted successfully` });
else
(error: Error) =>
res.status(400).json({
message: `DailyEventReference with id: ${safe.data.id} was not able to be processed`,
error,
});
}
// export default withValidQueryIdTransformParseInt(deleteDailyEventReference);
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteDailyEventReference));
+49 -25
View File
@@ -1,10 +1,12 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DailyEventReference } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DailyEventReferenceResponse } from "@lib/types";
import {
schemaDailyEventReference,
schemaDailyEventReferenceBodyParams,
schemaDailyEventReferencePublic,
withValidDailyEventReference,
} from "@lib/validations/daily-event-reference";
import {
@@ -12,30 +14,52 @@ import {
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
data?: DailyEventReference;
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/daily-event-references/{id}/edit:
* patch:
* summary: Edit an existing dailyEventReference
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the dailyEventReference to edit
* tags:
* - dailyEventReferences
* responses:
* 201:
* description: OK, dailyEventReference edited successfuly
* model: DailyEventReference
* 400:
* description: Bad request. DailyEventReference body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function editDailyEventReference(
req: NextApiRequest,
res: NextApiResponse<DailyEventReferenceResponse>
) {
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
const safeBody = await schemaDailyEventReferenceBodyParams.safeParse(req.body);
export async function editDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const { query, body, method } = req;
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
const safeBody = await schemaDailyEventReference.safeParse(body);
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
const dailyEventReference = await prisma.dailyEventReference.update({
where: { id: safeQuery.data.id },
data: safeBody.data,
});
const data = schemaDailyEventReferencePublic.parse(dailyEventReference);
if (method === "PATCH" && safeQuery.success && safeBody.success) {
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 });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only PATCH Method allowed for updating dailyEventReferences" });
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 withValidQueryIdTransformParseInt(withValidDailyEventReference(editDailyEventReference));
export default withMiddleware("HTTP_PATCH")(
withValidQueryIdTransformParseInt(withValidDailyEventReference(editDailyEventReference))
);
+41 -16
View File
@@ -1,29 +1,54 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DailyEventReference } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DailyEventReferenceResponse } from "@lib/types";
import { schemaDailyEventReferencePublic } from "@lib/validations/daily-event-reference";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
data?: DailyEventReference;
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/daily-event-references/{id}:
* get:
* summary: Get a dailyEventReference by ID
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the dailyEventReference to get
* tags:
* - dailyEventReferences
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: DailyEventReference was not found
*/
export async function dailyEventReferenceById(
req: NextApiRequest,
res: NextApiResponse<DailyEventReferenceResponse>
) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query");
export async function dailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const { query, method } = req;
const safe = await schemaQueryIdParseInt.safeParse(query);
if (method === "GET" && safe.success) {
const data = await prisma.dailyEventReference.findUnique({ where: { id: safe.data.id } });
const dailyEventReference = await prisma.dailyEventReference.findUnique({ where: { id: safe.data.id } });
const data = schemaDailyEventReferencePublic.parse(dailyEventReference);
if (data) res.status(200).json({ data });
else res.status(404).json({ message: "Event type not found" });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only GET Method allowed" });
if (dailyEventReference) res.status(200).json({ data });
else
(error: Error) =>
res.status(404).json({
message: "DailyEventReference was not found",
error,
});
}
export default withValidQueryIdTransformParseInt(dailyEventReference);
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(dailyEventReferenceById));
+35 -8
View File
@@ -1,15 +1,42 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DailyEventReference } from "@calcom/prisma/client";
type ResponseData = {
data?: DailyEventReference[];
error?: unknown;
};
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DailyEventReferencesResponse } from "@lib/types";
import { schemaDailyEventReferencePublic } from "@lib/validations/daily-event-reference";
/**
* @swagger
* /api/daily-event-references:
* get:
* summary: Get all dailyEventReferences
* tags:
* - dailyEventReferences
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No dailyEventReferences were found
*/
async function allDailyEventReferences(
_: NextApiRequest,
res: NextApiResponse<DailyEventReferencesResponse>
) {
const dailyEventReferences = await prisma.dailyEventReference.findMany();
const data = dailyEventReferences.map((dailyEventReference) =>
schemaDailyEventReferencePublic.parse(dailyEventReference)
);
export default async function dailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const data = await prisma.dailyEventReference.findMany();
if (data) res.status(200).json({ data });
else res.status(400).json({ error: "No data found" });
else
(error: Error) =>
res.status(404).json({
message: "No DailyEventReferences were found",
error,
});
}
export default withMiddleware("HTTP_GET")(allDailyEventReferences);
+44 -20
View File
@@ -1,31 +1,55 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DailyEventReference } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DailyEventReferenceResponse } from "@lib/types";
import {
schemaDailyEventReference,
schemaDailyEventReferenceBodyParams,
schemaDailyEventReferencePublic,
withValidDailyEventReference,
} from "@lib/validations/daily-event-reference";
type ResponseData = {
data?: DailyEventReference;
message?: string;
error?: string;
};
/**
* @swagger
* /api/daily-event-references/new:
* post:
* summary: Creates a new dailyEventReference
* requestBody:
* description: Optional description in *Markdown*
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/DailyEventReference'
* tags:
* - dailyEventReferences
* responses:
* 201:
* description: OK, dailyEventReference created
* model: DailyEventReference
* 400:
* description: Bad request. DailyEventReference body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
async function createDailyEventReference(
req: NextApiRequest,
res: NextApiResponse<DailyEventReferenceResponse>
) {
const safe = schemaDailyEventReferenceBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body", safe.error);
async function createDailyEventReference(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
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
} else res.status(405).json({ error: "Only POST Method allowed" });
const dailyEventReference = await prisma.dailyEventReference.create({ data: safe.data });
const data = schemaDailyEventReferencePublic.parse(dailyEventReference);
if (data) res.status(201).json({ data, message: "DailyEventReference created successfully" });
else
(error: Error) =>
res.status(400).json({
message: "Could not create new dailyEventReference",
error,
});
}
export default withValidDailyEventReference(createDailyEventReference);
export default withMiddleware("HTTP_POST")(withValidDailyEventReference(createDailyEventReference));
+39 -17
View File
@@ -2,28 +2,50 @@ import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BaseResponse } from "@lib/types";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/destination-calendars/{id}/delete:
* delete:
* summary: Remove an existing destinationCalendar
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the destinationCalendar to delete
* tags:
* - destinationCalendars
* responses:
* 201:
* description: OK, destinationCalendar removed successfuly
* model: DestinationCalendar
* 400:
* description: Bad request. DestinationCalendar id is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function deleteDestinationCalendar(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query", safe.error);
export async function deleteDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
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 } });
// 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` });
// 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` });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only DELETE Method allowed" });
const data = await prisma.destinationCalendar.delete({ where: { id: safe.data.id } });
if (data)
res.status(200).json({ message: `DestinationCalendar with id: ${safe.data.id} deleted successfully` });
else
(error: Error) =>
res.status(400).json({
message: `DestinationCalendar with id: ${safe.data.id} was not able to be processed`,
error,
});
}
export default withValidQueryIdTransformParseInt(deleteDestinationCalendar);
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteDestinationCalendar));
+49 -25
View File
@@ -1,10 +1,12 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DestinationCalendar } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DestinationCalendarResponse } from "@lib/types";
import {
schemaDestinationCalendar,
schemaDestinationCalendarBodyParams,
schemaDestinationCalendarPublic,
withValidDestinationCalendar,
} from "@lib/validations/destination-calendar";
import {
@@ -12,30 +14,52 @@ import {
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
data?: DestinationCalendar;
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/destination-calendars/{id}/edit:
* patch:
* summary: Edit an existing destinationCalendar
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the destinationCalendar to edit
* tags:
* - destinationCalendars
* responses:
* 201:
* description: OK, destinationCalendar edited successfuly
* model: DestinationCalendar
* 400:
* description: Bad request. DestinationCalendar body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function editDestinationCalendar(
req: NextApiRequest,
res: NextApiResponse<DestinationCalendarResponse>
) {
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
const safeBody = await schemaDestinationCalendarBodyParams.safeParse(req.body);
export async function editDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const { query, body, method } = req;
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
const safeBody = await schemaDestinationCalendar.safeParse(body);
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
const destinationCalendar = await prisma.destinationCalendar.update({
where: { id: safeQuery.data.id },
data: safeBody.data,
});
const data = schemaDestinationCalendarPublic.parse(destinationCalendar);
if (method === "PATCH" && safeQuery.success && safeBody.success) {
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 });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only PATCH Method allowed for updating destinationCalendars" });
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 withValidQueryIdTransformParseInt(withValidDestinationCalendar(editDestinationCalendar));
export default withMiddleware("HTTP_PATCH")(
withValidQueryIdTransformParseInt(withValidDestinationCalendar(editDestinationCalendar))
);
+41 -16
View File
@@ -1,29 +1,54 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DestinationCalendar } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DestinationCalendarResponse } from "@lib/types";
import { schemaDestinationCalendarPublic } from "@lib/validations/destination-calendar";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
data?: DestinationCalendar;
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/destination-calendars/{id}:
* get:
* summary: Get a destinationCalendar by ID
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the destinationCalendar to get
* tags:
* - destinationCalendars
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: DestinationCalendar was not found
*/
export async function destinationCalendarById(
req: NextApiRequest,
res: NextApiResponse<DestinationCalendarResponse>
) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query");
export async function destinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const { query, method } = req;
const safe = await schemaQueryIdParseInt.safeParse(query);
if (method === "GET" && safe.success) {
const data = await prisma.destinationCalendar.findUnique({ where: { id: safe.data.id } });
const destinationCalendar = await prisma.destinationCalendar.findUnique({ where: { id: safe.data.id } });
const data = schemaDestinationCalendarPublic.parse(destinationCalendar);
if (data) res.status(200).json({ data });
else res.status(404).json({ message: "Event type not found" });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only GET Method allowed" });
if (destinationCalendar) res.status(200).json({ data });
else
(error: Error) =>
res.status(404).json({
message: "DestinationCalendar was not found",
error,
});
}
export default withValidQueryIdTransformParseInt(destinationCalendar);
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(destinationCalendarById));
+35 -8
View File
@@ -1,15 +1,42 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DestinationCalendar } from "@calcom/prisma/client";
type ResponseData = {
data?: DestinationCalendar[];
error?: unknown;
};
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DestinationCalendarsResponse } from "@lib/types";
import { schemaDestinationCalendarPublic } from "@lib/validations/destination-calendar";
/**
* @swagger
* /api/destination-calendars:
* get:
* summary: Get all destinationCalendars
* tags:
* - destinationCalendars
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No destinationCalendars were found
*/
async function allDestinationCalendars(
_: NextApiRequest,
res: NextApiResponse<DestinationCalendarsResponse>
) {
const destinationCalendars = await prisma.destinationCalendar.findMany();
const data = destinationCalendars.map((destinationCalendar) =>
schemaDestinationCalendarPublic.parse(destinationCalendar)
);
export default async function destinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const data = await prisma.destinationCalendar.findMany();
if (data) res.status(200).json({ data });
else res.status(400).json({ error: "No data found" });
else
(error: Error) =>
res.status(404).json({
message: "No DestinationCalendars were found",
error,
});
}
export default withMiddleware("HTTP_GET")(allDestinationCalendars);
+44 -20
View File
@@ -1,31 +1,55 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { DestinationCalendar } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DestinationCalendarResponse } from "@lib/types";
import {
schemaDestinationCalendar,
schemaDestinationCalendarBodyParams,
schemaDestinationCalendarPublic,
withValidDestinationCalendar,
} from "@lib/validations/destination-calendar";
type ResponseData = {
data?: DestinationCalendar;
message?: string;
error?: string;
};
/**
* @swagger
* /api/destination-calendars/new:
* post:
* summary: Creates a new destinationCalendar
* requestBody:
* description: Optional description in *Markdown*
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/DestinationCalendar'
* tags:
* - destinationCalendars
* responses:
* 201:
* description: OK, destinationCalendar created
* model: DestinationCalendar
* 400:
* description: Bad request. DestinationCalendar body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
async function createDestinationCalendar(
req: NextApiRequest,
res: NextApiResponse<DestinationCalendarResponse>
) {
const safe = schemaDestinationCalendarBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body", safe.error);
async function createDestinationCalendar(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
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
} else res.status(405).json({ error: "Only POST Method allowed" });
const destinationCalendar = await prisma.destinationCalendar.create({ data: safe.data });
const data = schemaDestinationCalendarPublic.parse(destinationCalendar);
if (data) res.status(201).json({ data, message: "DestinationCalendar created successfully" });
else
(error: Error) =>
res.status(400).json({
message: "Could not create new destinationCalendar",
error,
});
}
export default withValidDestinationCalendar(createDestinationCalendar);
export default withMiddleware("HTTP_POST")(withValidDestinationCalendar(createDestinationCalendar));
@@ -2,28 +2,50 @@ import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BaseResponse } from "@lib/types";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/event-type-custom-inputs/{id}/delete:
* delete:
* summary: Remove an existing eventTypeCustomInput
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the eventTypeCustomInput to delete
* tags:
* - eventTypeCustomInputs
* responses:
* 201:
* description: OK, eventTypeCustomInput removed successfuly
* model: EventTypeCustomInput
* 400:
* description: Bad request. EventTypeCustomInput id is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function deleteEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query", safe.error);
export async function deleteEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
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 } });
// 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` });
// 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` });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only DELETE Method allowed" });
const data = await prisma.eventTypeCustomInput.delete({ where: { id: safe.data.id } });
if (data)
res.status(200).json({ message: `EventTypeCustomInput with id: ${safe.data.id} deleted successfully` });
else
(error: Error) =>
res.status(400).json({
message: `EventTypeCustomInput with id: ${safe.data.id} was not able to be processed`,
error,
});
}
export default withValidQueryIdTransformParseInt(deleteEventTypeCustomInput);
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteEventTypeCustomInput));
@@ -1,41 +0,0 @@
import type { NextApiRequest, NextApiResponse } from "next";
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;
message?: string;
error?: unknown;
};
export async function editEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const { query, body, method } = req;
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
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,
});
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 });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only PATCH Method allowed for updating eventTypeCustomInputs" });
}
export default withValidQueryIdTransformParseInt(withValidEventTypeCustomInput(editEventTypeCustomInput));
@@ -0,0 +1,65 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { EventTypeCustomInputResponse } from "@lib/types";
import {
schemaEventTypeCustomInputBodyParams,
schemaEventTypeCustomInputPublic,
withValidEventTypeCustomInput,
} from "@lib/validations/event-type-custom-input";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
/**
* @swagger
* /api/event-type-custom-inputs/{id}/edit:
* patch:
* summary: Edit an existing eventTypeCustomInput
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the eventTypeCustomInput to edit
* tags:
* - eventTypeCustomInputs
* responses:
* 201:
* description: OK, eventTypeCustomInput edited successfuly
* model: EventTypeCustomInput
* 400:
* description: Bad request. EventTypeCustomInput body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function editEventTypeCustomInput(
req: NextApiRequest,
res: NextApiResponse<EventTypeCustomInputResponse>
) {
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
const safeBody = await schemaEventTypeCustomInputBodyParams.safeParse(req.body);
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
const eventTypeCustomInput = await prisma.eventTypeCustomInput.update({
where: { id: safeQuery.data.id },
data: safeBody.data,
});
const data = schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput);
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("HTTP_PATCH")(
withValidQueryIdTransformParseInt(withValidEventTypeCustomInput(editEventTypeCustomInput))
);
@@ -1,29 +1,54 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { EventTypeCustomInput } from "@calcom/prisma/client";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { EventTypeCustomInputResponse } from "@lib/types";
import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-custom-input";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
type ResponseData = {
data?: EventTypeCustomInput;
message?: string;
error?: unknown;
};
/**
* @swagger
* /api/event-type-custom-inputs/{id}:
* get:
* summary: Get a eventTypeCustomInput by ID
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the eventTypeCustomInput to get
* tags:
* - eventTypeCustomInputs
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: EventTypeCustomInput was not found
*/
export async function eventTypeCustomInputById(
req: NextApiRequest,
res: NextApiResponse<EventTypeCustomInputResponse>
) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query");
export async function eventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const { query, method } = req;
const safe = await schemaQueryIdParseInt.safeParse(query);
if (method === "GET" && safe.success) {
const data = await prisma.eventTypeCustomInput.findUnique({ where: { id: safe.data.id } });
const eventTypeCustomInput = await prisma.eventTypeCustomInput.findUnique({ where: { id: safe.data.id } });
const data = schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput);
if (data) res.status(200).json({ data });
else res.status(404).json({ message: "Event type not found" });
// Reject any other HTTP method than POST
} else res.status(405).json({ message: "Only GET Method allowed" });
if (eventTypeCustomInput) res.status(200).json({ data });
else
(error: Error) =>
res.status(404).json({
message: "EventTypeCustomInput was not found",
error,
});
}
export default withValidQueryIdTransformParseInt(eventTypeCustomInput);
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(eventTypeCustomInputById));
+35 -8
View File
@@ -1,15 +1,42 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { EventTypeCustomInput } from "@calcom/prisma/client";
type ResponseData = {
data?: EventTypeCustomInput[];
error?: unknown;
};
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { EventTypeCustomInputsResponse } from "@lib/types";
import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-custom-input";
/**
* @swagger
* /api/event-type-custom-inputs:
* get:
* summary: Get all eventTypeCustomInputs
* tags:
* - eventTypeCustomInputs
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No eventTypeCustomInputs were found
*/
async function allEventTypeCustomInputs(
_: NextApiRequest,
res: NextApiResponse<EventTypeCustomInputsResponse>
) {
const eventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany();
const data = eventTypeCustomInputs.map((eventTypeCustomInput) =>
schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)
);
export default async function eventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const data = await prisma.eventTypeCustomInput.findMany();
if (data) res.status(200).json({ data });
else res.status(400).json({ error: "No data found" });
else
(error: Error) =>
res.status(404).json({
message: "No EventTypeCustomInputs were found",
error,
});
}
export default withMiddleware("HTTP_GET")(allEventTypeCustomInputs);
-31
View File
@@ -1,31 +0,0 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { EventTypeCustomInput } from "@calcom/prisma/client";
import {
schemaEventTypeCustomInput,
withValidEventTypeCustomInput,
} from "@lib/validations/eventTypeCustomInput";
type ResponseData = {
data?: EventTypeCustomInput;
message?: string;
error?: string;
};
async function createEventTypeCustomInput(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
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
} else res.status(405).json({ error: "Only POST Method allowed" });
}
export default withValidEventTypeCustomInput(createEventTypeCustomInput);
@@ -0,0 +1,55 @@
import type { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { EventTypeCustomInputResponse } from "@lib/types";
import {
schemaEventTypeCustomInputBodyParams,
schemaEventTypeCustomInputPublic,
withValidEventTypeCustomInput,
} from "@lib/validations/event-type-custom-input";
/**
* @swagger
* /api/event-type-custom-inputs/new:
* post:
* summary: Creates a new eventTypeCustomInput
* requestBody:
* description: Optional description in *Markdown*
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/EventTypeCustomInput'
* tags:
* - eventTypeCustomInputs
* responses:
* 201:
* description: OK, eventTypeCustomInput created
* model: EventTypeCustomInput
* 400:
* description: Bad request. EventTypeCustomInput body is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
async function createEventTypeCustomInput(
req: NextApiRequest,
res: NextApiResponse<EventTypeCustomInputResponse>
) {
const safe = schemaEventTypeCustomInputBodyParams.safeParse(req.body);
if (!safe.success) throw new Error("Invalid request body", safe.error);
const eventTypeCustomInput = await prisma.eventTypeCustomInput.create({ data: safe.data });
const data = schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput);
if (data) res.status(201).json({ data, message: "EventTypeCustomInput created successfully" });
else
(error: Error) =>
res.status(400).json({
message: "Could not create new eventTypeCustomInput",
error,
});
}
export default withMiddleware("HTTP_POST")(withValidEventTypeCustomInput(createEventTypeCustomInput));
+28 -9
View File
@@ -4,16 +4,27 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BaseResponse } from "@lib/types";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
/**
* @swagger
* /api/selectedCalendars/:id/delete:
* /api/selected-calendars/{userId}_{teamId}/delete:
* delete:
* summary: Remove an existing selectedCalendar
* parameters:
* - in: path
* - name: userId
* schema:
* type: integer
* required: true
* description: Numeric ID of the user to get the selectedCalendar of
* * - name: teamId
* schema:
* type: integer
* required: true
* description: Numeric ID of the team to get the selectedCalendar of
* tags:
* - selectedCalendars
* responses:
* 201:
* description: OK, selectedCalendar removed successfuly
@@ -24,10 +35,18 @@ import {
* description: Authorization information is missing or invalid.
*/
export async function deleteSelectedCalendar(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
const safe = await schemaQueryIdAsString.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query", safe.error);
const data = await prisma.selectedCalendar.delete({ where: { id: safe.data.id } });
const [userId, integration, externalId] = safe.data.id.split("_");
const data = await prisma.selectedCalendar.delete({
where: {
userId_integration_externalId: {
userId: parseInt(userId),
integration: integration,
externalId: externalId,
},
},
});
if (data)
res.status(200).json({ message: `SelectedCalendar with id: ${safe.data.id} deleted successfully` });
@@ -39,4 +58,4 @@ export async function deleteSelectedCalendar(req: NextApiRequest, res: NextApiRe
});
}
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteSelectedCalendar));
export default withMiddleware("HTTP_DELETE")(withValidQueryIdString(deleteSelectedCalendar));
+15 -9
View File
@@ -9,16 +9,15 @@ import {
schemaSelectedCalendarPublic,
withValidSelectedCalendar,
} from "@lib/validations/selected-calendar";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
/**
* @swagger
* /api/selectedCalendars/:id/edit:
* /api/selected-calendars/{id}/edit:
* patch:
* summary: Edits an existing selectedCalendar
* tags:
* - selectedCalendars
* responses:
* 201:
* description: OK, selectedCalendar edited successfuly
@@ -32,12 +31,19 @@ export async function editSelectedCalendar(
req: NextApiRequest,
res: NextApiResponse<SelectedCalendarResponse>
) {
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
const safeQuery = await schemaQueryIdAsString.safeParse(req.query);
const safeBody = await schemaSelectedCalendarBodyParams.safeParse(req.body);
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
const [userId, integration, externalId] = safeQuery.data.id.split("_");
const selectedCalendar = await prisma.selectedCalendar.update({
where: { id: safeQuery.data.id },
where: {
userId_integration_externalId: {
userId: parseInt(userId),
integration: integration,
externalId: externalId,
},
},
data: safeBody.data,
});
const data = schemaSelectedCalendarPublic.parse(selectedCalendar);
@@ -52,5 +58,5 @@ export async function editSelectedCalendar(
}
export default withMiddleware("HTTP_PATCH")(
withValidQueryIdTransformParseInt(withValidSelectedCalendar(editSelectedCalendar))
withValidQueryIdString(withValidSelectedCalendar(editSelectedCalendar))
);
+24 -12
View File
@@ -5,25 +5,28 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { SelectedCalendarResponse } from "@lib/types";
import { schemaSelectedCalendarPublic } from "@lib/validations/selected-calendar";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
} from "@lib/validations/shared/queryIdTransformParseInt";
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
/**
* @swagger
* /api/selectedCalendars/{id}:
* /api/selected-calendars/{userId}_{teamId}:
* get:
* summary: find selectedCalendar by ID
* summary: find selectedCalendar by userID and teamID
* parameters:
* - in: path
* name: id
* name: userId
* schema:
* type: integer
* required: true
* description: Numeric ID of the user to delete
* description: Numeric userId of the selectedCalendar to get
* - in: path
* name: teamId
* schema:
* type: integer
* required: true
* description: Numeric teamId of the selectedCalendar to get
* tags:
* - selected-calendars
* - selectedCalendars
* responses:
* 200:
* description: OK
@@ -36,10 +39,19 @@ export async function selectedCalendarById(
req: NextApiRequest,
res: NextApiResponse<SelectedCalendarResponse>
) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
const safe = await schemaQueryIdAsString.safeParse(req.query);
if (!safe.success) throw new Error("Invalid request query");
const [userId, integration, externalId] = safe.data.id.split("_");
const selectedCalendar = await prisma.selectedCalendar.findUnique({ where: { id: safe.data.id } });
const selectedCalendar = await prisma.selectedCalendar.findUnique({
where: {
userId_integration_externalId: {
userId: parseInt(userId),
integration: integration,
externalId: externalId,
},
},
});
const data = schemaSelectedCalendarPublic.parse(selectedCalendar);
if (selectedCalendar) res.status(200).json({ data });
@@ -51,4 +63,4 @@ export async function selectedCalendarById(
});
}
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(selectedCalendarById));
export default withMiddleware("HTTP_GET")(withValidQueryIdString(selectedCalendarById));