fix build and pass lint
This commit is contained in:
1 parent
3366627835
commit
5aa0b37443
30 files changed
+193
-74
No files matched your search
@@ -120,21 +120,21 @@ We aim to provide a fully tested API for our peace of mind, this is accomplished
|
|||||||
|
|
||||||
## Endpoints matrix
|
## Endpoints matrix
|
||||||
|
|
||||||
| resource | get [id] | get all | create | edit | delete |
|
| resource | get [id] | get all | create | edit | delete |
|
||||||
| ------------------------ | -------- | ------- | ------ | ---- | ------ |
|
| --------------------- | -------- | ------- | ------ | ---- | ------ |
|
||||||
| attendees | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| attendees | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| availabilities | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| availabilities | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| booking-references | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| booking-references | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| event-references | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| event-references | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| destination-calendars | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| destination-calendars | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| custom-inputs | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| custom-inputs | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| event-types | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| event-types | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| memberships | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| memberships | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| payments | ✅ | ✅ | ❌ | ❌ | ❌ |
|
| payments | ✅ | ✅ | ❌ | ❌ | ❌ |
|
||||||
| schedules | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| schedules | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| selected-calendars | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| selected-calendars | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| teams | ✅ | ✅ | ✅ | ✅ | ✅ |
|
| teams | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||||
| users | ✅ | 👤[1] | ✅ | ✅ | ✅ |
|
| users | ✅ | 👤[1] | ✅ | ✅ | ✅ |
|
||||||
|
|
||||||
## Models from database that are not exposed
|
## Models from database that are not exposed
|
||||||
|
|
||||||
|
|||||||
@@ -1,51 +1,92 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { _EventTypeModel as EventType } from "@calcom/prisma/zod";
|
import { _EventTypeModel as EventType } from "@calcom/prisma/zod";
|
||||||
|
import { eventTypeLocations, recurringEvent } from "@calcom/prisma/zod-utils";
|
||||||
|
|
||||||
|
import { jsonSchema } from "./shared/jsonSchema";
|
||||||
|
|
||||||
export const schemaEventTypeBaseBodyParams = EventType.pick({
|
export const schemaEventTypeBaseBodyParams = EventType.pick({
|
||||||
title: true,
|
title: true,
|
||||||
slug: true,
|
slug: true,
|
||||||
length: true,
|
length: true,
|
||||||
|
hidden: true,
|
||||||
|
position: true,
|
||||||
|
userId: true,
|
||||||
|
teamId: true,
|
||||||
|
eventName: true,
|
||||||
|
timeZone: true,
|
||||||
|
periodType: true,
|
||||||
|
periodStartDate: true,
|
||||||
|
periodEndDate: true,
|
||||||
|
periodDays: true,
|
||||||
|
periodCountCalendarDays: true,
|
||||||
|
requiresConfirmation: true,
|
||||||
|
disableGuests: true,
|
||||||
|
hideCalendarNotes: true,
|
||||||
|
minimumBookingNotice: true,
|
||||||
|
beforeEventBuffer: true,
|
||||||
|
afterEventBuffer: true,
|
||||||
|
schedulingType: true,
|
||||||
|
price: true,
|
||||||
|
currency: true,
|
||||||
|
slotInterval: true,
|
||||||
|
metadata: true,
|
||||||
|
successRedirectUrl: true,
|
||||||
}).partial();
|
}).partial();
|
||||||
|
|
||||||
const schemaEventTypeCreateParams = z
|
const schemaEventTypeBaseParams = z
|
||||||
.object({
|
.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
slug: z.string(),
|
slug: z.string(),
|
||||||
length: z.number(),
|
description: z.string().optional().nullable(),
|
||||||
|
length: z.number().int(),
|
||||||
|
locations: jsonSchema,
|
||||||
|
metadata: jsonSchema,
|
||||||
|
recurringEvent: jsonSchema,
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export const schemaEventTypeCreateBodyParams =
|
export const schemaEventTypeCreateBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeBaseParams);
|
||||||
schemaEventTypeBaseBodyParams.merge(schemaEventTypeCreateParams);
|
|
||||||
|
|
||||||
const schemaEventTypeEditParams = z
|
const schemaEventTypeEditParams = z
|
||||||
.object({
|
.object({
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
slug: z.string().optional(),
|
slug: z.string().optional(),
|
||||||
length: z.number().optional(),
|
length: z.number().int().optional(),
|
||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
export const schemaEventTypeEditBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeEditParams);
|
export const schemaEventTypeEditBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeEditParams);
|
||||||
export const schemaEventTypeReadPublic = EventType.pick({
|
export const schemaEventTypeReadPublic = EventType.pick({
|
||||||
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
slug: true,
|
slug: true,
|
||||||
length: true,
|
length: true,
|
||||||
});
|
locations: true,
|
||||||
|
hidden: true,
|
||||||
// import { z } from "zod";
|
position: true,
|
||||||
|
userId: true,
|
||||||
// import { _EventTypeModel as EventType } from "@calcom/prisma/zod";
|
teamId: true,
|
||||||
|
eventName: true,
|
||||||
// export const schemaEventTypeBaseBodyParams = EventType.omit({ id: true }).partial();
|
timeZone: true,
|
||||||
|
periodType: true,
|
||||||
// const schemaEventTypeRequiredParams = z.object({
|
periodStartDate: true,
|
||||||
// title: z.string(),
|
periodEndDate: true,
|
||||||
// slug: z.string(),
|
periodDays: true,
|
||||||
// length: z.number(),
|
periodCountCalendarDays: true,
|
||||||
// });
|
requiresConfirmation: true,
|
||||||
|
recurringEvent: true,
|
||||||
// export const schemaEventTypeBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeRequiredParams);
|
disableGuests: true,
|
||||||
// // @NOTE: Removing locations and metadata properties before validation, add them later if required
|
hideCalendarNotes: true,
|
||||||
// export const schemaEventTypePublic = EventType.omit({ locations: true, metadata: true });
|
minimumBookingNotice: true,
|
||||||
|
beforeEventBuffer: true,
|
||||||
|
afterEventBuffer: true,
|
||||||
|
schedulingType: true,
|
||||||
|
price: true,
|
||||||
|
currency: true,
|
||||||
|
slotInterval: true,
|
||||||
|
metadata: true,
|
||||||
|
successRedirectUrl: true,
|
||||||
|
})
|
||||||
|
.merge(schemaEventTypeBaseParams)
|
||||||
|
.partial();
|
||||||
@@ -4,6 +4,8 @@ import { _UserModel as User } from "@calcom/prisma/zod";
|
|||||||
|
|
||||||
import { timeZone } from "@lib/validations/shared/timeZone";
|
import { timeZone } from "@lib/validations/shared/timeZone";
|
||||||
|
|
||||||
|
import { jsonSchema } from "./shared/jsonSchema";
|
||||||
|
|
||||||
// @note: These are the ONLY values allowed as weekStart. So user don't introduce bad data.
|
// @note: These are the ONLY values allowed as weekStart. So user don't introduce bad data.
|
||||||
enum weekdays {
|
enum weekdays {
|
||||||
MONDAY = "Monday",
|
MONDAY = "Monday",
|
||||||
@@ -57,6 +59,7 @@ export const schemaUserBaseBodyParams = User.pick({
|
|||||||
timeZone: true,
|
timeZone: true,
|
||||||
weekStart: true,
|
weekStart: true,
|
||||||
endTime: true,
|
endTime: true,
|
||||||
|
metadata: true,
|
||||||
bufferTime: true,
|
bufferTime: true,
|
||||||
theme: true,
|
theme: true,
|
||||||
defaultScheduleId: true,
|
defaultScheduleId: true,
|
||||||
@@ -89,6 +92,7 @@ const schemaUserEditParams = z.object({
|
|||||||
.refine((id: number) => id > 0)
|
.refine((id: number) => id > 0)
|
||||||
.optional(),
|
.optional(),
|
||||||
locale: z.nativeEnum(locales).optional(),
|
locale: z.nativeEnum(locales).optional(),
|
||||||
|
metadata: jsonSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
// @note: These are the values that are editable via PATCH method on the user Model,
|
// @note: These are the values that are editable via PATCH method on the user Model,
|
||||||
@@ -104,6 +108,7 @@ export const schemaUserReadPublic = User.pick({
|
|||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
bio: true,
|
bio: true,
|
||||||
avatar: true,
|
avatar: true,
|
||||||
|
metadata: true,
|
||||||
timeZone: true,
|
timeZone: true,
|
||||||
weekStart: true,
|
weekStart: true,
|
||||||
endTime: true,
|
endTime: true,
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"name": "@calcom/api",
|
"name": "@calcom/api",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Public API for Cal.com",
|
"description": "Public API for Cal.com",
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next build && PORT=3002 next start",
|
"dev": "next build && PORT=3002 next start",
|
||||||
"dev-real":"PORT=3002 next dev",
|
"dev-real": "PORT=3002 next dev",
|
||||||
"start": "PORT=3002 next start",
|
"start": "PORT=3002 next start",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ export async function bookingReferenceById(
|
|||||||
console.log(safeBody.error);
|
console.log(safeBody.error);
|
||||||
res.status(400).json({ message: "Invalid request body", error: safeBody.error });
|
res.status(400).json({ message: "Invalid request body", error: safeBody.error });
|
||||||
return;
|
return;
|
||||||
// throw new Error("Invalid request body");
|
|
||||||
}
|
}
|
||||||
await prisma.bookingReference
|
await prisma.bookingReference
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -97,17 +97,7 @@ async function createOrlistAllBookingReferences(
|
|||||||
if (!safe.success) {
|
if (!safe.success) {
|
||||||
res.status(400).json({ message: "Bad request. BookingReference body is invalid", error: safe.error });
|
res.status(400).json({ message: "Bad request. BookingReference body is invalid", error: safe.error });
|
||||||
return;
|
return;
|
||||||
// throw new Error("Invalid request body");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const userWithBookings = await prisma.user.findUnique({
|
|
||||||
where: { id: userId },
|
|
||||||
include: { bookings: true },
|
|
||||||
});
|
|
||||||
if (!userWithBookings) {
|
|
||||||
throw new Error("User not found");
|
|
||||||
}
|
|
||||||
const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
|
|
||||||
if (!safe.data.bookingId) throw new Error("BookingReference: bookingId not found");
|
if (!safe.data.bookingId) throw new Error("BookingReference: bookingId not found");
|
||||||
if (!userBookingIds.includes(safe.data.bookingId)) res.status(401).json({ message: "Unauthorized" });
|
if (!userBookingIds.includes(safe.data.bookingId)) res.status(401).json({ message: "Unauthorized" });
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ export async function bookingById(
|
|||||||
console.log(safeBody.error);
|
console.log(safeBody.error);
|
||||||
res.status(400).json({ message: "Bad request", error: safeBody.error });
|
res.status(400).json({ message: "Bad request", error: safeBody.error });
|
||||||
return;
|
return;
|
||||||
// throw new Error("Invalid request body");
|
|
||||||
}
|
}
|
||||||
await prisma.booking
|
await prisma.booking
|
||||||
.update({
|
.update({
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ async function createOrlistAllBookings(
|
|||||||
console.log(safe.error);
|
console.log(safe.error);
|
||||||
res.status(400).json({ message: "Bad request. Booking body is invalid." });
|
res.status(400).json({ message: "Bad request. Booking body is invalid." });
|
||||||
return;
|
return;
|
||||||
// throw new Error("Invalid request body");
|
|
||||||
}
|
}
|
||||||
safe.data.userId = userId;
|
safe.data.userId = userId;
|
||||||
const data = await prisma.booking.create({ data: { ...safe.data } });
|
const data = await prisma.booking.create({ data: { ...safe.data } });
|
||||||
|
|||||||
@@ -105,7 +105,10 @@ async function eventTypeById(
|
|||||||
|
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.eventTypeCustomInput
|
await prisma.eventTypeCustomInput
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -59,7 +59,10 @@ async function createOrlistAllEventTypeCustomInputs(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaEventTypeCustomInputBodyParams.safeParse(body);
|
const safe = schemaEventTypeCustomInputBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Since we're supporting a create or connect relation on eventType, we need to treat them differently
|
// Since we're supporting a create or connect relation on eventType, we need to treat them differently
|
||||||
// When using connect on event type, check if userId is the owner of the event
|
// When using connect on event type, check if userId is the owner of the event
|
||||||
if (safe.data.eventType.connect && !userEventTypes.includes(safe.data.eventType.connect.id as number)) {
|
if (safe.data.eventType.connect && !userEventTypes.includes(safe.data.eventType.connect.id as number)) {
|
||||||
|
|||||||
@@ -121,7 +121,10 @@ export async function destionationCalendarById(
|
|||||||
*/
|
*/
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.destinationCalendar
|
await prisma.destinationCalendar
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ async function createOrlistAllDestinationCalendars(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaDestinationCalendarCreateBodyParams.safeParse(body);
|
const safe = schemaDestinationCalendarCreateBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.destinationCalendar.create({ data: { ...safe.data, userId } });
|
const data = await prisma.destinationCalendar.create({ data: { ...safe.data, userId } });
|
||||||
const destination_calendar = schemaDestinationCalendarReadPublic.parse(data);
|
const destination_calendar = schemaDestinationCalendarReadPublic.parse(data);
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ export async function dailyEventReferenceById(
|
|||||||
*/
|
*/
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.dailyEventReference
|
await prisma.dailyEventReference
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -64,7 +64,10 @@ async function createOrlistAllDailyEventReferences(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(body);
|
const safe = schemaDailyEventReferenceCreateBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.dailyEventReference.create({ data: safe.data });
|
const data = await prisma.dailyEventReference.create({ data: safe.data });
|
||||||
const daily_event_reference = schemaDailyEventReferenceReadPublic.parse(data);
|
const daily_event_reference = schemaDailyEventReferenceReadPublic.parse(data);
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ export async function eventTypeById(
|
|||||||
case "PATCH":
|
case "PATCH":
|
||||||
const safeBody = schemaEventTypeEditBodyParams.safeParse(body);
|
const safeBody = schemaEventTypeEditBodyParams.safeParse(body);
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.eventType
|
await prisma.eventType
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ async function createOrlistAllEventTypes(
|
|||||||
* /event-types:
|
* /event-types:
|
||||||
* get:
|
* get:
|
||||||
* summary: Find all event types
|
* summary: Find all event types
|
||||||
|
* operationId: listEventTypes
|
||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
@@ -43,6 +44,32 @@ async function createOrlistAllEventTypes(
|
|||||||
* /event-types:
|
* /event-types:
|
||||||
* post:
|
* post:
|
||||||
* summary: Creates a new event type
|
* summary: Creates a new event type
|
||||||
|
* operationId: addEventType
|
||||||
|
* requestBody:
|
||||||
|
* description: Create a new event-type related to your user or team
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* required:
|
||||||
|
* - title
|
||||||
|
* - slug
|
||||||
|
* - length
|
||||||
|
* - metadata
|
||||||
|
* properties:
|
||||||
|
* length:
|
||||||
|
* type: number
|
||||||
|
* example: 30
|
||||||
|
* metadata:
|
||||||
|
* type: object
|
||||||
|
* example: {"smartContractAddress": "0x1234567890123456789012345678901234567890"}
|
||||||
|
* title:
|
||||||
|
* type: string
|
||||||
|
* example: My Event
|
||||||
|
* slug:
|
||||||
|
* type: string
|
||||||
|
* example: my-event
|
||||||
* tags:
|
* tags:
|
||||||
* - event-types
|
* - event-types
|
||||||
* externalDocs:
|
* externalDocs:
|
||||||
@@ -56,7 +83,10 @@ async function createOrlistAllEventTypes(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaEventTypeCreateBodyParams.safeParse(body);
|
const safe = schemaEventTypeCreateBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body", error: safe.error });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.eventType.create({ data: { ...safe.data, userId } });
|
const data = await prisma.eventType.create({ data: { ...safe.data, userId } });
|
||||||
const event_type = schemaEventTypeReadPublic.parse(data);
|
const event_type = schemaEventTypeReadPublic.parse(data);
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ export async function WebhookById(
|
|||||||
case "PATCH":
|
case "PATCH":
|
||||||
const safeBody = schemaWebhookEditBodyParams.safeParse(body);
|
const safeBody = schemaWebhookEditBodyParams.safeParse(body);
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.webhook
|
await prisma.webhook
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -56,7 +56,10 @@ async function createOrlistAllWebhooks(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaWebhookCreateBodyParams.safeParse(body);
|
const safe = schemaWebhookCreateBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.webhook.create({ data: { ...safe.data, userId } });
|
const data = await prisma.webhook.create({ data: { ...safe.data, userId } });
|
||||||
const webhook = schemaWebhookReadPublic.parse(data);
|
const webhook = schemaWebhookReadPublic.parse(data);
|
||||||
|
|||||||
@@ -97,7 +97,10 @@ export async function membershipById(
|
|||||||
case "PATCH":
|
case "PATCH":
|
||||||
const safeBody = schemaMembershipBodyParams.safeParse(body);
|
const safeBody = schemaMembershipBodyParams.safeParse(body);
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.membership
|
await prisma.membership
|
||||||
.update({
|
.update({
|
||||||
|
|||||||
@@ -52,7 +52,10 @@ async function createOrlistAllMemberships(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaMembershipBodyParams.safeParse(body);
|
const safe = schemaMembershipBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = await prisma.membership.create({ data: { ...safe.data, userId } });
|
const data = await prisma.membership.create({ data: { ...safe.data, userId } });
|
||||||
const membership = schemaMembershipPublic.parse(data);
|
const membership = schemaMembershipPublic.parse(data);
|
||||||
|
|||||||
@@ -83,7 +83,10 @@ export async function scheduleById(
|
|||||||
*/
|
*/
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.schedule
|
await prisma.schedule
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ async function createOrlistAllSchedules(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaScheduleBodyParams.safeParse(body);
|
const safe = schemaScheduleBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = await prisma.schedule.create({ data: { ...safe.data, userId } });
|
const data = await prisma.schedule.create({ data: { ...safe.data, userId } });
|
||||||
const schedule = schemaSchedulePublic.parse(data);
|
const schedule = schemaSchedulePublic.parse(data);
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,10 @@ export async function selectedCalendarById(
|
|||||||
*/
|
*/
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.selectedCalendar
|
await prisma.selectedCalendar
|
||||||
.update({
|
.update({
|
||||||
|
|||||||
@@ -70,7 +70,10 @@ async function createOrlistAllSelectedCalendars(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaSelectedCalendarBodyParams.safeParse(body);
|
const safe = schemaSelectedCalendarBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Create new selectedCalendar connecting it to current userId
|
// Create new selectedCalendar connecting it to current userId
|
||||||
const data = await prisma.selectedCalendar.create({
|
const data = await prisma.selectedCalendar.create({
|
||||||
data: { ...safe.data, user: { connect: { id: userId } } },
|
data: { ...safe.data, user: { connect: { id: userId } } },
|
||||||
|
|||||||
@@ -102,7 +102,10 @@ export async function teamById(
|
|||||||
|
|
||||||
case "PATCH":
|
case "PATCH":
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
throw new Error("Invalid request body");
|
{
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await prisma.team
|
await prisma.team
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
||||||
|
|||||||
@@ -58,7 +58,10 @@ async function createOrlistAllTeams(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaTeamBodyParams.safeParse(body);
|
const safe = schemaTeamBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const team = await prisma.team.create({ data: safe.data });
|
const team = await prisma.team.create({ data: safe.data });
|
||||||
// We're also creating the relation membership of team ownership in this call.
|
// We're also creating the relation membership of team ownership in this call.
|
||||||
const membership = await prisma.membership
|
const membership = await prisma.membership
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export async function userById(
|
|||||||
const safeBody = schemaUserEditBodyParams.safeParse(body);
|
const safeBody = schemaUserEditBodyParams.safeParse(body);
|
||||||
if (!safeBody.success) {
|
if (!safeBody.success) {
|
||||||
res.status(400).json({ message: "Bad request", error: safeBody.error });
|
res.status(400).json({ message: "Bad request", error: safeBody.error });
|
||||||
// throw new Error("Invalid request body");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const userSchedules = await prisma.schedule.findMany({
|
const userSchedules = await prisma.schedule.findMany({
|
||||||
|
|||||||
@@ -56,7 +56,10 @@ async function createOrlistAllPayments(
|
|||||||
* description: Authorization information is missing or invalid.
|
* description: Authorization information is missing or invalid.
|
||||||
*/
|
*/
|
||||||
const safe = schemaPaymentBodyParams.safeParse(body);
|
const safe = schemaPaymentBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const payment = await prisma.payment.create({ data: safe.data });
|
const payment = await prisma.payment.create({ data: safe.data });
|
||||||
const data = schemaPaymentPublic.parse(payment);
|
const data = schemaPaymentPublic.parse(payment);
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ import { schemaResourceBodyParams, schemaResourcePublic, withValidResource } fro
|
|||||||
*/
|
*/
|
||||||
async function createResource({body}: NextApiRequest, res: NextApiResponse<ResourceResponse>) {
|
async function createResource({body}: NextApiRequest, res: NextApiResponse<ResourceResponse>) {
|
||||||
const safe = schemaResourceBodyParams.safeParse(body);
|
const safe = schemaResourceBodyParams.safeParse(body);
|
||||||
if (!safe.success) throw new Error("Invalid request body");
|
if (!safe.success) {
|
||||||
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const resource = await prisma.resource.create({ data: safe.data });
|
const resource = await prisma.resource.create({ data: safe.data });
|
||||||
const data = schemaResourcePublic.parse(resource);
|
const data = schemaResourcePublic.parse(resource);
|
||||||
|
|||||||
Vendored
-1
@@ -1,2 +1 @@
|
|||||||
declare module "modify-response-middleware";
|
declare module "modify-response-middleware";
|
||||||
|
|
||||||
Reference in new issue
Block a user