fix: booking reference moved to pick-first create/edit separate validations
This commit is contained in:
1 parent
6997606a4c
commit
14e2964a6d
8 files changed
+85
-56
No files matched your search
@@ -4,7 +4,10 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { AvailabilityResponse } from "@lib/types";
|
||||
import { schemaAvailabilityEditBodyParams, schemaAvailabilityReadPublic } from "@lib/validations/availability";
|
||||
import {
|
||||
schemaAvailabilityEditBodyParams,
|
||||
schemaAvailabilityReadPublic,
|
||||
} from "@lib/validations/availability";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
withValidQueryIdTransformParseInt,
|
||||
|
||||
@@ -4,7 +4,10 @@ import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { AvailabilityResponse, AvailabilitiesResponse } from "@lib/types";
|
||||
import { schemaAvailabilityCreateBodyParams, schemaAvailabilityReadPublic } from "@lib/validations/availability";
|
||||
import {
|
||||
schemaAvailabilityCreateBodyParams,
|
||||
schemaAvailabilityReadPublic,
|
||||
} from "@lib/validations/availability";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
|
||||
@@ -6,8 +6,8 @@ import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { BookingReferenceResponse } from "@lib/types";
|
||||
import {
|
||||
schemaBookingReferenceBodyParams,
|
||||
schemaBookingReferencePublic,
|
||||
schemaBookingEditBodyParams,
|
||||
schemaBookingReferenceReadPublic,
|
||||
} from "@lib/validations/booking-reference";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
@@ -18,14 +18,14 @@ import {
|
||||
* @swagger
|
||||
* /booking-references/{id}:
|
||||
* get:
|
||||
* summary: Get a daily event reference by ID
|
||||
* summary: Get a booking reference by ID
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric ID of the daily event reference to get
|
||||
* description: Numeric ID of the booking reference to get
|
||||
* security:
|
||||
* - ApiKeyAuth: []
|
||||
* tags:
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
* 404:
|
||||
* description: BookingReference was not found
|
||||
* patch:
|
||||
* summary: Edit an existing daily event reference
|
||||
* summary: Edit an existing booking reference
|
||||
* consumes:
|
||||
* - application/json
|
||||
* parameters:
|
||||
@@ -54,7 +54,7 @@ import {
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric ID of the daily event reference to edit
|
||||
* description: Numeric ID of the booking reference to edit
|
||||
* security:
|
||||
* - ApiKeyAuth: []
|
||||
* tags:
|
||||
@@ -68,14 +68,14 @@ import {
|
||||
* 401:
|
||||
* description: Authorization information is missing or invalid.
|
||||
* delete:
|
||||
* summary: Remove an existing daily event reference
|
||||
* summary: Remove an existing booking reference
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* schema:
|
||||
* type: integer
|
||||
* required: true
|
||||
* description: Numeric ID of the daily event reference to delete
|
||||
* description: Numeric ID of the booking reference to delete
|
||||
* security:
|
||||
* - ApiKeyAuth: []
|
||||
* tags:
|
||||
@@ -95,7 +95,6 @@ export async function bookingReferenceById(
|
||||
) {
|
||||
const { method, query, body } = req;
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
const safeBody = schemaBookingReferenceBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
const userId = req.userId;
|
||||
const userWithBookings = await prisma.user.findUnique({
|
||||
@@ -111,7 +110,7 @@ export async function bookingReferenceById(
|
||||
case "GET":
|
||||
await prisma.bookingReference
|
||||
.findUnique({ where: { id: safeQuery.data.id } })
|
||||
.then((data) => schemaBookingReferencePublic.parse(data))
|
||||
.then((data) => schemaBookingReferenceReadPublic.parse(data))
|
||||
.then((booking_reference) => res.status(200).json({ booking_reference }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({
|
||||
@@ -122,12 +121,14 @@ export async function bookingReferenceById(
|
||||
break;
|
||||
|
||||
case "PATCH":
|
||||
const safeBody = schemaBookingEditBodyParams.safeParse(body);
|
||||
|
||||
if (!safeBody.success) {
|
||||
throw new Error("Invalid request body");
|
||||
}
|
||||
await prisma.bookingReference
|
||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||
.then((data) => schemaBookingReferencePublic.parse(data))
|
||||
.then((data) => schemaBookingReferenceReadPublic.parse(data))
|
||||
.then((booking_reference) => res.status(200).json({ booking_reference }))
|
||||
.catch((error: Error) =>
|
||||
res.status(404).json({
|
||||
|
||||
@@ -5,8 +5,8 @@ import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { BookingReferenceResponse, BookingReferencesResponse } from "@lib/types";
|
||||
import {
|
||||
schemaBookingReferenceBodyParams,
|
||||
schemaBookingReferencePublic,
|
||||
schemaBookingCreateBodyParams,
|
||||
schemaBookingReferenceReadPublic,
|
||||
} from "@lib/validations/booking-reference";
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ async function createOrlistAllBookingReferences(
|
||||
if (method === "GET") {
|
||||
const data = await prisma.bookingReference.findMany({ where: { id: { in: userBookingIds } } });
|
||||
const booking_references = data.map((bookingReference) =>
|
||||
schemaBookingReferencePublic.parse(bookingReference)
|
||||
schemaBookingReferenceReadPublic.parse(bookingReference)
|
||||
);
|
||||
if (booking_references) res.status(200).json({ booking_references });
|
||||
else
|
||||
@@ -65,7 +65,7 @@ async function createOrlistAllBookingReferences(
|
||||
error,
|
||||
});
|
||||
} else if (method === "POST") {
|
||||
const safe = schemaBookingReferenceBodyParams.safeParse(req.body);
|
||||
const safe = schemaBookingCreateBodyParams.safeParse(req.body);
|
||||
if (!safe.success) {
|
||||
throw new Error("Invalid request body");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user