Merge pull request #34 from calcom/feat/unify-endpoints-further
This commit is contained in:
+34
-42
@@ -27,147 +27,139 @@ export type BaseResponse = {
|
||||
|
||||
// User
|
||||
export type UserResponse = BaseResponse & {
|
||||
data?: Partial<User>;
|
||||
user?: 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>[];
|
||||
users?: Partial<User>[];
|
||||
};
|
||||
|
||||
// Team
|
||||
export type TeamResponse = BaseResponse & {
|
||||
data?: Partial<Team>;
|
||||
team?: Partial<Team>;
|
||||
};
|
||||
export type TeamsResponse = BaseResponse & {
|
||||
data?: Partial<Team>[];
|
||||
teams?: Partial<Team>[];
|
||||
};
|
||||
|
||||
// SelectedCalendar
|
||||
export type SelectedCalendarResponse = BaseResponse & {
|
||||
data?: Partial<SelectedCalendar>;
|
||||
selected_calendar?: Partial<SelectedCalendar>;
|
||||
};
|
||||
export type SelectedCalendarsResponse = BaseResponse & {
|
||||
data?: Partial<SelectedCalendar>[];
|
||||
selected_calendars?: Partial<SelectedCalendar>[];
|
||||
};
|
||||
|
||||
// Attendee
|
||||
export type AttendeeResponse = BaseResponse & {
|
||||
data?: Partial<Attendee>;
|
||||
attendee?: Partial<Attendee>;
|
||||
};
|
||||
// Grouping attendees in booking arrays for now,
|
||||
// later might remove endpoint and move to booking endpoint altogether.
|
||||
export type AttendeesResponse = BaseResponse & {
|
||||
data?: Partial<Attendee>[];
|
||||
attendees?: Partial<Attendee>[];
|
||||
};
|
||||
|
||||
// Availability
|
||||
export type AvailabilityResponse = BaseResponse & {
|
||||
data?: Partial<Availability>;
|
||||
availability?: Partial<Availability>;
|
||||
};
|
||||
export type AvailabilitiesResponse = BaseResponse & {
|
||||
data?: Partial<Availability>[];
|
||||
availabilities?: Partial<Availability>[];
|
||||
};
|
||||
|
||||
// BookingReference
|
||||
export type BookingReferenceResponse = BaseResponse & {
|
||||
data?: Partial<BookingReference>;
|
||||
booking_reference?: Partial<BookingReference>;
|
||||
};
|
||||
export type BookingReferencesResponse = BaseResponse & {
|
||||
data?: Partial<BookingReference>[];
|
||||
booking_references?: Partial<BookingReference>[];
|
||||
};
|
||||
|
||||
// Booking
|
||||
export type BookingResponse = BaseResponse & {
|
||||
data?: Partial<Booking>;
|
||||
booking?: Partial<Booking>;
|
||||
};
|
||||
export type BookingsResponse = BaseResponse & {
|
||||
data?: Partial<Booking>[];
|
||||
bookings?: Partial<Booking>[];
|
||||
};
|
||||
|
||||
// Credential
|
||||
export type CredentialResponse = BaseResponse & {
|
||||
data?: Partial<Credential>;
|
||||
credential?: Partial<Credential>;
|
||||
};
|
||||
export type CredentialsResponse = BaseResponse & {
|
||||
data?: Partial<Credential>[];
|
||||
credentials?: Partial<Credential>[];
|
||||
};
|
||||
|
||||
// DailyEventReference
|
||||
export type DailyEventReferenceResponse = BaseResponse & {
|
||||
data?: Partial<DailyEventReference>;
|
||||
daily_event_reference?: Partial<DailyEventReference>;
|
||||
};
|
||||
export type DailyEventReferencesResponse = BaseResponse & {
|
||||
data?: Partial<DailyEventReference>[];
|
||||
daily_event_references?: Partial<DailyEventReference>[];
|
||||
};
|
||||
|
||||
// DestinationCalendar
|
||||
export type DestinationCalendarResponse = BaseResponse & {
|
||||
data?: Partial<DestinationCalendar>;
|
||||
destination_calendar?: Partial<DestinationCalendar>;
|
||||
};
|
||||
export type DestinationCalendarsResponse = BaseResponse & {
|
||||
data?: Partial<DestinationCalendar>[];
|
||||
destination_calendars?: Partial<DestinationCalendar>[];
|
||||
};
|
||||
|
||||
// Membership
|
||||
export type MembershipResponse = BaseResponse & {
|
||||
data?: Partial<Membership>;
|
||||
membership?: Partial<Membership>;
|
||||
};
|
||||
export type MembershipsResponse = BaseResponse & {
|
||||
data?: Partial<Membership>[];
|
||||
memberships?: Partial<Membership>[];
|
||||
};
|
||||
|
||||
// EventTypeCustomInput
|
||||
export type EventTypeCustomInputResponse = BaseResponse & {
|
||||
data?: Partial<EventTypeCustomInput>;
|
||||
event_type_custom_input?: Partial<EventTypeCustomInput>;
|
||||
};
|
||||
export type EventTypeCustomInputsResponse = BaseResponse & {
|
||||
data?: Partial<EventTypeCustomInput>[];
|
||||
event_type_custom_inputs?: Partial<EventTypeCustomInput>[];
|
||||
};
|
||||
|
||||
// EventType
|
||||
export type EventTypeResponse = BaseResponse & {
|
||||
data?: Partial<EventType>;
|
||||
event_type?: Partial<EventType>;
|
||||
};
|
||||
export type EventTypesResponse = BaseResponse & {
|
||||
data?: Partial<EventType>[];
|
||||
event_types?: Partial<EventType>[];
|
||||
};
|
||||
|
||||
// Payment
|
||||
export type PaymentResponse = BaseResponse & {
|
||||
data?: Partial<Payment>;
|
||||
payment?: Partial<Payment>;
|
||||
};
|
||||
export type PaymentsResponse = BaseResponse & {
|
||||
data?: Partial<Payment>[];
|
||||
payments?: Partial<Payment>[];
|
||||
};
|
||||
|
||||
// Schedule
|
||||
export type ScheduleResponse = BaseResponse & {
|
||||
data?: Partial<Schedule>;
|
||||
schedule?: Partial<Schedule>;
|
||||
};
|
||||
export type SchedulesResponse = BaseResponse & {
|
||||
data?: Partial<Schedule>[];
|
||||
schedules?: Partial<Schedule>[];
|
||||
};
|
||||
|
||||
// Webhook
|
||||
export type WebhookResponse = BaseResponse & {
|
||||
data?: Partial<Webhook>;
|
||||
webhook?: Partial<Webhook>;
|
||||
};
|
||||
export type WebhooksResponse = BaseResponse & {
|
||||
data?: Partial<Webhook>[];
|
||||
webhooks?: Partial<Webhook>[];
|
||||
};
|
||||
|
||||
// ReminderMail
|
||||
export type ReminderMailResponse = BaseResponse & {
|
||||
data?: Partial<ReminderMail>;
|
||||
reminder_mail?: Partial<ReminderMail>;
|
||||
};
|
||||
export type ReminderMailsResponse = BaseResponse & {
|
||||
data?: Partial<ReminderMail>[];
|
||||
reminder_mails?: Partial<ReminderMail>[];
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/attendees/{id}:
|
||||
* /v1/attendees/{id}:
|
||||
* get:
|
||||
* summary: Get an attendee by ID
|
||||
* parameters:
|
||||
@@ -81,16 +81,16 @@ import {
|
||||
*/
|
||||
export async function attendeeById(req: NextApiRequest, res: NextApiResponse<AttendeeResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaAttendeeBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaAttendeeBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.attendee
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((attendee) => schemaAttendeePublic.parse(attendee))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaAttendeePublic.parse(data))
|
||||
.then((attendee) => res.status(200).json({ attendee }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Attendee with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -103,8 +103,8 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse<Att
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((attendee) => schemaAttendeePublic.parse(attendee))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaAttendeePublic.parse(data))
|
||||
.then((attendee) => res.status(200).json({ attendee }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Attendee with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { schemaAttendeeBodyParams, schemaAttendeePublic, withValidAttendee } fro
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/attendees:
|
||||
* /v1/attendees:
|
||||
* get:
|
||||
* summary: Get all attendees
|
||||
* tags:
|
||||
@@ -49,9 +49,9 @@ async function createOrlistAllAttendees(
|
||||
attendees: true,
|
||||
},
|
||||
});
|
||||
const userBookingsAttendees = userBookings.map((booking) => booking.attendees).flat();
|
||||
const attendees = userBookings.map((booking) => booking.attendees).flat();
|
||||
if (method === "GET") {
|
||||
if (userBookingsAttendees) res.status(200).json({ data: userBookingsAttendees });
|
||||
if (attendees) res.status(200).json({ attendees });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
@@ -67,12 +67,12 @@ async function createOrlistAllAttendees(
|
||||
const bookingId = safe.data.bookingId;
|
||||
delete safe.data.bookingId;
|
||||
const noBookingId = safe.data;
|
||||
const attendee = await prisma.attendee.create({
|
||||
const data = await prisma.attendee.create({
|
||||
data: { ...noBookingId, booking: { connect: { id: parseInt(bookingId as string) } } },
|
||||
});
|
||||
const data = schemaAttendeePublic.parse(attendee);
|
||||
const attendee = schemaAttendeePublic.parse(data);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Attendee created successfully" });
|
||||
if (attendee) res.status(201).json({ attendee, message: "Attendee created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/availabilities/{id}:
|
||||
* /v1/availabilities/{id}:
|
||||
* get:
|
||||
* summary: Get an availability by ID
|
||||
* parameters:
|
||||
@@ -81,16 +81,16 @@ import {
|
||||
*/
|
||||
export async function availabilityById(req: NextApiRequest, res: NextApiResponse<AvailabilityResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaAvailabilityBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaAvailabilityBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.availability
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((availability) => schemaAvailabilityPublic.parse(availability))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaAvailabilityPublic.parse(data))
|
||||
.then((availability) => res.status(200).json({ availability }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -103,8 +103,8 @@ export async function availabilityById(req: NextApiRequest, res: NextApiResponse
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((availability) => schemaAvailabilityPublic.parse(availability))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaAvailabilityPublic.parse(data))
|
||||
.then((availability) => res.status(200).json({ availability }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Availability with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,12 +3,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { AvailabilitiesResponse } from "@lib/types";
|
||||
import { schemaAvailabilityPublic } from "@lib/validations/availability";
|
||||
import { AvailabilityResponse, AvailabilitiesResponse } from "@lib/types";
|
||||
import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/validations/availability";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/availabilities:
|
||||
* /v1/availabilities:
|
||||
* get:
|
||||
* summary: Get all availabilities
|
||||
* tags:
|
||||
@@ -20,18 +20,49 @@ import { schemaAvailabilityPublic } from "@lib/validations/availability";
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No availabilities were found
|
||||
* post:
|
||||
* summary: Creates a new availability
|
||||
* tags:
|
||||
* - availabilities
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, availability created
|
||||
* model: Availability
|
||||
* 400:
|
||||
* description: Bad request. Availability body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allAvailabilities(_: NextApiRequest, res: NextApiResponse<AvailabilitiesResponse>) {
|
||||
const availabilities = await prisma.availability.findMany();
|
||||
const data = availabilities.map((availability) => schemaAvailabilityPublic.parse(availability));
|
||||
async function createOrlistAllAvailabilities(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<AvailabilitiesResponse | AvailabilityResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.availability.findMany();
|
||||
const availabilities = data.map((availability) => schemaAvailabilityPublic.parse(availability));
|
||||
if (availabilities) res.status(200).json({ availabilities });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Availabilities were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaAvailabilityBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Availabilities were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.availability.create({ data: safe.data });
|
||||
const availability = schemaAvailabilityPublic.parse(data);
|
||||
|
||||
if (availability) res.status(201).json({ availability, message: "Availability created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new availability",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allAvailabilities);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllAvailabilities);
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { AvailabilityResponse } from "@lib/types";
|
||||
import {
|
||||
schemaAvailabilityBodyParams,
|
||||
schemaAvailabilityPublic,
|
||||
withValidAvailability,
|
||||
} from "@lib/validations/availability";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/availabilities/new:
|
||||
* post:
|
||||
* summary: Creates a new availability
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Availability'
|
||||
* tags:
|
||||
* - availabilities
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, availability created
|
||||
* 400:
|
||||
* description: Bad request. Availability body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createAvailability(req: NextApiRequest, res: NextApiResponse<AvailabilityResponse>) {
|
||||
const safe = schemaAvailabilityBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const availability = await prisma.availability.create({ data: safe.data });
|
||||
const data = schemaAvailabilityPublic.parse(availability);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Availability created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new availability",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidAvailability(createAvailability));
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/booking-references/{id}:
|
||||
* /v1/booking-references/{id}:
|
||||
* get:
|
||||
* summary: Get a daily event reference by ID
|
||||
* parameters:
|
||||
@@ -87,16 +87,17 @@ export async function bookingReferenceById(
|
||||
res: NextApiResponse<BookingReferenceResponse>
|
||||
) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaBookingReferenceBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaBookingReferenceBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
// FIXME: Allow only userId owner of booking ref to edit it
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.bookingReference
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaBookingReferencePublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((booking_reference) => res.status(200).json({ booking_reference }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `BookingReference with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -109,8 +110,8 @@ export async function bookingReferenceById(
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((bookingReference) => schemaBookingReferencePublic.parse(bookingReference))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaBookingReferencePublic.parse(data))
|
||||
.then((booking_reference) => res.status(200).json({ booking_reference }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `BookingReference with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,14 +3,17 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { BookingReferencesResponse } from "@lib/types";
|
||||
import { schemaBookingReferencePublic } from "@lib/validations/booking-reference";
|
||||
import { BookingReferenceResponse, BookingReferencesResponse } from "@lib/types";
|
||||
import {
|
||||
schemaBookingReferenceBodyParams,
|
||||
schemaBookingReferencePublic,
|
||||
} from "@lib/validations/booking-reference";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/booking-references:
|
||||
* /v1/booking-references:
|
||||
* get:
|
||||
* summary: Get all bookingReferences
|
||||
* summary: Get all booking references
|
||||
* tags:
|
||||
* - booking-references
|
||||
* responses:
|
||||
@@ -19,21 +22,52 @@ import { schemaBookingReferencePublic } from "@lib/validations/booking-reference
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No bookingReferences were found
|
||||
* description: No booking references were found
|
||||
* post:
|
||||
* summary: Creates a new booking reference
|
||||
* tags:
|
||||
* - booking-references
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, booking reference created
|
||||
* model: BookingReference
|
||||
* 400:
|
||||
* description: Bad request. BookingReference body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allBookingReferences(_: NextApiRequest, res: NextApiResponse<BookingReferencesResponse>) {
|
||||
const bookingReferences = await prisma.bookingReference.findMany();
|
||||
const data = bookingReferences.map((bookingReference) =>
|
||||
schemaBookingReferencePublic.parse(bookingReference)
|
||||
);
|
||||
async function createOrlistAllBookingReferences(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<BookingReferencesResponse | BookingReferenceResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.bookingReference.findMany();
|
||||
const booking_references = data.map((bookingReference) =>
|
||||
schemaBookingReferencePublic.parse(bookingReference)
|
||||
);
|
||||
if (booking_references) res.status(200).json({ booking_references });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No BookingReferences were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaBookingReferenceBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No BookingReferences were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.bookingReference.create({ data: safe.data });
|
||||
const booking_reference = schemaBookingReferencePublic.parse(data);
|
||||
|
||||
if (data) res.status(201).json({ booking_reference, message: "BookingReference created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new booking reference",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allBookingReferences);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllBookingReferences);
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { BookingReferenceResponse } from "@lib/types";
|
||||
import {
|
||||
schemaBookingReferenceBodyParams,
|
||||
schemaBookingReferencePublic,
|
||||
withValidBookingReference,
|
||||
} from "@lib/validations/booking-reference";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/booking-references/new:
|
||||
* post:
|
||||
* summary: Creates a new bookingReference
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/BookingReference'
|
||||
* tags:
|
||||
* - booking-references
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, bookingReference created
|
||||
* 400:
|
||||
* description: Bad request. BookingReference body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createBookingReference(req: NextApiRequest, res: NextApiResponse<BookingReferenceResponse>) {
|
||||
const safe = schemaBookingReferenceBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const bookingReference = await prisma.bookingReference.create({ data: safe.data });
|
||||
const data = schemaBookingReferencePublic.parse(bookingReference);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "BookingReference created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new bookingReference",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidBookingReference(createBookingReference));
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/bookings/{id}:
|
||||
* /v1/bookings/{id}:
|
||||
* get:
|
||||
* summary: Get a booking by ID
|
||||
* parameters:
|
||||
@@ -81,16 +81,16 @@ import {
|
||||
*/
|
||||
export async function bookingById(req: NextApiRequest, res: NextApiResponse<BookingResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaBookingBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaBookingBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
// FIXME: Allow only userId owner of booking to edit it
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.booking
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((booking) => schemaBookingPublic.parse(booking))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaBookingPublic.parse(data))
|
||||
.then((booking) => res.status(200).json({ booking }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Booking with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -103,8 +103,8 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((booking) => schemaBookingPublic.parse(booking))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaBookingPublic.parse(data))
|
||||
.then((booking) => res.status(200).json({ booking }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Booking with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
+47
-14
@@ -3,12 +3,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { BookingsResponse } from "@lib/types";
|
||||
import { schemaBookingPublic } from "@lib/validations/booking";
|
||||
import { BookingResponse, BookingsResponse } from "@lib/types";
|
||||
import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "@lib/validations/booking";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/bookings:
|
||||
* /v1/bookings:
|
||||
* get:
|
||||
* summary: Get all bookings
|
||||
* tags:
|
||||
@@ -20,18 +20,51 @@ import { schemaBookingPublic } from "@lib/validations/booking";
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No bookings were found
|
||||
* post:
|
||||
* summary: Creates a new booking
|
||||
* tags:
|
||||
* - bookings
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, booking created
|
||||
* model: Booking
|
||||
* 400:
|
||||
* description: Bad request. Booking body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allBookings(_: NextApiRequest, res: NextApiResponse<BookingsResponse>) {
|
||||
const bookings = await prisma.booking.findMany();
|
||||
const data = bookings.map((booking) => schemaBookingPublic.parse(booking));
|
||||
async function createOrlistAllBookings(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<BookingsResponse | BookingResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
// FIXME: List only bookings owner by userId
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Bookings were found",
|
||||
error,
|
||||
});
|
||||
if (method === "GET") {
|
||||
const data = await prisma.booking.findMany();
|
||||
const bookings = data.map((booking) => schemaBookingPublic.parse(booking));
|
||||
if (bookings) res.status(200).json({ bookings });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Bookings were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaBookingBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const data = await prisma.booking.create({ data: safe.data });
|
||||
const booking = schemaBookingPublic.parse(data);
|
||||
|
||||
if (booking) res.status(201).json({ booking, message: "Booking created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new booking",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allBookings);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllBookings);
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { BookingResponse } from "@lib/types";
|
||||
import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "@lib/validations/booking";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/bookings/new:
|
||||
* post:
|
||||
* summary: Creates a new booking
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Booking'
|
||||
* tags:
|
||||
* - bookings
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, booking created
|
||||
* model: Booking
|
||||
* 400:
|
||||
* description: Bad request. Booking body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createBooking(req: NextApiRequest, res: NextApiResponse<BookingResponse>) {
|
||||
const safe = schemaBookingBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const booking = await prisma.booking.create({ data: safe.data });
|
||||
const data = schemaBookingPublic.parse(booking);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Booking created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new booking",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidBooking(createBooking));
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/credentials/{id}:
|
||||
* /v1/credentials/{id}:
|
||||
* get:
|
||||
* summary: Get a credential by ID
|
||||
* parameters:
|
||||
@@ -81,16 +81,16 @@ import {
|
||||
*/
|
||||
export async function credentialById(req: NextApiRequest, res: NextApiResponse<CredentialResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaCredentialBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaCredentialBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.credential
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((credential) => schemaCredentialPublic.parse(credential))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaCredentialPublic.parse(data))
|
||||
.then((credential) => res.status(200).json({ credential }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -103,8 +103,8 @@ export async function credentialById(req: NextApiRequest, res: NextApiResponse<C
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((credential) => schemaCredentialPublic.parse(credential))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaCredentialPublic.parse(data))
|
||||
.then((credential) => res.status(200).json({ credential }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Credential with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,8 +3,8 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { CredentialsResponse } from "@lib/types";
|
||||
import { schemaCredentialPublic } from "@lib/validations/credential";
|
||||
import { CredentialResponse, CredentialsResponse } from "@lib/types";
|
||||
import { schemaCredentialBodyParams, schemaCredentialPublic } from "@lib/validations/credential";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -20,18 +20,49 @@ import { schemaCredentialPublic } from "@lib/validations/credential";
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No credentials were found
|
||||
* post:
|
||||
* summary: Creates a new credential
|
||||
* tags:
|
||||
* - credentials
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, credential created
|
||||
* model: Credential
|
||||
* 400:
|
||||
* description: Bad request. Credential body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allCredentials(_: NextApiRequest, res: NextApiResponse<CredentialsResponse>) {
|
||||
const credentials = await prisma.credential.findMany();
|
||||
const data = credentials.map((credential) => schemaCredentialPublic.parse(credential));
|
||||
async function createOrlistAllCredentials(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<CredentialsResponse | CredentialResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.credential.findMany();
|
||||
const credentials = data.map((credential) => schemaCredentialPublic.parse(credential));
|
||||
if (credentials) res.status(200).json({ credentials });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Credentials were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaCredentialBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Credentials were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.credential.create({ data: safe.data });
|
||||
const credential = schemaCredentialPublic.parse(data);
|
||||
|
||||
if (credential) res.status(201).json({ credential, message: "Credential created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new credential",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allCredentials);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllCredentials);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { CredentialResponse } from "@lib/types";
|
||||
import {
|
||||
schemaCredentialBodyParams,
|
||||
schemaCredentialPublic,
|
||||
withValidCredential,
|
||||
} from "@lib/validations/credential";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/credentials/new:
|
||||
* post:
|
||||
* summary: Creates a new credential
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Credential'
|
||||
* tags:
|
||||
* - credentials
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, credential created
|
||||
* model: Credential
|
||||
* 400:
|
||||
* description: Bad request. Credential body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createCredential(req: NextApiRequest, res: NextApiResponse<CredentialResponse>) {
|
||||
const safe = schemaCredentialBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const credential = await prisma.credential.create({ data: safe.data });
|
||||
const data = schemaCredentialPublic.parse(credential);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Credential created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new credential",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidCredential(createCredential));
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/daily-event-references/{id}:
|
||||
* /v1/daily-event-references/{id}:
|
||||
* get:
|
||||
* summary: Get a daily event reference by ID
|
||||
* parameters:
|
||||
@@ -87,8 +87,8 @@ export async function dailyEventReferenceById(
|
||||
res: NextApiResponse<DailyEventReferenceResponse>
|
||||
) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaDailyEventReferenceBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaDailyEventReferenceBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
@@ -96,7 +96,7 @@ export async function dailyEventReferenceById(
|
||||
await prisma.dailyEventReference
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaDailyEventReferencePublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((daily_event_reference) => res.status(200).json({ daily_event_reference }))
|
||||
.catch((error: Error) =>
|
||||
res
|
||||
.status(404)
|
||||
@@ -111,8 +111,8 @@ export async function dailyEventReferenceById(
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((dailyEventReference) => schemaDailyEventReferencePublic.parse(dailyEventReference))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaDailyEventReferencePublic.parse(data))
|
||||
.then((daily_event_reference) => res.status(200).json({ daily_event_reference }))
|
||||
.catch((error: Error) =>
|
||||
res
|
||||
.status(404)
|
||||
|
||||
@@ -3,40 +3,72 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { DailyEventReferencesResponse } from "@lib/types";
|
||||
import { schemaDailyEventReferencePublic } from "@lib/validations/daily-event-reference";
|
||||
import { DailyEventReferenceResponse, DailyEventReferencesResponse } from "@lib/types";
|
||||
import {
|
||||
schemaDailyEventReferenceBodyParams,
|
||||
schemaDailyEventReferencePublic,
|
||||
} from "@lib/validations/daily-event-reference";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/daily-event-references:
|
||||
* /v1/daily-event-references:
|
||||
* get:
|
||||
* summary: Get all dailyEventReferences
|
||||
* summary: Get all daily event reference
|
||||
* tags:
|
||||
* - daily-event-references
|
||||
* - daily-event-reference
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No dailyEventReferences were found
|
||||
* description: No daily event references were found
|
||||
* post:
|
||||
* summary: Creates a new daily event reference
|
||||
* tags:
|
||||
* - daily-event-reference
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, daily event reference created
|
||||
* model: DailyEventReference
|
||||
* 400:
|
||||
* description: Bad request. DailyEventReference body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allDailyEventReferences(
|
||||
_: NextApiRequest,
|
||||
res: NextApiResponse<DailyEventReferencesResponse>
|
||||
async function createOrlistAllDailyEventReferences(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<DailyEventReferencesResponse | DailyEventReferenceResponse>
|
||||
) {
|
||||
const dailyEventReferences = await prisma.dailyEventReference.findMany();
|
||||
const data = dailyEventReferences.map((dailyEventReference) =>
|
||||
schemaDailyEventReferencePublic.parse(dailyEventReference)
|
||||
);
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.dailyEventReference.findMany();
|
||||
const daily_event_references = data.map((dailyEventReference) =>
|
||||
schemaDailyEventReferencePublic.parse(dailyEventReference)
|
||||
);
|
||||
if (daily_event_references) res.status(200).json({ daily_event_references });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No DailyEventReferences were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaDailyEventReferenceBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No DailyEventReferences were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.dailyEventReference.create({ data: safe.data });
|
||||
const daily_event_reference = schemaDailyEventReferencePublic.parse(data);
|
||||
|
||||
if (daily_event_reference)
|
||||
res.status(201).json({ daily_event_reference, message: "DailyEventReference created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new daily event reference",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allDailyEventReferences);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllDailyEventReferences);
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { DailyEventReferenceResponse } from "@lib/types";
|
||||
import {
|
||||
schemaDailyEventReferenceBodyParams,
|
||||
schemaDailyEventReferencePublic,
|
||||
withValidDailyEventReference,
|
||||
} from "@lib/validations/daily-event-reference";
|
||||
|
||||
/**
|
||||
* @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:
|
||||
* - daily-event-references
|
||||
* 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);
|
||||
|
||||
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 withMiddleware("HTTP_POST")(withValidDailyEventReference(createDailyEventReference));
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/destination-calendars/{id}:
|
||||
* /v1/destination-calendars/{id}:
|
||||
* get:
|
||||
* summary: Get a destination calendar by ID
|
||||
* parameters:
|
||||
@@ -87,8 +87,8 @@ export async function destionationCalendarById(
|
||||
res: NextApiResponse<DestinationCalendarResponse>
|
||||
) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaDestinationCalendarBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaDestinationCalendarBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
@@ -96,7 +96,7 @@ export async function destionationCalendarById(
|
||||
await prisma.destinationCalendar
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaDestinationCalendarPublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((destination_calendar) => res.status(200).json({ destination_calendar }))
|
||||
.catch((error: Error) =>
|
||||
res
|
||||
.status(404)
|
||||
@@ -111,8 +111,8 @@ export async function destionationCalendarById(
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((destinationCalendar) => schemaDestinationCalendarPublic.parse(destinationCalendar))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaDestinationCalendarPublic.parse(data))
|
||||
.then((destination_calendar) => res.status(200).json({ destination_calendar }))
|
||||
.catch((error: Error) =>
|
||||
res
|
||||
.status(404)
|
||||
|
||||
@@ -3,12 +3,15 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { DestinationCalendarsResponse } from "@lib/types";
|
||||
import { schemaDestinationCalendarPublic } from "@lib/validations/destination-calendar";
|
||||
import { DestinationCalendarResponse, DestinationCalendarsResponse } from "@lib/types";
|
||||
import {
|
||||
schemaDestinationCalendarBodyParams,
|
||||
schemaDestinationCalendarPublic,
|
||||
} from "@lib/validations/destination-calendar";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/destination-calendars:
|
||||
* /v1/destination-calendars:
|
||||
* get:
|
||||
* summary: Get all destination calendars
|
||||
* tags:
|
||||
@@ -19,24 +22,53 @@ import { schemaDestinationCalendarPublic } from "@lib/validations/destination-ca
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No destinationCalendars were found
|
||||
* description: No destination calendars were found
|
||||
* post:
|
||||
* summary: Creates a new destination calendar
|
||||
* tags:
|
||||
* - destination-calendars
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, destination calendar created
|
||||
* model: DestinationCalendar
|
||||
* 400:
|
||||
* description: Bad request. DestinationCalendar body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allDestinationCalendars(
|
||||
_: NextApiRequest,
|
||||
res: NextApiResponse<DestinationCalendarsResponse>
|
||||
async function createOrlistAllDestinationCalendars(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<DestinationCalendarsResponse | DestinationCalendarResponse>
|
||||
) {
|
||||
const destinationCalendars = await prisma.destinationCalendar.findMany();
|
||||
const data = destinationCalendars.map((destinationCalendar) =>
|
||||
schemaDestinationCalendarPublic.parse(destinationCalendar)
|
||||
);
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.destinationCalendar.findMany();
|
||||
const destination_calendars = data.map((destinationCalendar) =>
|
||||
schemaDestinationCalendarPublic.parse(destinationCalendar)
|
||||
);
|
||||
if (data) res.status(200).json({ destination_calendars });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No DestinationCalendars were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaDestinationCalendarBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No DestinationCalendars were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.destinationCalendar.create({ data: safe.data });
|
||||
const destination_calendar = schemaDestinationCalendarPublic.parse(data);
|
||||
|
||||
if (destination_calendar)
|
||||
res.status(201).json({ destination_calendar, message: "DestinationCalendar created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new destinationCalendar",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allDestinationCalendars);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllDestinationCalendars);
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { DestinationCalendarResponse } from "@lib/types";
|
||||
import {
|
||||
schemaDestinationCalendarBodyParams,
|
||||
schemaDestinationCalendarPublic,
|
||||
withValidDestinationCalendar,
|
||||
} from "@lib/validations/destination-calendar";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/destination-calendars/new:
|
||||
* post:
|
||||
* summary: Creates a new destination calendar
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/DestinationCalendar'
|
||||
* tags:
|
||||
* - destination-calendars
|
||||
* 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);
|
||||
|
||||
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 withMiddleware("HTTP_POST")(withValidDestinationCalendar(createDestinationCalendar));
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/event-type-custom-inputs/{id}:
|
||||
* /v1/event-type-custom-inputs/{id}:
|
||||
* get:
|
||||
* summary: Get a eventTypeCustomInput by ID
|
||||
* parameters:
|
||||
@@ -44,7 +44,7 @@ import {
|
||||
* description: The eventTypeCustomInput to edit
|
||||
* schema:
|
||||
* type: object
|
||||
* $ref: '#/comCustomInputponents/schemas/EventType'
|
||||
* $ref: '#/components/schemas/EventTypeCustomInput'
|
||||
* required: true
|
||||
* - in: path
|
||||
* name: id
|
||||
@@ -84,8 +84,8 @@ import {
|
||||
*/
|
||||
async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventTypeCustomInputResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaEventTypeCustomInputBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaEventTypeCustomInputBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
@@ -93,7 +93,7 @@ async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventType
|
||||
await prisma.eventTypeCustomInput
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaEventTypeCustomInputPublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((event_type_custom_input) => res.status(200).json({ event_type_custom_input }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -106,8 +106,8 @@ async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventType
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((eventTypeCustomInput) => schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaEventTypeCustomInputPublic.parse(data))
|
||||
.then((event_type_custom_input) => res.status(200).json({ event_type_custom_input }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,12 +3,15 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { EventTypeCustomInputsResponse } from "@lib/types";
|
||||
import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-custom-input";
|
||||
import { EventTypeCustomInputResponse, EventTypeCustomInputsResponse } from "@lib/types";
|
||||
import {
|
||||
schemaEventTypeCustomInputBodyParams,
|
||||
schemaEventTypeCustomInputPublic,
|
||||
} from "@lib/validations/event-type-custom-input";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/event-type-custom-inputs:
|
||||
* /v1/event-type-custom-inputs:
|
||||
* get:
|
||||
* summary: Get all eventTypeCustomInputs
|
||||
* tags:
|
||||
@@ -20,23 +23,52 @@ import { schemaEventTypeCustomInputPublic } from "@lib/validations/event-type-cu
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No eventTypeCustomInputs were found
|
||||
* post:
|
||||
* summary: Creates a new eventTypeCustomInput
|
||||
* tags:
|
||||
* - event-type-custom-inputs
|
||||
* 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 allEventTypeCustomInputs(
|
||||
_: NextApiRequest,
|
||||
res: NextApiResponse<EventTypeCustomInputsResponse>
|
||||
async function createOrlistAllEventTypeCustomInputs(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<EventTypeCustomInputsResponse | EventTypeCustomInputResponse>
|
||||
) {
|
||||
const eventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany();
|
||||
const data = eventTypeCustomInputs.map((eventTypeCustomInput) =>
|
||||
schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)
|
||||
);
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.eventTypeCustomInput.findMany();
|
||||
const event_type_custom_inputs = data.map((eventTypeCustomInput) =>
|
||||
schemaEventTypeCustomInputPublic.parse(eventTypeCustomInput)
|
||||
);
|
||||
if (event_type_custom_inputs) res.status(200).json({ event_type_custom_inputs });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No EventTypeCustomInputs were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaEventTypeCustomInputBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No EventTypeCustomInputs were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.eventTypeCustomInput.create({ data: safe.data });
|
||||
const event_type_custom_input = schemaEventTypeCustomInputPublic.parse(data);
|
||||
|
||||
if (event_type_custom_input)
|
||||
res.status(201).json({ event_type_custom_input, message: "EventTypeCustomInput created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new eventTypeCustomInput",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allEventTypeCustomInputs);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllEventTypeCustomInputs);
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
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:
|
||||
* - event-type-custom-inputs
|
||||
* 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));
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/event-types/{id}:
|
||||
* /v1/event-types/{id}:
|
||||
* get:
|
||||
* summary: Get a eventType by ID
|
||||
* parameters:
|
||||
@@ -81,8 +81,8 @@ import {
|
||||
*/
|
||||
export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventTypeResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaEventTypeBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaEventTypeBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
@@ -90,7 +90,7 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Ev
|
||||
await prisma.eventType
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaEventTypePublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((event_type) => res.status(200).json({ event_type }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -103,8 +103,8 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Ev
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((eventType) => schemaEventTypePublic.parse(eventType))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaEventTypePublic.parse(data))
|
||||
.then((event_type) => res.status(200).json({ event_type }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `EventType with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,14 +3,14 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { EventTypesResponse } from "@lib/types";
|
||||
import { schemaEventTypePublic } from "@lib/validations/event-type";
|
||||
import { EventTypeResponse, EventTypesResponse } from "@lib/types";
|
||||
import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/eventTypes:
|
||||
* /v1/event-types:
|
||||
* get:
|
||||
* summary: Returns all eventTypes
|
||||
* summary: Get all event types
|
||||
* tags:
|
||||
* - event-types
|
||||
* responses:
|
||||
@@ -19,19 +19,50 @@ import { schemaEventTypePublic } from "@lib/validations/event-type";
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No eventTypes were found
|
||||
* description: No event types were found
|
||||
* post:
|
||||
* summary: Creates a new event type
|
||||
* tags:
|
||||
* - event-types
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, event type created
|
||||
* model: EventType
|
||||
* 400:
|
||||
* description: Bad request. EventType body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allEventTypes(_: NextApiRequest, res: NextApiResponse<EventTypesResponse>) {
|
||||
const eventTypes = await prisma.eventType.findMany();
|
||||
const data = eventTypes.map((eventType) => schemaEventTypePublic.parse(eventType));
|
||||
async function createOrlistAllEventTypes(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<EventTypesResponse | EventTypeResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.eventType.findMany();
|
||||
const event_types = data.map((eventType) => schemaEventTypePublic.parse(eventType));
|
||||
if (event_types) res.status(200).json({ event_types });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No EventTypes were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaEventTypeBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No EventTypes were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.eventType.create({ data: safe.data });
|
||||
const event_type = schemaEventTypePublic.parse(data);
|
||||
|
||||
if (data) res.status(201).json({ event_type, message: "EventType created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new event type",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allEventTypes);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllEventTypes);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { EventTypeResponse } from "@lib/types";
|
||||
import {
|
||||
schemaEventTypeBodyParams,
|
||||
schemaEventTypePublic,
|
||||
withValidEventType,
|
||||
} from "@lib/validations/event-type";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/event-types/new:
|
||||
* post:
|
||||
* summary: Creates a new eventType
|
||||
* tags:
|
||||
* - event-types
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, eventType created
|
||||
* model: EventType
|
||||
* 400:
|
||||
* description: Bad request. EventType body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createEventType(req: NextApiRequest, res: NextApiResponse<EventTypeResponse>) {
|
||||
const safe = schemaEventTypeBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const eventType = await prisma.eventType.create({ data: safe.data });
|
||||
const data = schemaEventTypePublic.parse(eventType);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "EventType created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new eventType",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidEventType(createEventType));
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default async function CalcomApi(req: NextApiRequest, res: NextApiResponse) {
|
||||
export default async function CalcomApi(_: NextApiRequest, res: NextApiResponse) {
|
||||
res.status(201).json({ message: "Welcome to Cal.com API - docs are at https://docs.cal.com/api" });
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/memberships/{userId}_{teamId}:
|
||||
* /v1/memberships/{userId}_{teamId}:
|
||||
* get:
|
||||
* summary: Get a membership by userID and teamID
|
||||
* parameters:
|
||||
@@ -96,8 +96,8 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
*/
|
||||
export async function membershipById(req: NextApiRequest, res: NextApiResponse<MembershipResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdAsString.safeParse(query);
|
||||
const safeBody = await schemaMembershipBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdAsString.safeParse(query);
|
||||
const safeBody = schemaMembershipBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
// This is how we set the userId and teamId in the query for managing compoundId.
|
||||
const [userId, teamId] = safeQuery.data.id.split("_");
|
||||
@@ -106,8 +106,8 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<M
|
||||
case "GET":
|
||||
await prisma.membership
|
||||
.findUnique({ where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } } })
|
||||
.then((membership) => schemaMembershipPublic.parse(membership))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaMembershipPublic.parse(data))
|
||||
.then((membership) => res.status(200).json({ membership }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -120,8 +120,8 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<M
|
||||
where: { userId_teamId: { userId: parseInt(userId), teamId: parseInt(teamId) } },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((membership) => schemaMembershipPublic.parse(membership))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaMembershipPublic.parse(data))
|
||||
.then((membership) => res.status(200).json({ membership }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Membership with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,14 +3,14 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { MembershipsResponse } from "@lib/types";
|
||||
import { schemaMembershipPublic } from "@lib/validations/membership";
|
||||
import { MembershipResponse, MembershipsResponse } from "@lib/types";
|
||||
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/memberships:
|
||||
* /v1/memberships:
|
||||
* get:
|
||||
* summary: Returns all memberships
|
||||
* summary: Get all memberships
|
||||
* tags:
|
||||
* - memberships
|
||||
* responses:
|
||||
@@ -20,18 +20,49 @@ import { schemaMembershipPublic } from "@lib/validations/membership";
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No memberships were found
|
||||
* post:
|
||||
* summary: Creates a new membership
|
||||
* tags:
|
||||
* - memberships
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, membership created
|
||||
* model: Membership
|
||||
* 400:
|
||||
* description: Bad request. Membership body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allMemberships(_: NextApiRequest, res: NextApiResponse<MembershipsResponse>) {
|
||||
const memberships = await prisma.membership.findMany();
|
||||
const data = memberships.map((membership) => schemaMembershipPublic.parse(membership));
|
||||
async function createOrlistAllMemberships(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<MembershipsResponse | MembershipResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.membership.findMany();
|
||||
const memberships = data.map((membership) => schemaMembershipPublic.parse(membership));
|
||||
if (memberships) res.status(200).json({ memberships });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Memberships were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaMembershipBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Memberships were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.membership.create({ data: safe.data });
|
||||
const membership = schemaMembershipPublic.parse(data);
|
||||
|
||||
if (membership) res.status(201).json({ membership, message: "Membership created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new membership",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allMemberships);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllMemberships);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { MembershipResponse } from "@lib/types";
|
||||
import {
|
||||
schemaMembershipBodyParams,
|
||||
schemaMembershipPublic,
|
||||
withValidMembership,
|
||||
} from "@lib/validations/membership";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/memberships/new:
|
||||
* post:
|
||||
* summary: Creates a new membership
|
||||
* tags:
|
||||
* - memberships
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, membership created
|
||||
* model: Membership
|
||||
* 400:
|
||||
* description: Bad request. Membership body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createMembership(req: NextApiRequest, res: NextApiResponse<MembershipResponse>) {
|
||||
const safe = schemaMembershipBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const membership = await prisma.membership.create({ data: safe.data });
|
||||
const data = schemaMembershipPublic.parse(membership);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Membership created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new membership",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidMembership(createMembership));
|
||||
+28
-94
@@ -4,7 +4,8 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { PaymentResponse } from "@lib/types";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/payment";
|
||||
import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
|
||||
import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
@@ -12,9 +13,9 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments/{id}:
|
||||
* /v1/payments/{id}:
|
||||
* get:
|
||||
* summary: Get an payment by ID
|
||||
* summary: Get one of your own payments by ID
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
@@ -31,100 +32,33 @@ import {
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: Payment was not found
|
||||
* patch:
|
||||
* summary: Edit an existing payment
|
||||
* consumes:
|
||||
* - application/json
|
||||
* parameters:
|
||||
* - in: body
|
||||
* name: payment
|
||||
* description: The payment to edit
|
||||
* schema:
|
||||
* type: object
|
||||
* $ref: '#/components/schemas/Payment'
|
||||
* required: true
|
||||
* - in: path
|
||||
* name: id
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric ID of the payment to edit
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, payment edited successfuly
|
||||
* model: Payment
|
||||
* 400:
|
||||
* description: Bad request. Payment body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* delete:
|
||||
* summary: Remove an existing payment
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric ID of the payment to delete
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, payment removed successfuly
|
||||
* model: Payment
|
||||
* 400:
|
||||
* description: Bad request. Payment id is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
export async function paymentById(req: NextApiRequest, res: NextApiResponse<PaymentResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaPaymentBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
const { method, query } = req;
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const userId = await getCalcomUserId(res);
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.payment
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((payment) => schemaPaymentPublic.parse(payment))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Payment with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
break;
|
||||
|
||||
case "PATCH":
|
||||
if (!safeBody.success) throw new Error("Invalid request body");
|
||||
await prisma.payment
|
||||
.update({
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
if (safeQuery.success && method === "GET") {
|
||||
const userWithBookings = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: { bookings: true },
|
||||
});
|
||||
await prisma.payment
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaPaymentPublic.parse(data))
|
||||
.then((payment) => {
|
||||
if (userWithBookings?.bookings.map((b) => b.id).includes(payment.bookingId)) {
|
||||
res.status(200).json({ payment });
|
||||
} else {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
}
|
||||
})
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({
|
||||
message: `Payment with id: ${safeQuery.data.id} not found`,
|
||||
error,
|
||||
})
|
||||
.then((payment) => schemaPaymentPublic.parse(payment))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Payment with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
break;
|
||||
|
||||
case "DELETE":
|
||||
await prisma.payment
|
||||
.delete({ where: { id: safeQuery.data.id } })
|
||||
.then(() =>
|
||||
res.status(200).json({ message: `Payment with id: ${safeQuery.data.id} deleted successfully` })
|
||||
)
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Payment with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
res.status(405).json({ message: "Method not allowed" });
|
||||
break;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET_DELETE_PATCH")(withValidQueryIdTransformParseInt(paymentById));
|
||||
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(paymentById));
|
||||
|
||||
@@ -4,11 +4,12 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { PaymentsResponse } from "@lib/types";
|
||||
import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
|
||||
import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments:
|
||||
* /v1/payments:
|
||||
* get:
|
||||
* summary: Get all payments
|
||||
* tags:
|
||||
@@ -22,10 +23,19 @@ import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
* description: No payments were found
|
||||
*/
|
||||
async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsResponse>) {
|
||||
const payments = await prisma.payment.findMany();
|
||||
const data = payments.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
const userId = await getCalcomUserId(res);
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
const userWithBookings = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: { bookings: true },
|
||||
});
|
||||
if (!userWithBookings) throw new Error("No user found");
|
||||
const bookings = userWithBookings.bookings;
|
||||
const bookingIds = bookings.map((booking) => booking.id);
|
||||
const data = await prisma.payment.findMany({ where: { bookingId: { in: bookingIds } } });
|
||||
const payments = data.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
|
||||
if (payments) res.status(200).json({ payments });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
@@ -33,5 +43,5 @@ async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsRespo
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
// NO POST FOR PAYMENTS FOR NOW
|
||||
export default withMiddleware("HTTP_GET")(allPayments);
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { PaymentResponse } from "@lib/types";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments/new:
|
||||
* post:
|
||||
* summary: Creates a new payment
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Payment'
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, payment created
|
||||
* model: Payment
|
||||
* 400:
|
||||
* description: Bad request. Payment body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createPayment(req: NextApiRequest, res: NextApiResponse<PaymentResponse>) {
|
||||
const safe = schemaPaymentBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const payment = await prisma.payment.create({ data: safe.data });
|
||||
const data = schemaPaymentPublic.parse(payment);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Payment created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new payment",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidPayment(createPayment));
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/reminder-mails/{id}:
|
||||
* /v1/reminder-mails/{id}:
|
||||
* get:
|
||||
* summary: Get a reminderMail by ID
|
||||
* parameters:
|
||||
@@ -81,8 +81,8 @@ import {
|
||||
*/
|
||||
export async function reminderMailById(req: NextApiRequest, res: NextApiResponse<ReminderMailResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaReminderMailBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaReminderMailBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
@@ -90,7 +90,7 @@ export async function reminderMailById(req: NextApiRequest, res: NextApiResponse
|
||||
await prisma.reminderMail
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaReminderMailPublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((reminder_mail) => res.status(200).json({ reminder_mail }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -104,7 +104,7 @@ export async function reminderMailById(req: NextApiRequest, res: NextApiResponse
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((reminderMail) => schemaReminderMailPublic.parse(reminderMail))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((reminder_mail) => res.status(200).json({ reminder_mail }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `ReminderMail with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,12 +3,16 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { ReminderMailsResponse } from "@lib/types";
|
||||
import { schemaReminderMailPublic } from "@lib/validations/reminder-mail";
|
||||
import { ReminderMailResponse, ReminderMailsResponse } from "@lib/types";
|
||||
import {
|
||||
schemaReminderMailBodyParams,
|
||||
schemaReminderMailPublic,
|
||||
withValidReminderMail,
|
||||
} from "@lib/validations/reminder-mail";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/reminder-mails:
|
||||
* /v1/reminder-mails:
|
||||
* get:
|
||||
* summary: Get all reminder mails
|
||||
* tags:
|
||||
@@ -19,19 +23,50 @@ import { schemaReminderMailPublic } from "@lib/validations/reminder-mail";
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No reminderMails were found
|
||||
* description: No reminder mails were found
|
||||
* post:
|
||||
* summary: Creates a new reminder mail
|
||||
* tags:
|
||||
* - reminder-mails
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, reminder mail created
|
||||
* model: ReminderMail
|
||||
* 400:
|
||||
* description: Bad request. ReminderMail body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allReminderMails(_: NextApiRequest, res: NextApiResponse<ReminderMailsResponse>) {
|
||||
const reminderMails = await prisma.reminderMail.findMany();
|
||||
const data = reminderMails.map((reminderMail) => schemaReminderMailPublic.parse(reminderMail));
|
||||
async function createOrlistAllReminderMails(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<ReminderMailsResponse | ReminderMailResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.reminderMail.findMany();
|
||||
const reminder_mails = data.map((reminderMail) => schemaReminderMailPublic.parse(reminderMail));
|
||||
if (reminder_mails) res.status(200).json({ reminder_mails });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No ReminderMails were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaReminderMailBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No ReminderMails were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.reminderMail.create({ data: safe.data });
|
||||
const reminder_mail = schemaReminderMailPublic.parse(data);
|
||||
|
||||
if (reminder_mail) res.status(201).json({ reminder_mail, message: "reminder mail created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "could not create new reminder mail",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allReminderMails);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(withValidReminderMail(createOrlistAllReminderMails));
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { ReminderMailResponse } from "@lib/types";
|
||||
import {
|
||||
schemaReminderMailBodyParams,
|
||||
schemaReminderMailPublic,
|
||||
withValidReminderMail,
|
||||
} from "@lib/validations/reminder-mail";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/reminder-mails/new:
|
||||
* post:
|
||||
* summary: Creates a new reminder mail
|
||||
* requestBody:
|
||||
* description: Optional description in *Markdown*
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/ReminderMail'
|
||||
* tags:
|
||||
* - reminder-mails
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, reminderMail created
|
||||
* model: ReminderMail
|
||||
* 400:
|
||||
* description: Bad request. ReminderMail body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createReminderMail(req: NextApiRequest, res: NextApiResponse<ReminderMailResponse>) {
|
||||
const safe = schemaReminderMailBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const reminderMail = await prisma.reminderMail.create({ data: safe.data });
|
||||
const data = schemaReminderMailPublic.parse(reminderMail);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "ReminderMail created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new reminderMail",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidReminderMail(createReminderMail));
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/schedules/{id}:
|
||||
* /v1/schedules/{id}:
|
||||
* get:
|
||||
* summary: Get a schedule by ID
|
||||
* parameters:
|
||||
@@ -81,16 +81,16 @@ import {
|
||||
*/
|
||||
export async function scheduleById(req: NextApiRequest, res: NextApiResponse<ScheduleResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaScheduleBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaScheduleBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.schedule
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((schedule) => schemaSchedulePublic.parse(schedule))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaSchedulePublic.parse(data))
|
||||
.then((schedule) => res.status(200).json({ schedule }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -103,8 +103,8 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((schedule) => schemaSchedulePublic.parse(schedule))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaSchedulePublic.parse(data))
|
||||
.then((schedule) => res.status(200).json({ schedule }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Schedule with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,14 +3,14 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { SchedulesResponse } from "@lib/types";
|
||||
import { schemaSchedulePublic } from "@lib/validations/schedule";
|
||||
import { ScheduleResponse, SchedulesResponse } from "@lib/types";
|
||||
import { schemaScheduleBodyParams, schemaSchedulePublic, withValidSchedule } from "@lib/validations/schedule";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/schedules:
|
||||
* /v1/schedules:
|
||||
* get:
|
||||
* summary: Returns all schedules
|
||||
* summary: Get all schedules
|
||||
* tags:
|
||||
* - schedules
|
||||
* responses:
|
||||
@@ -20,18 +20,49 @@ import { schemaSchedulePublic } from "@lib/validations/schedule";
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No schedules were found
|
||||
* post:
|
||||
* summary: Creates a new schedule
|
||||
* tags:
|
||||
* - schedules
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, schedule created
|
||||
* model: Schedule
|
||||
* 400:
|
||||
* description: Bad request. Schedule body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allSchedules(_: NextApiRequest, res: NextApiResponse<SchedulesResponse>) {
|
||||
const schedules = await prisma.schedule.findMany();
|
||||
const data = schedules.map((schedule) => schemaSchedulePublic.parse(schedule));
|
||||
async function createOrlistAllSchedules(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<SchedulesResponse | ScheduleResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.schedule.findMany();
|
||||
const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule));
|
||||
if (schedules) res.status(200).json({ schedules });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Schedules were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaScheduleBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Schedules were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.schedule.create({ data: safe.data });
|
||||
const schedule = schemaSchedulePublic.parse(data);
|
||||
|
||||
if (schedule) res.status(201).json({ schedule, message: "Schedule created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new schedule",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allSchedules);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(withValidSchedule(createOrlistAllSchedules));
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { ScheduleResponse } from "@lib/types";
|
||||
import { schemaScheduleBodyParams, schemaSchedulePublic, withValidSchedule } from "@lib/validations/schedule";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/schedules/new:
|
||||
* post:
|
||||
* summary: Creates a new schedule
|
||||
* tags:
|
||||
* - schedules
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, schedule created
|
||||
* model: Schedule
|
||||
* 400:
|
||||
* description: Bad request. Schedule body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createSchedule(req: NextApiRequest, res: NextApiResponse<ScheduleResponse>) {
|
||||
const safe = schemaScheduleBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const schedule = await prisma.schedule.create({ data: safe.data });
|
||||
const data = schemaSchedulePublic.parse(schedule);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Schedule created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new schedule",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidSchedule(createSchedule));
|
||||
@@ -1,68 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { PaymentResponse, PaymentsResponse } from "@lib/types";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments:
|
||||
* get:
|
||||
* summary: Get all payments
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No payments were found
|
||||
* post:
|
||||
* summary: Creates a new payment
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, payment created
|
||||
* model: Payment
|
||||
* 400:
|
||||
* description: Bad request. Payment body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createOrlistAllPayments(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<PaymentsResponse | PaymentResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const payments = await prisma.payment.findMany();
|
||||
const data = payments.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Payments were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaPaymentBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const payment = await prisma.payment.create({ data: safe.data });
|
||||
const data = schemaPaymentPublic.parse(payment);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Payment created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new payment",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(withValidPayment(createOrlistAllPayments));
|
||||
@@ -12,7 +12,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/selected-calendars/{userId}_{teamId}:
|
||||
* /v1/selected-calendars/{userId}_{integration}_{externalId}:
|
||||
* get:
|
||||
* summary: Get a selected-calendar by userID and teamID
|
||||
* parameters:
|
||||
@@ -21,13 +21,19 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric userId of the selected-calendar to get
|
||||
* description: userId of the selected calendar to get
|
||||
* - in: path
|
||||
* name: teamId
|
||||
* name: externalId
|
||||
* schema:
|
||||
* type: integer
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Numeric teamId of the selected-calendar to get
|
||||
* description: externalId of the selected calendar to get
|
||||
* - in: path
|
||||
* name: integration
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: integration of the selected calendar to get
|
||||
* tags:
|
||||
* - selected-calendars
|
||||
* responses:
|
||||
@@ -38,7 +44,7 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
* 404:
|
||||
* description: SelectedCalendar was not found
|
||||
* patch:
|
||||
* summary: Edit an existing selected-calendar
|
||||
* summary: Edit an existing selected calendar
|
||||
* consumes:
|
||||
* - application/json
|
||||
* parameters:
|
||||
@@ -54,13 +60,19 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric userId of the selected-calendar to get
|
||||
* description: userId of the selected calendar to get
|
||||
* - in: path
|
||||
* name: teamId
|
||||
* name: externalId
|
||||
* schema:
|
||||
* type: integer
|
||||
* type: string
|
||||
* required: true
|
||||
* description: Numeric teamId of the selected-calendar to get
|
||||
* description: externalId of the selected calendar to get
|
||||
* - in: path
|
||||
* name: integration
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: integration of the selected calendar to get
|
||||
* tags:
|
||||
* - selected-calendars
|
||||
* responses:
|
||||
@@ -79,13 +91,19 @@ import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric userId of the selected-calendar to get
|
||||
* description: userId of the selected calendar to get
|
||||
* - in: path
|
||||
* name: teamId
|
||||
* name: externalId
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric teamId of the selected-calendar to get
|
||||
* description: externalId of the selected-calendar to get
|
||||
* - in: path
|
||||
* name: integration
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: integration of the selected calendar to get
|
||||
* tags:
|
||||
* - selected-calendars
|
||||
* responses:
|
||||
@@ -102,10 +120,10 @@ export async function selectedCalendarById(
|
||||
res: NextApiResponse<SelectedCalendarResponse>
|
||||
) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdAsString.safeParse(query);
|
||||
const safeBody = await schemaSelectedCalendarBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdAsString.safeParse(query);
|
||||
const safeBody = schemaSelectedCalendarBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
// This is how we set the userId and teamId in the query for managing compoundId.
|
||||
// This is how we set the userId and externalId in the query for managing compoundId.
|
||||
const [userId, integration, externalId] = safeQuery.data.id.split("_");
|
||||
|
||||
switch (method) {
|
||||
@@ -121,7 +139,7 @@ export async function selectedCalendarById(
|
||||
},
|
||||
})
|
||||
.then((selectedCalendar) => schemaSelectedCalendarPublic.parse(selectedCalendar))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((selected_calendar) => res.status(200).json({ selected_calendar }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `SelectedCalendar with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -141,7 +159,7 @@ export async function selectedCalendarById(
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((selectedCalendar) => schemaSelectedCalendarPublic.parse(selectedCalendar))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((selected_calendar) => res.status(200).json({ selected_calendar }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `SelectedCalendar with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -3,14 +3,18 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { SelectedCalendarsResponse } from "@lib/types";
|
||||
import { schemaSelectedCalendarPublic } from "@lib/validations/selected-calendar";
|
||||
import { SelectedCalendarResponse, SelectedCalendarsResponse } from "@lib/types";
|
||||
import {
|
||||
schemaSelectedCalendarBodyParams,
|
||||
schemaSelectedCalendarPublic,
|
||||
withValidSelectedCalendar,
|
||||
} from "@lib/validations/selected-calendar";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/selected-calendars:
|
||||
* /v1/selected-calendars:
|
||||
* get:
|
||||
* summary: Returns all selected calendars
|
||||
* summary: Get all selected calendars
|
||||
* tags:
|
||||
* - selected-calendars
|
||||
* responses:
|
||||
@@ -19,21 +23,55 @@ import { schemaSelectedCalendarPublic } from "@lib/validations/selected-calendar
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No selectedCalendars were found
|
||||
* description: No selected calendars were found
|
||||
* post:
|
||||
* summary: Creates a new selected calendar
|
||||
* tags:
|
||||
* - selected-calendars
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, selected calendar created
|
||||
* model: SelectedCalendar
|
||||
* 400:
|
||||
* description: Bad request. SelectedCalendar body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allSelectedCalendars(_: NextApiRequest, res: NextApiResponse<SelectedCalendarsResponse>) {
|
||||
const selectedCalendars = await prisma.selectedCalendar.findMany();
|
||||
const data = selectedCalendars.map((selectedCalendar) =>
|
||||
schemaSelectedCalendarPublic.parse(selectedCalendar)
|
||||
);
|
||||
async function createOrlistAllSelectedCalendars(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<SelectedCalendarsResponse | SelectedCalendarResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const data = await prisma.selectedCalendar.findMany();
|
||||
const selected_calendars = data.map((selected_calendar) =>
|
||||
schemaSelectedCalendarPublic.parse(selected_calendar)
|
||||
);
|
||||
if (selected_calendars) res.status(200).json({ selected_calendars });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No SelectedCalendars were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaSelectedCalendarBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No SelectedCalendars were found",
|
||||
error,
|
||||
});
|
||||
const data = await prisma.selectedCalendar.create({ data: safe.data });
|
||||
const selected_calendar = schemaSelectedCalendarPublic.parse(data);
|
||||
|
||||
if (selected_calendar)
|
||||
res.status(201).json({ selected_calendar, message: "SelectedCalendar created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new selected calendar",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allSelectedCalendars);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(
|
||||
withValidSelectedCalendar(createOrlistAllSelectedCalendars)
|
||||
);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { SelectedCalendarResponse } from "@lib/types";
|
||||
import {
|
||||
schemaSelectedCalendarBodyParams,
|
||||
schemaSelectedCalendarPublic,
|
||||
withValidSelectedCalendar,
|
||||
} from "@lib/validations/selected-calendar";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/selected-calendars/new:
|
||||
* post:
|
||||
* summary: Creates a new selected calendar
|
||||
* tags:
|
||||
* - selected-calendars
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, selected calendar created
|
||||
* model: SelectedCalendar
|
||||
* 400:
|
||||
* description: Bad request. SelectedCalendar body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createSelectedCalendar(req: NextApiRequest, res: NextApiResponse<SelectedCalendarResponse>) {
|
||||
const safe = schemaSelectedCalendarBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const selectedCalendar = await prisma.selectedCalendar.create({ data: safe.data });
|
||||
const data = schemaSelectedCalendarPublic.parse(selectedCalendar);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "SelectedCalendar created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new selectedCalendar",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidSelectedCalendar(createSelectedCalendar));
|
||||
@@ -1,68 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { PaymentResponse, PaymentsResponse } from "@lib/types";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments:
|
||||
* get:
|
||||
* summary: Get all payments
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No payments were found
|
||||
* post:
|
||||
* summary: Creates a new payment
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, payment created
|
||||
* model: Payment
|
||||
* 400:
|
||||
* description: Bad request. Payment body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createOrlistAllPayments(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<PaymentsResponse | PaymentResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const payments = await prisma.payment.findMany();
|
||||
const data = payments.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Payments were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaPaymentBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const payment = await prisma.payment.create({ data: safe.data });
|
||||
const data = schemaPaymentPublic.parse(payment);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Payment created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new payment",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(withValidPayment(createOrlistAllPayments));
|
||||
+11
-6
@@ -4,6 +4,7 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { TeamResponse } from "@lib/types";
|
||||
import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
@@ -12,7 +13,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/teams/{id}:
|
||||
* /v1/teams/{id}:
|
||||
* get:
|
||||
* summary: Get a team by ID
|
||||
* parameters:
|
||||
@@ -81,16 +82,20 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
|
||||
*/
|
||||
export async function teamById(req: NextApiRequest, res: NextApiResponse<TeamResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaTeamBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaTeamBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
|
||||
const userId = getCalcomUserId(res);
|
||||
const userWithMemberships = await prisma.membership.findMany({
|
||||
where: { userId: userId },
|
||||
});
|
||||
console.log(userWithMemberships);
|
||||
switch (method) {
|
||||
case "GET":
|
||||
await prisma.team
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaTeamPublic.parse(data))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((team) => res.status(200).json({ team }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Team with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -104,7 +109,7 @@ export async function teamById(req: NextApiRequest, res: NextApiResponse<TeamRes
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((team) => schemaTeamPublic.parse(team))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((team) => res.status(200).json({ team }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `Team with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
+52
-15
@@ -3,14 +3,15 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { TeamsResponse } from "@lib/types";
|
||||
import { schemaTeamPublic } from "@lib/validations/team";
|
||||
import { TeamResponse, TeamsResponse } from "@lib/types";
|
||||
import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
|
||||
import { schemaTeamBodyParams, schemaTeamPublic, withValidTeam } from "@lib/validations/team";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/teams:
|
||||
* /v1/teams:
|
||||
* get:
|
||||
* summary: Returns all teams
|
||||
* summary: Get all teams
|
||||
* tags:
|
||||
* - teams
|
||||
* responses:
|
||||
@@ -20,18 +21,54 @@ import { schemaTeamPublic } from "@lib/validations/team";
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No teams were found
|
||||
* post:
|
||||
* summary: Creates a new team
|
||||
* tags:
|
||||
* - teams
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, team created
|
||||
* model: Team
|
||||
* 400:
|
||||
* description: Bad request. Team body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function allTeams(_: NextApiRequest, res: NextApiResponse<TeamsResponse>) {
|
||||
const teams = await prisma.team.findMany();
|
||||
const data = teams.map((team) => schemaTeamPublic.parse(team));
|
||||
async function createOrlistAllTeams(req: NextApiRequest, res: NextApiResponse<TeamsResponse | TeamResponse>) {
|
||||
const { method } = req;
|
||||
const userId = getCalcomUserId(res);
|
||||
if (method === "GET") {
|
||||
const userWithMemberships = await prisma.membership.findMany({
|
||||
where: { userId: userId },
|
||||
});
|
||||
const teamIds = userWithMemberships.map((membership) => membership.teamId);
|
||||
const teams = await prisma.team.findMany({ where: { id: { in: teamIds } } });
|
||||
if (teams) res.status(200).json({ teams });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Teams were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
// FIXME: add userId as owner of the team
|
||||
const safe = schemaTeamBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
const team = await prisma.team.create({ data: safe.data });
|
||||
const membership = await prisma.membership.create({
|
||||
data: { userId: userId, teamId: team.id, role: "ADMIN" },
|
||||
});
|
||||
console.log(membership);
|
||||
const data = schemaTeamPublic.parse(team);
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Teams were found",
|
||||
error,
|
||||
});
|
||||
if (data) res.status(201).json({ team: data, message: "Team created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new team",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET")(allTeams);
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllTeams);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { TeamResponse } from "@lib/types";
|
||||
import { schemaTeamBodyParams, schemaTeamPublic, withValidTeam } from "@lib/validations/team";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/teams/new:
|
||||
* post:
|
||||
* summary: Creates a new team
|
||||
* tags:
|
||||
* - teams
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, team created
|
||||
* model: Team
|
||||
* 400:
|
||||
* description: Bad request. Team body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createTeam(req: NextApiRequest, res: NextApiResponse<TeamResponse>) {
|
||||
const safe = schemaTeamBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body", safe.error);
|
||||
|
||||
const team = await prisma.team.create({ data: safe.data });
|
||||
const data = schemaTeamPublic.parse(team);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Team created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new team",
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_POST")(withValidTeam(createTeam));
|
||||
@@ -13,7 +13,7 @@ import { schemaUserBodyParams, schemaUserPublic } from "@lib/validations/user";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/users/{id}:
|
||||
* /v1/users/{id}:
|
||||
* get:
|
||||
* summary: Get a user by ID, returns your user if regular user.
|
||||
* parameters:
|
||||
@@ -82,8 +82,8 @@ import { schemaUserBodyParams, schemaUserPublic } from "@lib/validations/user";
|
||||
*/
|
||||
export async function userById(req: NextApiRequest, res: NextApiResponse<UserResponse>) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = await schemaUserBodyParams.safeParse(body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaUserBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
const userId = getCalcomUserId(res);
|
||||
if (safeQuery.data.id === userId) {
|
||||
@@ -91,8 +91,8 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
||||
case "GET":
|
||||
await prisma.user
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((user) => schemaUserPublic.parse(user))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaUserPublic.parse(data))
|
||||
.then((user) => res.status(200).json({ user }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `User with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
@@ -105,8 +105,8 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
||||
where: { id: safeQuery.data.id },
|
||||
data: safeBody.data,
|
||||
})
|
||||
.then((user) => schemaUserPublic.parse(user))
|
||||
.then((data) => res.status(200).json({ data }))
|
||||
.then((data) => schemaUserPublic.parse(data))
|
||||
.then((user) => res.status(200).json({ user }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({ message: `User with id: ${safeQuery.data.id} not found`, error })
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { schemaUserPublic } from "@lib/validations/user";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/users:
|
||||
* /v1/users:
|
||||
* get:
|
||||
* summary: Get all users (admin only), returns your user if regular user.
|
||||
* tags:
|
||||
@@ -24,13 +24,13 @@ import { schemaUserPublic } from "@lib/validations/user";
|
||||
*/
|
||||
async function allUsers(req: NextApiRequest, res: NextApiResponse<UsersResponse>) {
|
||||
const userId = getCalcomUserId(res);
|
||||
const users = await prisma.user.findMany({
|
||||
const data = await prisma.user.findMany({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
const data = users.map((user) => schemaUserPublic.parse(user));
|
||||
if (data) res.status(200).json({ data });
|
||||
const users = data.map((user) => schemaUserPublic.parse(user));
|
||||
if (users) res.status(200).json({ users });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/resources/{id}/delete:
|
||||
* /v1/resources/{id}/delete:
|
||||
* delete:
|
||||
* summary: Remove an existing resource
|
||||
* parameters:
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
export async function deleteResource(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safe = schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (!safe.success) throw new Error("Invalid request query", safe.error);
|
||||
|
||||
const data = await prisma.resource.delete({ where: { id: safe.data.id } });
|
||||
|
||||
@@ -4,15 +4,15 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { ResourceResponse } from "@lib/types";
|
||||
import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } from "@lib/validations/resource";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } from "@lib/validations/resource";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/resources/{id}/edit:
|
||||
* /v1/resources/{id}/edit:
|
||||
* patch:
|
||||
* summary: Edit an existing resource
|
||||
* parameters:
|
||||
@@ -34,8 +34,8 @@ import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } fro
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
export async function editResource(req: NextApiRequest, res: NextApiResponse<ResourceResponse>) {
|
||||
const safeQuery = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safeBody = await schemaResourceBodyParams.safeParse(req.body);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safeBody = schemaResourceBodyParams.safeParse(req.body);
|
||||
|
||||
if (!safeQuery.success || !safeBody.success) throw new Error("Invalid request");
|
||||
const resource = await prisma.resource.update({
|
||||
@@ -53,4 +53,6 @@ export async function editResource(req: NextApiRequest, res: NextApiResponse<Res
|
||||
});
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_PATCH")(withValidQueryIdTransformParseInt(withValidResource(editResource)));
|
||||
export default withMiddleware("HTTP_PATCH")(
|
||||
withValidQueryIdTransformParseInt(withValidResource(editResource))
|
||||
);
|
||||
|
||||
@@ -4,15 +4,15 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { ResourceResponse } from "@lib/types";
|
||||
import { schemaResourcePublic } from "@lib/validations/resource";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
import { schemaResourcePublic } from "@lib/validations/resource";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/resources/{id}:
|
||||
* /v1/resources/{id}:
|
||||
* get:
|
||||
* summary: Get a resource by ID
|
||||
* parameters:
|
||||
@@ -33,7 +33,7 @@ import { schemaResourcePublic } from "@lib/validations/resource";
|
||||
* description: Resource was not found
|
||||
*/
|
||||
export async function resourceById(req: NextApiRequest, res: NextApiResponse<ResourceResponse>) {
|
||||
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
||||
const safe = schemaQueryIdParseInt.safeParse(req.query);
|
||||
if (!safe.success) throw new Error("Invalid request query");
|
||||
|
||||
const resource = await prisma.resource.findUnique({ where: { id: safe.data.id } });
|
||||
|
||||
@@ -8,7 +8,7 @@ import { schemaResourcePublic } from "@lib/validations/resource";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/resources:
|
||||
* /v1/resources:
|
||||
* get:
|
||||
* summary: Get all resources
|
||||
* tags:
|
||||
@@ -4,11 +4,11 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { PaymentResponse, PaymentsResponse } from "@lib/types";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments:
|
||||
* /v1/payments:
|
||||
* get:
|
||||
* summary: Get all payments
|
||||
* tags:
|
||||
@@ -65,4 +65,4 @@ async function createOrlistAllPayments(
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(withValidPayment(createOrlistAllPayments));
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(createOrlistAllPayments);
|
||||
@@ -1,68 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { PaymentResponse, PaymentsResponse } from "@lib/types";
|
||||
import { schemaPaymentBodyParams, schemaPaymentPublic, withValidPayment } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments:
|
||||
* get:
|
||||
* summary: Get all payments
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* 404:
|
||||
* description: No payments were found
|
||||
* post:
|
||||
* summary: Creates a new payment
|
||||
* tags:
|
||||
* - payments
|
||||
* responses:
|
||||
* 201:
|
||||
* description: OK, payment created
|
||||
* model: Payment
|
||||
* 400:
|
||||
* description: Bad request. Payment body is invalid.
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function createOrlistAllPayments(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<PaymentsResponse | PaymentResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const payments = await prisma.payment.findMany();
|
||||
const data = payments.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
if (data) res.status(200).json({ data });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Payments were found",
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaPaymentBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const payment = await prisma.payment.create({ data: safe.data });
|
||||
const data = schemaPaymentPublic.parse(payment);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Payment created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new payment",
|
||||
error,
|
||||
});
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
export default withMiddleware("HTTP_GET_OR_POST")(withValidPayment(createOrlistAllPayments));
|
||||
@@ -8,7 +8,7 @@ import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } fro
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/resources/new:
|
||||
* /v1/resources/new:
|
||||
* post:
|
||||
* summary: Creates a new resource
|
||||
* requestBody:
|
||||
Reference in New Issue
Block a user