feat: all resources endpoints for get all and new unified
This commit is contained in:
1 parent
963c893727
commit
0bda988676
38 files changed
+370
-483
No files matched your search
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/attendees/{id}:
|
||||
* /v1/attendees/{id}:
|
||||
* get:
|
||||
* summary: Get an attendee by ID
|
||||
* parameters:
|
||||
|
||||
@@ -9,7 +9,7 @@ import { schemaAttendeeBodyParams, schemaAttendeePublic, withValidAttendee } fro
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/attendees:
|
||||
* /v1/attendees:
|
||||
* get:
|
||||
* summary: Get all attendees
|
||||
* tags:
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/availabilities/{id}:
|
||||
* /v1/availabilities/{id}:
|
||||
* get:
|
||||
* summary: Get an availability by ID
|
||||
* parameters:
|
||||
|
||||
@@ -8,7 +8,7 @@ import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/val
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/availabilities:
|
||||
* /v1/availabilities:
|
||||
* get:
|
||||
* summary: Get all availabilities
|
||||
* tags:
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/booking-references/{id}:
|
||||
* /v1/booking-references/{id}:
|
||||
* get:
|
||||
* summary: Get a daily event reference by ID
|
||||
* parameters:
|
||||
@@ -90,6 +90,7 @@ export async function bookingReferenceById(
|
||||
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":
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/booking-references:
|
||||
* /v1/booking-references:
|
||||
* get:
|
||||
* summary: Get all booking references
|
||||
* tags:
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/bookings/{id}:
|
||||
* /v1/bookings/{id}:
|
||||
* get:
|
||||
* summary: Get a booking by ID
|
||||
* parameters:
|
||||
@@ -84,7 +84,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
|
||||
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
|
||||
|
||||
@@ -8,7 +8,7 @@ import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/bookings:
|
||||
* /v1/bookings:
|
||||
* get:
|
||||
* summary: Get all bookings
|
||||
* tags:
|
||||
@@ -38,6 +38,8 @@ async function createOrlistAllBookings(
|
||||
res: NextApiResponse<BookingsResponse | BookingResponse>
|
||||
) {
|
||||
const { method } = req;
|
||||
// FIXME: List only bookings owner by userId
|
||||
|
||||
if (method === "GET") {
|
||||
const data = await prisma.booking.findMany();
|
||||
const bookings = data.map((booking) => schemaBookingPublic.parse(booking));
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/credentials/{id}:
|
||||
* /v1/credentials/{id}:
|
||||
* get:
|
||||
* summary: Get a credential by ID
|
||||
* parameters:
|
||||
@@ -89,8 +89,8 @@ export async function credentialById(req: NextApiRequest, res: NextApiResponse<C
|
||||
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:
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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));
|
||||
@@ -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:
|
||||
@@ -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));
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments/{id}:
|
||||
* /v1/payments/{id}:
|
||||
* get:
|
||||
* summary: Get one of your own payments by ID
|
||||
* parameters:
|
||||
@@ -45,10 +45,10 @@ export async function paymentById(req: NextApiRequest, res: NextApiResponse<Paym
|
||||
});
|
||||
await prisma.payment
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((payment) => schemaPaymentPublic.parse(payment))
|
||||
.then((data) => {
|
||||
if (userWithBookings?.bookings.map((b) => b.id).includes(data.bookingId)) {
|
||||
res.status(200).json({ data });
|
||||
.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" });
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/payments:
|
||||
* /v1/payments:
|
||||
* get:
|
||||
* summary: Get all payments
|
||||
* tags:
|
||||
@@ -32,10 +32,10 @@ async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsRespo
|
||||
if (!userWithBookings) throw new Error("No user found");
|
||||
const bookings = userWithBookings.bookings;
|
||||
const bookingIds = bookings.map((booking) => booking.id);
|
||||
const payments = await prisma.payment.findMany({ where: { bookingId: { in: bookingIds } } });
|
||||
const data = payments.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
const data = await prisma.payment.findMany({ where: { bookingId: { in: bookingIds } } });
|
||||
const payments = data.map((payment) => schemaPaymentPublic.parse(payment));
|
||||
|
||||
if (data) res.status(200).json({ data });
|
||||
if (payments) res.status(200).json({ payments });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
@@ -43,5 +43,5 @@ async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsRespo
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
// NO POST FOR PAYMENTS FOR NOW
|
||||
export default withMiddleware("HTTP_GET")(allPayments);
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/reminder-mails/{id}:
|
||||
* /v1/reminder-mails/{id}:
|
||||
* get:
|
||||
* summary: Get a reminderMail by ID
|
||||
* parameters:
|
||||
@@ -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 })
|
||||
);
|
||||
|
||||
@@ -43,9 +43,9 @@ async function createOrlistAllReminderMails(
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const reminderMails = await prisma.reminderMail.findMany();
|
||||
const data = reminderMails.map((reminderMail) => schemaReminderMailPublic.parse(reminderMail));
|
||||
if (data) res.status(200).json({ data });
|
||||
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({
|
||||
@@ -56,10 +56,10 @@ async function createOrlistAllReminderMails(
|
||||
const safe = schemaReminderMailBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const reminderMail = await prisma.reminderMail.create({ data: safe.data });
|
||||
const data = schemaReminderMailPublic.parse(reminderMail);
|
||||
const data = await prisma.reminderMail.create({ data: safe.data });
|
||||
const reminder_mail = schemaReminderMailPublic.parse(data);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "reminder mail created successfully" });
|
||||
if (reminder_mail) res.status(201).json({ reminder_mail, message: "reminder mail created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
|
||||
@@ -89,8 +89,8 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
|
||||
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 })
|
||||
);
|
||||
|
||||
@@ -39,9 +39,9 @@ async function createOrlistAllSchedules(
|
||||
) {
|
||||
const { method } = req;
|
||||
if (method === "GET") {
|
||||
const schedules = await prisma.schedule.findMany();
|
||||
const data = schedules.map((schedule) => schemaSchedulePublic.parse(schedule));
|
||||
if (data) res.status(200).json({ data });
|
||||
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({
|
||||
@@ -52,10 +52,10 @@ async function createOrlistAllSchedules(
|
||||
const safe = schemaScheduleBodyParams.safeParse(req.body);
|
||||
if (!safe.success) throw new Error("Invalid request body");
|
||||
|
||||
const schedule = await prisma.schedule.create({ data: safe.data });
|
||||
const data = schemaSchedulePublic.parse(schedule);
|
||||
const data = await prisma.schedule.create({ data: safe.data });
|
||||
const schedule = schemaSchedulePublic.parse(data);
|
||||
|
||||
if (data) res.status(201).json({ data, message: "Schedule created successfully" });
|
||||
if (schedule) res.status(201).json({ schedule, message: "Schedule created successfully" });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/resources/{id}/delete:
|
||||
* /v1/resources/{id}/delete:
|
||||
* delete:
|
||||
* summary: Remove an existing resource
|
||||
* parameters:
|
||||
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
@@ -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