Extract prisma to it's own package (#1823)
* Moved prisma to packages * Add missing prisma configs * Extracts common libs and types * Build and pipeline fixes * Adds missing package * Prisma scripts cleanup * Updates lint staged * Type fixes * Sort imports * Updates yarn lock file * Fixes for yarn dx * Revert "Sort imports" This reverts commit 076109decab9b9ba307fc03696c3b0da5c4896f3. * Formatting * Prevent double TS version * Fix conflict * Extracted e2e configs
This commit is contained in:
1 parent
fdf7516cdd
commit
fe35cf6570
128 files changed
+349
-223
No files matched your search
@@ -0,0 +1,11 @@
|
||||
import { compare, hash } from "bcryptjs";
|
||||
|
||||
export async function hashPassword(password: string) {
|
||||
const hashedPassword = await hash(password, 12);
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
export async function verifyPassword(password: string, hashedPassword: string) {
|
||||
const isValid = await compare(password, hashedPassword);
|
||||
return isValid;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import dayjs, { ConfigType } from "dayjs";
|
||||
import customParseFormat from "dayjs/plugin/customParseFormat";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
|
||||
import type { Availability } from "@calcom/prisma/client";
|
||||
import type { Schedule, TimeRange, WorkingHours } from "@calcom/types/schedule";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
dayjs.extend(customParseFormat);
|
||||
// sets the desired time in current date, needs to be current date for proper DST translation
|
||||
export const defaultDayRange: TimeRange = {
|
||||
start: new Date(new Date().setUTCHours(9, 0, 0, 0)),
|
||||
end: new Date(new Date().setUTCHours(17, 0, 0, 0)),
|
||||
};
|
||||
|
||||
export const DEFAULT_SCHEDULE: Schedule = [
|
||||
[],
|
||||
[defaultDayRange],
|
||||
[defaultDayRange],
|
||||
[defaultDayRange],
|
||||
[defaultDayRange],
|
||||
[defaultDayRange],
|
||||
[],
|
||||
];
|
||||
|
||||
export function getAvailabilityFromSchedule(schedule: Schedule): Availability[] {
|
||||
return schedule.reduce((availability: Availability[], times: TimeRange[], day: number) => {
|
||||
const addNewTime = (time: TimeRange) =>
|
||||
({
|
||||
days: [day],
|
||||
startTime: time.start,
|
||||
endTime: time.end,
|
||||
} as Availability);
|
||||
|
||||
const filteredTimes = times.filter((time) => {
|
||||
let idx;
|
||||
if (
|
||||
(idx = availability.findIndex(
|
||||
(schedule) => schedule.startTime === time.start && schedule.endTime === time.end
|
||||
)) !== -1
|
||||
) {
|
||||
availability[idx].days.push(day);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
filteredTimes.forEach((time) => {
|
||||
availability.push(addNewTime(time));
|
||||
});
|
||||
return availability;
|
||||
}, [] as Availability[]);
|
||||
}
|
||||
|
||||
export const MINUTES_IN_DAY = 60 * 24;
|
||||
export const MINUTES_DAY_END = MINUTES_IN_DAY - 1;
|
||||
export const MINUTES_DAY_START = 0;
|
||||
|
||||
/**
|
||||
* Allows "casting" availability (days, startTime, endTime) given in UTC to a timeZone or utcOffset
|
||||
*/
|
||||
export function getWorkingHours(
|
||||
relativeTimeUnit: {
|
||||
timeZone?: string;
|
||||
utcOffset?: number;
|
||||
},
|
||||
availability: { days: number[]; startTime: ConfigType; endTime: ConfigType }[]
|
||||
) {
|
||||
// clearly bail when availability is not set, set everything available.
|
||||
if (!availability.length) {
|
||||
return [
|
||||
{
|
||||
days: [0, 1, 2, 3, 4, 5, 6],
|
||||
// shorthand for: dayjs().startOf("day").tz(timeZone).diff(dayjs.utc().startOf("day"), "minutes")
|
||||
startTime: MINUTES_DAY_START,
|
||||
endTime: MINUTES_DAY_END,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const utcOffset = relativeTimeUnit.utcOffset ?? dayjs().tz(relativeTimeUnit.timeZone).utcOffset();
|
||||
|
||||
const workingHours = availability.reduce((workingHours: WorkingHours[], schedule) => {
|
||||
// Get times localised to the given utcOffset/timeZone
|
||||
const startTime =
|
||||
dayjs.utc(schedule.startTime).get("hour") * 60 +
|
||||
dayjs.utc(schedule.startTime).get("minute") -
|
||||
utcOffset;
|
||||
const endTime =
|
||||
dayjs.utc(schedule.endTime).get("hour") * 60 + dayjs.utc(schedule.endTime).get("minute") - utcOffset;
|
||||
|
||||
// add to working hours, keeping startTime and endTimes between bounds (0-1439)
|
||||
const sameDayStartTime = Math.max(MINUTES_DAY_START, Math.min(MINUTES_DAY_END, startTime));
|
||||
const sameDayEndTime = Math.max(MINUTES_DAY_START, Math.min(MINUTES_DAY_END, endTime));
|
||||
if (sameDayStartTime !== sameDayEndTime) {
|
||||
workingHours.push({
|
||||
days: schedule.days,
|
||||
startTime: sameDayStartTime,
|
||||
endTime: sameDayEndTime,
|
||||
});
|
||||
}
|
||||
// check for overflow to the previous day
|
||||
if (startTime < MINUTES_DAY_START || endTime < MINUTES_DAY_START) {
|
||||
workingHours.push({
|
||||
days: schedule.days.map((day) => day - 1),
|
||||
startTime: startTime + MINUTES_IN_DAY,
|
||||
endTime: Math.min(endTime + MINUTES_IN_DAY, MINUTES_DAY_END),
|
||||
});
|
||||
}
|
||||
// else, check for overflow in the next day
|
||||
else if (startTime > MINUTES_DAY_END || endTime > MINUTES_DAY_END) {
|
||||
workingHours.push({
|
||||
days: schedule.days.map((day) => day + 1),
|
||||
startTime: Math.max(startTime - MINUTES_IN_DAY, MINUTES_DAY_START),
|
||||
endTime: endTime - MINUTES_IN_DAY,
|
||||
});
|
||||
}
|
||||
|
||||
return workingHours;
|
||||
}, []);
|
||||
|
||||
workingHours.sort((a, b) => a.startTime - b.startTime);
|
||||
|
||||
return workingHours;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export enum LocationType {
|
||||
InPerson = "inPerson",
|
||||
Phone = "phone",
|
||||
GoogleMeet = "integrations:google:meet",
|
||||
Zoom = "integrations:zoom",
|
||||
Daily = "integrations:daily",
|
||||
Jitsi = "integrations:jitsi",
|
||||
Huddle01 = "integrations:huddle01",
|
||||
Tandem = "integrations:tandem",
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@calcom/lib",
|
||||
"version": "0.0.0",
|
||||
"main": "./index.ts",
|
||||
"types": "./index.ts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bcryptjs": "^2.4.3",
|
||||
"dayjs": "^1.10.6",
|
||||
"dayjs-business-time": "^1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@calcom/tsconfig": "*",
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "@calcom/tsconfig/base.json",
|
||||
"include": ["."],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# DATABASE_URL='postgresql://<user>:<pass>@<db-host>:<db-port>/<db-name>'
|
||||
DATABASE_URL="postgresql://postgres:@localhost:5450/calendso"
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export * from ".prisma/client/index.d";
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export * from "@prisma/client/runtime";
|
||||
@@ -0,0 +1,27 @@
|
||||
# this file is a helper to run Cal.com locally
|
||||
# starts a postgres instance on port 5450 to use as a local db
|
||||
version: "3.6"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
ports:
|
||||
- "5450:5432" # expose pg on port 5450 to not collide with pg from elswhere
|
||||
restart: always
|
||||
volumes:
|
||||
- db_data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_DB: "cal-saml"
|
||||
POSTGRES_PASSWORD: ""
|
||||
POSTGRES_HOST_AUTH_METHOD: trust
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
postgres_is_ready:
|
||||
image: postgres
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
db_data:
|
||||
@@ -0,0 +1,13 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
export const prisma =
|
||||
globalThis.prisma ||
|
||||
new PrismaClient({
|
||||
log: ["query", "error", "warn"],
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
globalThis.prisma = prisma;
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
@@ -0,0 +1,50 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "EventType" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"slug" TEXT NOT NULL,
|
||||
"description" TEXT,
|
||||
"locations" JSONB,
|
||||
"length" INTEGER NOT NULL,
|
||||
"hidden" BOOLEAN NOT NULL DEFAULT false,
|
||||
"userId" INTEGER,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Credential" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"key" JSONB NOT NULL,
|
||||
"userId" INTEGER,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "users" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"username" TEXT,
|
||||
"name" TEXT,
|
||||
"email" TEXT,
|
||||
"password" TEXT,
|
||||
"bio" TEXT,
|
||||
"avatar" TEXT,
|
||||
"timeZone" TEXT NOT NULL DEFAULT E'Europe/London',
|
||||
"weekStart" TEXT DEFAULT E'Sunday',
|
||||
"startTime" INTEGER NOT NULL DEFAULT 0,
|
||||
"endTime" INTEGER NOT NULL DEFAULT 1440,
|
||||
"created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users.email_unique" ON "users"("email");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "EventType" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Credential" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,48 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "BookingReference" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"uid" TEXT NOT NULL,
|
||||
"bookingId" INTEGER,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Attendee" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"timeZone" TEXT NOT NULL,
|
||||
"bookingId" INTEGER,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Booking" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uid" TEXT NOT NULL,
|
||||
"userId" INTEGER,
|
||||
"eventTypeId" INTEGER,
|
||||
"title" TEXT NOT NULL,
|
||||
"description" TEXT,
|
||||
"startTime" TIMESTAMP(3) NOT NULL,
|
||||
"endTime" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3),
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Attendee" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Booking" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Booking" ADD FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BookingReference" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[uid]` on the table `Booking` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Booking.uid_unique" ON "Booking"("uid");
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "MembershipRole" AS ENUM ('MEMBER', 'OWNER');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Team" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"name" TEXT,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Membership" (
|
||||
"teamId" INTEGER NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"accepted" BOOLEAN NOT NULL DEFAULT false,
|
||||
"role" "MembershipRole" NOT NULL,
|
||||
|
||||
PRIMARY KEY ("userId","teamId")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Membership" ADD FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Membership" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,11 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "SelectedCalendar" (
|
||||
"userId" INTEGER NOT NULL,
|
||||
"integration" TEXT NOT NULL,
|
||||
"externalId" TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY ("userId","integration","externalId")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "SelectedCalendar" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "eventName" TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "bufferTime" INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,20 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "emailVerified" TIMESTAMP(3);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "VerificationRequest" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"identifier" TEXT NOT NULL,
|
||||
"token" TEXT NOT NULL,
|
||||
"expires" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "VerificationRequest.token_unique" ON "VerificationRequest"("token");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "VerificationRequest.identifier_token_unique" ON "VerificationRequest"("identifier", "token");
|
||||
@@ -0,0 +1,13 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "EventTypeCustomInput" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"eventTypeId" INTEGER NOT NULL,
|
||||
"label" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL,
|
||||
"required" BOOLEAN NOT NULL,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "EventTypeCustomInput" ADD FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,10 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "ResetPasswordRequest" (
|
||||
"id" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
"expires" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "hideBranding" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -0,0 +1,22 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "timeZone" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Availability" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"label" TEXT,
|
||||
"userId" INTEGER,
|
||||
"eventTypeId" INTEGER,
|
||||
"days" INTEGER[],
|
||||
"startTime" INTEGER NOT NULL,
|
||||
"endTime" INTEGER NOT NULL,
|
||||
"date" DATE,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Availability" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Availability" ADD FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "theme" TEXT;
|
||||
@@ -0,0 +1,6 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "periodCountCalendarDays" BOOLEAN,
|
||||
ADD COLUMN "periodDays" INTEGER,
|
||||
ADD COLUMN "periodEndDate" TIMESTAMP(3),
|
||||
ADD COLUMN "periodStartDate" TIMESTAMP(3),
|
||||
ADD COLUMN "periodType" TEXT DEFAULT E'unlimited';
|
||||
@@ -0,0 +1,6 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Booking" ADD COLUMN "confirmed" BOOLEAN NOT NULL DEFAULT true,
|
||||
ADD COLUMN "rejected" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "requiresConfirmation" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ReminderType" AS ENUM ('PENDING_BOOKING_CONFIRMATION');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "ReminderMail" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"referenceId" INTEGER NOT NULL,
|
||||
"reminderType" "ReminderType" NOT NULL,
|
||||
"elapsedMinutes" INTEGER NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "minimumBookingNotice" INTEGER NOT NULL DEFAULT 120;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Booking" ADD COLUMN "location" TEXT;
|
||||
@@ -0,0 +1,35 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "PaymentType" AS ENUM ('STRIPE');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Booking" ADD COLUMN "paid" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "currency" TEXT NOT NULL DEFAULT E'usd',
|
||||
ADD COLUMN "price" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Payment" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uid" TEXT NOT NULL,
|
||||
"type" "PaymentType" NOT NULL,
|
||||
"bookingId" INTEGER NOT NULL,
|
||||
"amount" INTEGER NOT NULL,
|
||||
"fee" INTEGER NOT NULL,
|
||||
"currency" TEXT NOT NULL,
|
||||
"success" BOOLEAN NOT NULL,
|
||||
"refunded" BOOLEAN NOT NULL,
|
||||
"data" JSONB NOT NULL,
|
||||
"externalId" TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Payment.uid_unique" ON "Payment"("uid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Payment.externalId_unique" ON "Payment"("externalId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Payment" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Team" ADD COLUMN "slug" TEXT;
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "EventTypeCustomInputType" AS ENUM ('text', 'textLong', 'number', 'bool');
|
||||
|
||||
--- AlterTable
|
||||
ALTER TABLE "EventTypeCustomInput" RENAME COLUMN "type" TO "type_old";
|
||||
ALTER TABLE "EventTypeCustomInput" ADD COLUMN "type" "EventTypeCustomInputType";
|
||||
|
||||
-- UpdateTable
|
||||
UPDATE "EventTypeCustomInput" SET "type" = CAST( "type_old" AS "EventTypeCustomInputType" );
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventTypeCustomInput" ALTER COLUMN "type" SET NOT NULL;
|
||||
ALTER TABLE "EventTypeCustomInput" DROP COLUMN "type_old";
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventTypeCustomInput" ADD COLUMN "placeholder" TEXT NOT NULL DEFAULT E'';
|
||||
@@ -0,0 +1,4 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Team" ADD COLUMN "bio" TEXT,
|
||||
ADD COLUMN "hideBranding" BOOLEAN NOT NULL DEFAULT false,
|
||||
ADD COLUMN "logo" TEXT;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "completedOnboarding" BOOLEAN DEFAULT false;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Schedule" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"userId" INTEGER,
|
||||
"eventTypeId" INTEGER,
|
||||
"title" TEXT,
|
||||
"freeBusyTimes" JSONB,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Schedule" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Schedule" ADD FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[slug]` on the table `Team` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Team.slug_unique" ON "Team"("slug");
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[userId,slug]` on the table `EventType` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "EventType.userId_slug_unique" ON "EventType"("userId", "slug");
|
||||
@@ -0,0 +1,5 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "UserPlan" AS ENUM ('FREE', 'TRIAL', 'PRO');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "plan" "UserPlan" NOT NULL DEFAULT E'PRO';
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[username]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users.username_unique" ON "users"("username");
|
||||
@@ -0,0 +1,5 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "BookingStatus" AS ENUM ('cancelled', 'accepted', 'rejected', 'pending');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Booking" ADD COLUMN "status" "BookingStatus" NOT NULL DEFAULT E'accepted';
|
||||
@@ -0,0 +1,30 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "SchedulingType" AS ENUM ('roundRobin', 'collective');
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "EventType" DROP CONSTRAINT "EventType_userId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "schedulingType" "SchedulingType",
|
||||
ADD COLUMN "teamId" INTEGER;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "_user_eventtype" (
|
||||
"A" INTEGER NOT NULL,
|
||||
"B" INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "_user_eventtype_AB_unique" ON "_user_eventtype"("A", "B");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "_user_eventtype_B_index" ON "_user_eventtype"("B");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "EventType" ADD FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_user_eventtype" ADD FOREIGN KEY ("A") REFERENCES "EventType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "_user_eventtype" ADD FOREIGN KEY ("B") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,15 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "DailyEventReference" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"dailyurl" TEXT NOT NULL DEFAULT E'dailycallurl',
|
||||
"dailytoken" TEXT NOT NULL DEFAULT E'dailytoken',
|
||||
"bookingId" INTEGER,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "DailyEventReference_bookingId_unique" ON "DailyEventReference"("bookingId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DailyEventReference" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- DropIndex
|
||||
DROP INDEX "EventType.userId_slug_unique";
|
||||
@@ -0,0 +1,4 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "BookingReference" ADD COLUMN "meetingId" TEXT,
|
||||
ADD COLUMN "meetingPassword" TEXT,
|
||||
ADD COLUMN "meetingUrl" TEXT;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "twoFactorEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
ADD COLUMN "twoFactorSecret" TEXT;
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[userId,slug]` on the table `EventType` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "EventType.userId_slug_unique" ON "EventType"("userId", "slug");
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "locale" TEXT;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "disableGuests" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -0,0 +1,17 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "WebhookTriggerEvents" AS ENUM ('BOOKING_CREATED', 'BOOKING_RESCHEDULED', 'BOOKING_CANCELLED');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Webhook" (
|
||||
"id" TEXT NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"subscriberUrl" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"eventTriggers" "WebhookTriggerEvents"[],
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Webhook.id_unique" ON "Webhook"("id");
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Made the column `periodType` on table `EventType` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `email` on table `users` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `weekStart` on table `users` required. This step will fail if there are existing NULL values in that column.
|
||||
- Made the column `completedOnboarding` on table `users` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ALTER COLUMN "periodType" SET NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ALTER COLUMN "email" SET NOT NULL,
|
||||
ALTER COLUMN "weekStart" SET NOT NULL,
|
||||
ALTER COLUMN "completedOnboarding" SET NOT NULL;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Webhook" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1 @@
|
||||
UPDATE "Booking" SET "status" = 'rejected' WHERE "rejected" = TRUE;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
-- This is an empty migration.
|
||||
|
||||
ALTER TABLE "Availability" RENAME COLUMN "startTime" to "old_startTime";
|
||||
ALTER TABLE "Availability" RENAME COLUMN "endTime" to "old_endTime";
|
||||
ALTER TABLE "Availability" ADD COLUMN "startTime" TIME;
|
||||
ALTER TABLE "Availability" ADD COLUMN "endTime" TIME;
|
||||
|
||||
UPDATE "Availability" SET "startTime" = CAST(CONCAT(CAST(("old_startTime" / 60) AS text), ':00') AS time);
|
||||
UPDATE "Availability" SET "endTime" = CAST(CONCAT(CAST(("old_endTime" / 60) AS text), ':00') AS time);
|
||||
|
||||
ALTER TABLE "Availability" DROP COLUMN "old_startTime";
|
||||
ALTER TABLE "Availability" DROP COLUMN "old_endTime";
|
||||
ALTER TABLE "Availability" ALTER COLUMN "startTime" SET NOT NULL;
|
||||
ALTER TABLE "Availability" ALTER COLUMN "endTime" SET NOT NULL;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "position" INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "brandColor" TEXT NOT NULL DEFAULT E'#292929';
|
||||
UPDATE "users" SET "brandColor" = '#292929';
|
||||
@@ -0,0 +1,6 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "IdentityProvider" AS ENUM ('CAL', 'GOOGLE');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "identityProvider" "IdentityProvider" NOT NULL DEFAULT E'CAL',
|
||||
ADD COLUMN "identityProviderId" TEXT;
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The `periodType` column on the `EventType` table would be dropped and recreated. This will lead to data loss if there is data in the column.
|
||||
|
||||
*/
|
||||
-- CreateEnum
|
||||
CREATE TYPE "PeriodType" AS ENUM ('unlimited', 'rolling', 'range');
|
||||
|
||||
-- AlterTable
|
||||
|
||||
ALTER TABLE "EventType" RENAME COLUMN "periodType" to "old_periodType";
|
||||
ALTER TABLE "EventType" ADD COLUMN "periodType" "PeriodType" NOT NULL DEFAULT E'unlimited';
|
||||
|
||||
UPDATE "EventType" SET "periodType" = "old_periodType"::"PeriodType";
|
||||
ALTER TABLE "EventType" DROP COLUMN "old_periodType";
|
||||
@@ -0,0 +1,2 @@
|
||||
-- add the new value to the existing type
|
||||
ALTER TYPE "IdentityProvider" ADD VALUE 'SAML';
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
insert into "Availability" ("userId", "startTime", "endTime", "days")
|
||||
select
|
||||
id as "userId",
|
||||
CAST(CONCAT(CAST(("startTime") AS text), ' minute')::interval AS time) as "startTime",
|
||||
CAST(CONCAT(CAST(("endTime") AS text), ' minute')::interval AS time) as "endTime",
|
||||
ARRAY [0,1,2,3,4,5,6]
|
||||
from
|
||||
(
|
||||
select
|
||||
users.id,
|
||||
users."startTime",
|
||||
users."endTime",
|
||||
users."timeZone",
|
||||
count("Availability".id) as availability_count
|
||||
from users
|
||||
left join "Availability" on "Availability"."userId" = users.id
|
||||
group by users.id
|
||||
) usersWithAvailabilityNumber
|
||||
where availability_count < 1
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Webhook" ADD COLUMN "payloadTemplate" TEXT;
|
||||
@@ -0,0 +1,29 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "DestinationCalendar" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"integration" TEXT NOT NULL,
|
||||
"externalId" TEXT NOT NULL,
|
||||
"userId" INTEGER,
|
||||
"bookingId" INTEGER,
|
||||
"eventTypeId" INTEGER,
|
||||
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "DestinationCalendar.userId_unique" ON "DestinationCalendar"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "DestinationCalendar.bookingId_unique" ON "DestinationCalendar"("bookingId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "DestinationCalendar.eventTypeId_unique" ON "DestinationCalendar"("eventTypeId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DestinationCalendar" ADD FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DestinationCalendar" ADD FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DestinationCalendar" ADD FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterEnum
|
||||
ALTER TYPE "MembershipRole" ADD VALUE 'ADMIN';
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "invitedTo" INTEGER;
|
||||
@@ -0,0 +1,74 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "EventTypeCustomInput" DROP CONSTRAINT "EventTypeCustomInput_eventTypeId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_teamId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Payment" DROP CONSTRAINT "Payment_bookingId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "SelectedCalendar" DROP CONSTRAINT "SelectedCalendar_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_userId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "SelectedCalendar" ADD CONSTRAINT "SelectedCalendar_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "EventTypeCustomInput" ADD CONSTRAINT "EventTypeCustomInput_eventTypeId_fkey" FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Payment" ADD CONSTRAINT "Payment_bookingId_fkey" FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Booking.uid_unique" RENAME TO "Booking_uid_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "DestinationCalendar.bookingId_unique" RENAME TO "DestinationCalendar_bookingId_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "DestinationCalendar.eventTypeId_unique" RENAME TO "DestinationCalendar_eventTypeId_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "DestinationCalendar.userId_unique" RENAME TO "DestinationCalendar_userId_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "EventType.userId_slug_unique" RENAME TO "EventType_userId_slug_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Payment.externalId_unique" RENAME TO "Payment_externalId_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Payment.uid_unique" RENAME TO "Payment_uid_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Team.slug_unique" RENAME TO "Team_slug_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "VerificationRequest.identifier_token_unique" RENAME TO "VerificationRequest_identifier_token_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "VerificationRequest.token_unique" RENAME TO "VerificationRequest_token_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Webhook.id_unique" RENAME TO "Webhook_id_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "users.email_unique" RENAME TO "users_email_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "users.username_unique" RENAME TO "users_username_key";
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "slotInterval" INTEGER;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- UpdateTable
|
||||
UPDATE users SET email=LOWER(email);
|
||||
@@ -0,0 +1,38 @@
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Booking_uid_key" RENAME TO "Booking.uid_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "DestinationCalendar_bookingId_key" RENAME TO "DestinationCalendar.bookingId_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "DestinationCalendar_eventTypeId_key" RENAME TO "DestinationCalendar.eventTypeId_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "DestinationCalendar_userId_key" RENAME TO "DestinationCalendar.userId_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "EventType_userId_slug_key" RENAME TO "EventType.userId_slug_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Payment_externalId_key" RENAME TO "Payment.externalId_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Payment_uid_key" RENAME TO "Payment.uid_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Team_slug_key" RENAME TO "Team.slug_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "VerificationRequest_identifier_token_key" RENAME TO "VerificationRequest.identifier_token_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "VerificationRequest_token_key" RENAME TO "VerificationRequest.token_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "Webhook_id_key" RENAME TO "Webhook.id_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "users_email_key" RENAME TO "users.email_unique";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX "users_username_key" RENAME TO "users.username_unique";
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "scAddress" TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "metadata" JSONB;
|
||||
@@ -0,0 +1,35 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Availability" DROP CONSTRAINT "Availability_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Credential" DROP CONSTRAINT "Credential_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Schedule" DROP CONSTRAINT "Schedule_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "SelectedCalendar" DROP CONSTRAINT "SelectedCalendar_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_userId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Credential" ADD CONSTRAINT "Credential_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Schedule" ADD CONSTRAINT "Schedule_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Availability" ADD CONSTRAINT "Availability_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "SelectedCalendar" ADD CONSTRAINT "SelectedCalendar_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "away" BOOLEAN NOT NULL DEFAULT false;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" DROP COLUMN "scAddress",
|
||||
ADD COLUMN "smartContractAddress" TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ALTER COLUMN "plan" SET DEFAULT E'TRIAL';
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Booking" ADD COLUMN "cancellationReason" TEXT;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Attendee" ADD COLUMN "locale" TEXT DEFAULT E'en';
|
||||
+1
@@ -0,0 +1 @@
|
||||
ALTER TABLE "EventType" ADD COLUMN "metadata" JSONB;
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `smartContractAddress` on the `EventType` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" DROP COLUMN IF EXISTS "smartContractAddress";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "verified" BOOLEAN DEFAULT false;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Booking" ADD COLUMN "rejectionReason" TEXT;
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "postgresql"
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@calcom/prisma",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "yarn generate-schemas",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules",
|
||||
"db-deploy": "yarn prisma migrate deploy",
|
||||
"db-migrate": "yarn prisma migrate dev",
|
||||
"db-nuke": "docker-compose down --volumes --remove-orphans",
|
||||
"db-reset": "run-s db-nuke db-setup",
|
||||
"db-seed": "yarn prisma db seed",
|
||||
"db-setup": "run-s db-up db-deploy db-seed",
|
||||
"db-up": "docker-compose up -d",
|
||||
"deploy": "run-s build db-deploy",
|
||||
"dx": "yarn db-setup",
|
||||
"generate-schemas": "prisma generate"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prisma": "3.0.2",
|
||||
"ts-node": "^10.2.1",
|
||||
"zod-prisma": "^0.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/lib": "*",
|
||||
"@prisma/client": "3.0.2"
|
||||
},
|
||||
"main": "index.ts",
|
||||
"types": "index.d.ts",
|
||||
"prisma": {
|
||||
"seed": "ts-node ./seed.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
generator zod {
|
||||
provider = "zod-prisma"
|
||||
output = "./zod"
|
||||
imports = "./zod-utils"
|
||||
relationModel = "default"
|
||||
}
|
||||
|
||||
enum SchedulingType {
|
||||
ROUND_ROBIN @map("roundRobin")
|
||||
COLLECTIVE @map("collective")
|
||||
}
|
||||
|
||||
enum PeriodType {
|
||||
UNLIMITED @map("unlimited")
|
||||
ROLLING @map("rolling")
|
||||
RANGE @map("range")
|
||||
}
|
||||
|
||||
model EventType {
|
||||
id Int @id @default(autoincrement())
|
||||
/// @zod.nonempty()
|
||||
title String
|
||||
/// @zod.custom(imports.eventTypeSlug)
|
||||
slug String
|
||||
description String?
|
||||
position Int @default(0)
|
||||
/// @zod.custom(imports.eventTypeLocations)
|
||||
locations Json?
|
||||
length Int
|
||||
hidden Boolean @default(false)
|
||||
users User[] @relation("user_eventtype")
|
||||
userId Int?
|
||||
team Team? @relation(fields: [teamId], references: [id])
|
||||
teamId Int?
|
||||
bookings Booking[]
|
||||
availability Availability[]
|
||||
destinationCalendar DestinationCalendar?
|
||||
eventName String?
|
||||
customInputs EventTypeCustomInput[]
|
||||
timeZone String?
|
||||
periodType PeriodType @default(UNLIMITED)
|
||||
periodStartDate DateTime?
|
||||
periodEndDate DateTime?
|
||||
periodDays Int?
|
||||
periodCountCalendarDays Boolean?
|
||||
requiresConfirmation Boolean @default(false)
|
||||
disableGuests Boolean @default(false)
|
||||
minimumBookingNotice Int @default(120)
|
||||
schedulingType SchedulingType?
|
||||
Schedule Schedule[]
|
||||
price Int @default(0)
|
||||
currency String @default("usd")
|
||||
slotInterval Int?
|
||||
metadata Json?
|
||||
|
||||
@@unique([userId, slug])
|
||||
}
|
||||
|
||||
model Credential {
|
||||
id Int @id @default(autoincrement())
|
||||
type String
|
||||
key Json
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int?
|
||||
}
|
||||
|
||||
enum UserPlan {
|
||||
FREE
|
||||
TRIAL
|
||||
PRO
|
||||
}
|
||||
|
||||
enum IdentityProvider {
|
||||
CAL
|
||||
GOOGLE
|
||||
SAML
|
||||
}
|
||||
|
||||
model DestinationCalendar {
|
||||
id Int @id @default(autoincrement())
|
||||
integration String
|
||||
externalId String
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
userId Int? @unique
|
||||
booking Booking? @relation(fields: [bookingId], references: [id])
|
||||
bookingId Int? @unique
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id])
|
||||
eventTypeId Int? @unique
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
username String? @unique
|
||||
name String?
|
||||
/// @zod.email()
|
||||
email String @unique
|
||||
emailVerified DateTime?
|
||||
password String?
|
||||
bio String?
|
||||
avatar String?
|
||||
timeZone String @default("Europe/London")
|
||||
weekStart String @default("Sunday")
|
||||
// DEPRECATED - TO BE REMOVED
|
||||
startTime Int @default(0)
|
||||
endTime Int @default(1440)
|
||||
// </DEPRECATED>
|
||||
bufferTime Int @default(0)
|
||||
hideBranding Boolean @default(false)
|
||||
theme String?
|
||||
createdDate DateTime @default(now()) @map(name: "created")
|
||||
eventTypes EventType[] @relation("user_eventtype")
|
||||
credentials Credential[]
|
||||
teams Membership[]
|
||||
bookings Booking[]
|
||||
availability Availability[]
|
||||
selectedCalendars SelectedCalendar[]
|
||||
completedOnboarding Boolean @default(false)
|
||||
locale String?
|
||||
twoFactorSecret String?
|
||||
twoFactorEnabled Boolean @default(false)
|
||||
identityProvider IdentityProvider @default(CAL)
|
||||
identityProviderId String?
|
||||
invitedTo Int?
|
||||
plan UserPlan @default(TRIAL)
|
||||
Schedule Schedule[]
|
||||
webhooks Webhook[]
|
||||
brandColor String @default("#292929")
|
||||
// the location where the events will end up
|
||||
destinationCalendar DestinationCalendar?
|
||||
away Boolean @default(false)
|
||||
metadata Json?
|
||||
verified Boolean? @default(false)
|
||||
|
||||
@@map(name: "users")
|
||||
}
|
||||
|
||||
model Team {
|
||||
id Int @id @default(autoincrement())
|
||||
name String?
|
||||
slug String? @unique
|
||||
logo String?
|
||||
bio String?
|
||||
hideBranding Boolean @default(false)
|
||||
members Membership[]
|
||||
eventTypes EventType[]
|
||||
}
|
||||
|
||||
enum MembershipRole {
|
||||
MEMBER
|
||||
ADMIN
|
||||
OWNER
|
||||
}
|
||||
|
||||
model Membership {
|
||||
teamId Int
|
||||
userId Int
|
||||
accepted Boolean @default(false)
|
||||
role MembershipRole
|
||||
team Team @relation(fields: [teamId], references: [id])
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([userId, teamId])
|
||||
}
|
||||
|
||||
model VerificationRequest {
|
||||
id Int @id @default(autoincrement())
|
||||
identifier String
|
||||
token String @unique
|
||||
expires DateTime
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([identifier, token])
|
||||
}
|
||||
|
||||
model BookingReference {
|
||||
id Int @id @default(autoincrement())
|
||||
type String
|
||||
uid String
|
||||
meetingId String?
|
||||
meetingPassword String?
|
||||
meetingUrl String?
|
||||
booking Booking? @relation(fields: [bookingId], references: [id])
|
||||
bookingId Int?
|
||||
}
|
||||
|
||||
model Attendee {
|
||||
id Int @id @default(autoincrement())
|
||||
email String
|
||||
name String
|
||||
timeZone String
|
||||
locale String? @default("en")
|
||||
booking Booking? @relation(fields: [bookingId], references: [id])
|
||||
bookingId Int?
|
||||
}
|
||||
|
||||
enum BookingStatus {
|
||||
CANCELLED @map("cancelled")
|
||||
ACCEPTED @map("accepted")
|
||||
REJECTED @map("rejected")
|
||||
PENDING @map("pending")
|
||||
}
|
||||
|
||||
model DailyEventReference {
|
||||
id Int @id @default(autoincrement())
|
||||
dailyurl String @default("dailycallurl")
|
||||
dailytoken String @default("dailytoken")
|
||||
booking Booking? @relation(fields: [bookingId], references: [id])
|
||||
bookingId Int? @unique
|
||||
}
|
||||
|
||||
model Booking {
|
||||
id Int @id @default(autoincrement())
|
||||
uid String @unique
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
userId Int?
|
||||
references BookingReference[]
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id])
|
||||
eventTypeId Int?
|
||||
title String
|
||||
description String?
|
||||
startTime DateTime
|
||||
endTime DateTime
|
||||
attendees Attendee[]
|
||||
location String?
|
||||
dailyRef DailyEventReference?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime?
|
||||
confirmed Boolean @default(true)
|
||||
rejected Boolean @default(false)
|
||||
status BookingStatus @default(ACCEPTED)
|
||||
paid Boolean @default(false)
|
||||
payment Payment[]
|
||||
destinationCalendar DestinationCalendar?
|
||||
cancellationReason String?
|
||||
rejectionReason String?
|
||||
}
|
||||
|
||||
model Schedule {
|
||||
id Int @id @default(autoincrement())
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int?
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id])
|
||||
eventTypeId Int?
|
||||
title String?
|
||||
freeBusyTimes Json?
|
||||
}
|
||||
|
||||
model Availability {
|
||||
id Int @id @default(autoincrement())
|
||||
label String?
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int?
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id])
|
||||
eventTypeId Int?
|
||||
days Int[]
|
||||
startTime DateTime @db.Time
|
||||
endTime DateTime @db.Time
|
||||
date DateTime? @db.Date
|
||||
}
|
||||
|
||||
model SelectedCalendar {
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int
|
||||
integration String
|
||||
externalId String
|
||||
|
||||
@@id([userId, integration, externalId])
|
||||
}
|
||||
|
||||
enum EventTypeCustomInputType {
|
||||
TEXT @map("text")
|
||||
TEXTLONG @map("textLong")
|
||||
NUMBER @map("number")
|
||||
BOOL @map("bool")
|
||||
}
|
||||
|
||||
model EventTypeCustomInput {
|
||||
id Int @id @default(autoincrement())
|
||||
eventTypeId Int
|
||||
eventType EventType @relation(fields: [eventTypeId], references: [id])
|
||||
label String
|
||||
type EventTypeCustomInputType
|
||||
required Boolean
|
||||
placeholder String @default("")
|
||||
}
|
||||
|
||||
model ResetPasswordRequest {
|
||||
id String @id @default(cuid())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
email String
|
||||
expires DateTime
|
||||
}
|
||||
|
||||
enum ReminderType {
|
||||
PENDING_BOOKING_CONFIRMATION
|
||||
}
|
||||
|
||||
model ReminderMail {
|
||||
id Int @id @default(autoincrement())
|
||||
referenceId Int
|
||||
reminderType ReminderType
|
||||
elapsedMinutes Int
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
|
||||
enum PaymentType {
|
||||
STRIPE
|
||||
}
|
||||
|
||||
model Payment {
|
||||
id Int @id @default(autoincrement())
|
||||
uid String @unique
|
||||
type PaymentType
|
||||
bookingId Int
|
||||
booking Booking? @relation(fields: [bookingId], references: [id])
|
||||
amount Int
|
||||
fee Int
|
||||
currency String
|
||||
success Boolean
|
||||
refunded Boolean
|
||||
data Json
|
||||
externalId String @unique
|
||||
}
|
||||
|
||||
enum WebhookTriggerEvents {
|
||||
BOOKING_CREATED
|
||||
BOOKING_RESCHEDULED
|
||||
BOOKING_CANCELLED
|
||||
}
|
||||
|
||||
model Webhook {
|
||||
id String @id @unique
|
||||
userId Int
|
||||
subscriberUrl String
|
||||
payloadTemplate String?
|
||||
createdAt DateTime @default(now())
|
||||
active Boolean @default(true)
|
||||
eventTriggers WebhookTriggerEvents[]
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
import { MembershipRole, Prisma, PrismaClient, UserPlan } from "@prisma/client";
|
||||
import dayjs from "dayjs";
|
||||
import { uuid } from "short-uuid";
|
||||
|
||||
import { hashPassword } from "@calcom/lib/auth";
|
||||
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function createUserAndEventType(opts: {
|
||||
user: {
|
||||
email: string;
|
||||
password: string;
|
||||
username: string;
|
||||
plan: UserPlan;
|
||||
name: string;
|
||||
completedOnboarding?: boolean;
|
||||
timeZone?: string;
|
||||
};
|
||||
eventTypes: Array<
|
||||
Prisma.EventTypeCreateInput & {
|
||||
_bookings?: Prisma.BookingCreateInput[];
|
||||
}
|
||||
>;
|
||||
}) {
|
||||
const userData: Prisma.UserCreateArgs["data"] = {
|
||||
...opts.user,
|
||||
password: await hashPassword(opts.user.password),
|
||||
emailVerified: new Date(),
|
||||
completedOnboarding: opts.user.completedOnboarding ?? true,
|
||||
locale: "en",
|
||||
availability: {
|
||||
createMany: {
|
||||
data: getAvailabilityFromSchedule(DEFAULT_SCHEDULE),
|
||||
},
|
||||
},
|
||||
};
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email: opts.user.email },
|
||||
update: userData,
|
||||
create: userData,
|
||||
});
|
||||
|
||||
console.log(
|
||||
`👤 Upserted '${opts.user.username}' with email "${opts.user.email}" & password "${opts.user.password}". Booking page 👉 ${process.env.BASE_URL}/${opts.user.username}`
|
||||
);
|
||||
|
||||
for (const eventTypeInput of opts.eventTypes) {
|
||||
const { _bookings: bookingInputs = [], ...eventTypeData } = eventTypeInput;
|
||||
eventTypeData.userId = user.id;
|
||||
eventTypeData.users = { connect: { id: user.id } };
|
||||
|
||||
const eventType = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
slug: eventTypeData.slug,
|
||||
users: {
|
||||
some: {
|
||||
id: eventTypeData.userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (eventType) {
|
||||
console.log(
|
||||
`\t📆 Event type ${eventTypeData.slug} already seems seeded - ${process.env.BASE_URL}/${user.username}/${eventTypeData.slug}`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const { id } = await prisma.eventType.create({
|
||||
data: eventTypeData,
|
||||
});
|
||||
|
||||
console.log(
|
||||
`\t📆 Event type ${eventTypeData.slug}, length ${eventTypeData.length}min - ${process.env.BASE_URL}/${user.username}/${eventTypeData.slug}`
|
||||
);
|
||||
for (const bookingInput of bookingInputs) {
|
||||
await prisma.booking.create({
|
||||
data: {
|
||||
...bookingInput,
|
||||
user: {
|
||||
connect: {
|
||||
email: opts.user.email,
|
||||
},
|
||||
},
|
||||
attendees: {
|
||||
create: {
|
||||
email: opts.user.email,
|
||||
name: opts.user.name,
|
||||
timeZone: "Europe/London",
|
||||
},
|
||||
},
|
||||
eventType: {
|
||||
connect: {
|
||||
id,
|
||||
},
|
||||
},
|
||||
confirmed: bookingInput.confirmed,
|
||||
},
|
||||
});
|
||||
console.log(
|
||||
`\t\t☎️ Created booking ${bookingInput.title} at ${new Date(
|
||||
bookingInput.startTime
|
||||
).toLocaleDateString()}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async function createTeamAndAddUsers(
|
||||
teamInput: Prisma.TeamCreateInput,
|
||||
users: { id: number; username: string; role?: MembershipRole }[]
|
||||
) {
|
||||
const createTeam = async (team: Prisma.TeamCreateInput) => {
|
||||
try {
|
||||
return await prisma.team.create({
|
||||
data: {
|
||||
...team,
|
||||
},
|
||||
});
|
||||
} catch (_err) {
|
||||
if (_err instanceof Error && _err.message.indexOf("Unique constraint failed on the fields") !== -1) {
|
||||
console.log(`Team '${team.name}' already exists, skipping.`);
|
||||
return;
|
||||
}
|
||||
throw _err;
|
||||
}
|
||||
};
|
||||
|
||||
const team = await createTeam(teamInput);
|
||||
if (!team) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`🏢 Created team '${teamInput.name}' - ${process.env.BASE_URL}/team/${team.slug}`);
|
||||
|
||||
for (const user of users) {
|
||||
const { role = MembershipRole.OWNER, id, username } = user;
|
||||
await prisma.membership.create({
|
||||
data: {
|
||||
teamId: team.id,
|
||||
userId: id,
|
||||
role: role,
|
||||
accepted: true,
|
||||
},
|
||||
});
|
||||
console.log(`\t👤 Added '${teamInput.name}' membership for '${username}' with role '${role}'`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "delete-me",
|
||||
username: "delete-me",
|
||||
name: "delete-me",
|
||||
plan: "FREE",
|
||||
},
|
||||
eventTypes: [],
|
||||
});
|
||||
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "onboarding",
|
||||
username: "onboarding",
|
||||
name: "onboarding",
|
||||
plan: "TRIAL",
|
||||
completedOnboarding: false,
|
||||
},
|
||||
eventTypes: [],
|
||||
});
|
||||
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "free-first-hidden",
|
||||
username: "free-first-hidden",
|
||||
name: "Free First Hidden Example",
|
||||
plan: "FREE",
|
||||
},
|
||||
eventTypes: [
|
||||
{
|
||||
title: "30min",
|
||||
slug: "30min",
|
||||
length: 30,
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
title: "60min",
|
||||
slug: "60min",
|
||||
length: 30,
|
||||
},
|
||||
],
|
||||
});
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
name: "Pro Example",
|
||||
password: "pro",
|
||||
username: "pro",
|
||||
plan: "PRO",
|
||||
},
|
||||
|
||||
eventTypes: [
|
||||
{
|
||||
title: "30min",
|
||||
slug: "30min",
|
||||
length: 30,
|
||||
_bookings: [
|
||||
{
|
||||
uid: uuid(),
|
||||
title: "30min",
|
||||
startTime: dayjs().add(1, "day").toDate(),
|
||||
endTime: dayjs().add(1, "day").add(30, "minutes").toDate(),
|
||||
},
|
||||
{
|
||||
uid: uuid(),
|
||||
title: "30min",
|
||||
startTime: dayjs().add(2, "day").toDate(),
|
||||
endTime: dayjs().add(2, "day").add(30, "minutes").toDate(),
|
||||
confirmed: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "60min",
|
||||
slug: "60min",
|
||||
length: 60,
|
||||
},
|
||||
{
|
||||
title: "paid",
|
||||
slug: "paid",
|
||||
length: 60,
|
||||
price: 50,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "trial",
|
||||
username: "trial",
|
||||
name: "Trial Example",
|
||||
plan: "TRIAL",
|
||||
},
|
||||
eventTypes: [
|
||||
{
|
||||
title: "30min",
|
||||
slug: "30min",
|
||||
length: 30,
|
||||
},
|
||||
{
|
||||
title: "60min",
|
||||
slug: "60min",
|
||||
length: 60,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "free",
|
||||
username: "free",
|
||||
name: "Free Example",
|
||||
plan: "FREE",
|
||||
},
|
||||
eventTypes: [
|
||||
{
|
||||
title: "30min",
|
||||
slug: "30min",
|
||||
length: 30,
|
||||
},
|
||||
{
|
||||
title: "60min",
|
||||
slug: "60min",
|
||||
length: 30,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "usa",
|
||||
username: "usa",
|
||||
name: "USA Timezone Example",
|
||||
plan: "FREE",
|
||||
timeZone: "America/Phoenix",
|
||||
},
|
||||
eventTypes: [
|
||||
{
|
||||
title: "30min",
|
||||
slug: "30min",
|
||||
length: 30,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const freeUserTeam = await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "teamfree",
|
||||
username: "teamfree",
|
||||
name: "Team Free Example",
|
||||
plan: "FREE",
|
||||
},
|
||||
eventTypes: [],
|
||||
});
|
||||
|
||||
const proUserTeam = await createUserAndEventType({
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
password: "teampro",
|
||||
username: "teampro",
|
||||
name: "Team Pro Example",
|
||||
plan: "PRO",
|
||||
},
|
||||
eventTypes: [],
|
||||
});
|
||||
|
||||
await createTeamAndAddUsers(
|
||||
{
|
||||
name: "Seeded Team",
|
||||
slug: "seeded-team",
|
||||
},
|
||||
[
|
||||
{
|
||||
id: proUserTeam.id,
|
||||
username: proUserTeam.name || "Unknown",
|
||||
},
|
||||
{
|
||||
id: freeUserTeam.id,
|
||||
username: freeUserTeam.name || "Unknown",
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
console.log("🌱 Seeded db");
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { LocationType } from "@calcom/lib/location";
|
||||
|
||||
export const eventTypeLocations = z.array(
|
||||
z.object({ type: z.nativeEnum(LocationType), address: z.string().optional() })
|
||||
);
|
||||
|
||||
export const eventTypeSlug = z.string().transform((val) => val.trim());
|
||||
export const stringToDate = z.string().transform((a) => new Date(a));
|
||||
export const stringOrNumber = z.union([z.string().transform((v) => parseInt(v, 10)), z.number().int()]);
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteBooking, BookingModel } from "./index";
|
||||
|
||||
export const _AttendeeModel = z.object({
|
||||
id: z.number().int(),
|
||||
email: z.string(),
|
||||
name: z.string(),
|
||||
timeZone: z.string(),
|
||||
locale: z.string().nullish(),
|
||||
bookingId: z.number().int().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteAttendee extends z.infer<typeof _AttendeeModel> {
|
||||
booking?: CompleteBooking | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* AttendeeModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const AttendeeModel: z.ZodSchema<CompleteAttendee> = z.lazy(() =>
|
||||
_AttendeeModel.extend({
|
||||
booking: BookingModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,31 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteUser, UserModel, CompleteEventType, EventTypeModel } from "./index";
|
||||
|
||||
export const _AvailabilityModel = z.object({
|
||||
id: z.number().int(),
|
||||
label: z.string().nullish(),
|
||||
userId: z.number().int().nullish(),
|
||||
eventTypeId: z.number().int().nullish(),
|
||||
days: z.number().int().array(),
|
||||
startTime: z.date(),
|
||||
endTime: z.date(),
|
||||
date: z.date().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteAvailability extends z.infer<typeof _AvailabilityModel> {
|
||||
user?: CompleteUser | null;
|
||||
eventType?: CompleteEventType | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* AvailabilityModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const AvailabilityModel: z.ZodSchema<CompleteAvailability> = z.lazy(() =>
|
||||
_AvailabilityModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
eventType: EventTypeModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,66 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { BookingStatus } from "@prisma/client";
|
||||
import {
|
||||
CompleteUser,
|
||||
UserModel,
|
||||
CompleteBookingReference,
|
||||
BookingReferenceModel,
|
||||
CompleteEventType,
|
||||
EventTypeModel,
|
||||
CompleteAttendee,
|
||||
AttendeeModel,
|
||||
CompleteDailyEventReference,
|
||||
DailyEventReferenceModel,
|
||||
CompletePayment,
|
||||
PaymentModel,
|
||||
CompleteDestinationCalendar,
|
||||
DestinationCalendarModel,
|
||||
} from "./index";
|
||||
|
||||
export const _BookingModel = z.object({
|
||||
id: z.number().int(),
|
||||
uid: z.string(),
|
||||
userId: z.number().int().nullish(),
|
||||
eventTypeId: z.number().int().nullish(),
|
||||
title: z.string(),
|
||||
description: z.string().nullish(),
|
||||
startTime: z.date(),
|
||||
endTime: z.date(),
|
||||
location: z.string().nullish(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date().nullish(),
|
||||
confirmed: z.boolean(),
|
||||
rejected: z.boolean(),
|
||||
status: z.nativeEnum(BookingStatus),
|
||||
paid: z.boolean(),
|
||||
cancellationReason: z.string().nullish(),
|
||||
rejectionReason: z.string().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteBooking extends z.infer<typeof _BookingModel> {
|
||||
user?: CompleteUser | null;
|
||||
references: CompleteBookingReference[];
|
||||
eventType?: CompleteEventType | null;
|
||||
attendees: CompleteAttendee[];
|
||||
dailyRef?: CompleteDailyEventReference | null;
|
||||
payment: CompletePayment[];
|
||||
destinationCalendar?: CompleteDestinationCalendar | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* BookingModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const BookingModel: z.ZodSchema<CompleteBooking> = z.lazy(() =>
|
||||
_BookingModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
references: BookingReferenceModel.array(),
|
||||
eventType: EventTypeModel.nullish(),
|
||||
attendees: AttendeeModel.array(),
|
||||
dailyRef: DailyEventReferenceModel.nullish(),
|
||||
payment: PaymentModel.array(),
|
||||
destinationCalendar: DestinationCalendarModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteBooking, BookingModel } from "./index";
|
||||
|
||||
export const _BookingReferenceModel = z.object({
|
||||
id: z.number().int(),
|
||||
type: z.string(),
|
||||
uid: z.string(),
|
||||
meetingId: z.string().nullish(),
|
||||
meetingPassword: z.string().nullish(),
|
||||
meetingUrl: z.string().nullish(),
|
||||
bookingId: z.number().int().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteBookingReference extends z.infer<typeof _BookingReferenceModel> {
|
||||
booking?: CompleteBooking | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* BookingReferenceModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const BookingReferenceModel: z.ZodSchema<CompleteBookingReference> = z.lazy(() =>
|
||||
_BookingReferenceModel.extend({
|
||||
booking: BookingModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,33 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteUser, UserModel } from "./index";
|
||||
|
||||
// Helper schema for JSON fields
|
||||
type Literal = boolean | number | string;
|
||||
type Json = Literal | { [key: string]: Json } | Json[];
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
|
||||
const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
|
||||
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
|
||||
);
|
||||
|
||||
export const _CredentialModel = z.object({
|
||||
id: z.number().int(),
|
||||
type: z.string(),
|
||||
key: jsonSchema,
|
||||
userId: z.number().int().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteCredential extends z.infer<typeof _CredentialModel> {
|
||||
user?: CompleteUser | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* CredentialModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const CredentialModel: z.ZodSchema<CompleteCredential> = z.lazy(() =>
|
||||
_CredentialModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,25 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteBooking, BookingModel } from "./index";
|
||||
|
||||
export const _DailyEventReferenceModel = z.object({
|
||||
id: z.number().int(),
|
||||
dailyurl: z.string(),
|
||||
dailytoken: z.string(),
|
||||
bookingId: z.number().int().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteDailyEventReference extends z.infer<typeof _DailyEventReferenceModel> {
|
||||
booking?: CompleteBooking | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* DailyEventReferenceModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const DailyEventReferenceModel: z.ZodSchema<CompleteDailyEventReference> = z.lazy(() =>
|
||||
_DailyEventReferenceModel.extend({
|
||||
booking: BookingModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import {
|
||||
CompleteUser,
|
||||
UserModel,
|
||||
CompleteBooking,
|
||||
BookingModel,
|
||||
CompleteEventType,
|
||||
EventTypeModel,
|
||||
} from "./index";
|
||||
|
||||
export const _DestinationCalendarModel = z.object({
|
||||
id: z.number().int(),
|
||||
integration: z.string(),
|
||||
externalId: z.string(),
|
||||
userId: z.number().int().nullish(),
|
||||
bookingId: z.number().int().nullish(),
|
||||
eventTypeId: z.number().int().nullish(),
|
||||
});
|
||||
|
||||
export interface CompleteDestinationCalendar extends z.infer<typeof _DestinationCalendarModel> {
|
||||
user?: CompleteUser | null;
|
||||
booking?: CompleteBooking | null;
|
||||
eventType?: CompleteEventType | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* DestinationCalendarModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const DestinationCalendarModel: z.ZodSchema<CompleteDestinationCalendar> = z.lazy(() =>
|
||||
_DestinationCalendarModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
booking: BookingModel.nullish(),
|
||||
eventType: EventTypeModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,82 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { PeriodType, SchedulingType } from "@prisma/client";
|
||||
import {
|
||||
CompleteUser,
|
||||
UserModel,
|
||||
CompleteTeam,
|
||||
TeamModel,
|
||||
CompleteBooking,
|
||||
BookingModel,
|
||||
CompleteAvailability,
|
||||
AvailabilityModel,
|
||||
CompleteDestinationCalendar,
|
||||
DestinationCalendarModel,
|
||||
CompleteEventTypeCustomInput,
|
||||
EventTypeCustomInputModel,
|
||||
CompleteSchedule,
|
||||
ScheduleModel,
|
||||
} from "./index";
|
||||
|
||||
// Helper schema for JSON fields
|
||||
type Literal = boolean | number | string;
|
||||
type Json = Literal | { [key: string]: Json } | Json[];
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
|
||||
const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
|
||||
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
|
||||
);
|
||||
|
||||
export const _EventTypeModel = z.object({
|
||||
id: z.number().int(),
|
||||
title: z.string().nonempty(),
|
||||
slug: imports.eventTypeSlug,
|
||||
description: z.string().nullish(),
|
||||
position: z.number().int(),
|
||||
locations: imports.eventTypeLocations,
|
||||
length: z.number().int(),
|
||||
hidden: z.boolean(),
|
||||
userId: z.number().int().nullish(),
|
||||
teamId: z.number().int().nullish(),
|
||||
eventName: z.string().nullish(),
|
||||
timeZone: z.string().nullish(),
|
||||
periodType: z.nativeEnum(PeriodType),
|
||||
periodStartDate: z.date().nullish(),
|
||||
periodEndDate: z.date().nullish(),
|
||||
periodDays: z.number().int().nullish(),
|
||||
periodCountCalendarDays: z.boolean().nullish(),
|
||||
requiresConfirmation: z.boolean(),
|
||||
disableGuests: z.boolean(),
|
||||
minimumBookingNotice: z.number().int(),
|
||||
schedulingType: z.nativeEnum(SchedulingType).nullish(),
|
||||
price: z.number().int(),
|
||||
currency: z.string(),
|
||||
slotInterval: z.number().int().nullish(),
|
||||
metadata: jsonSchema,
|
||||
});
|
||||
|
||||
export interface CompleteEventType extends z.infer<typeof _EventTypeModel> {
|
||||
users: CompleteUser[];
|
||||
team?: CompleteTeam | null;
|
||||
bookings: CompleteBooking[];
|
||||
availability: CompleteAvailability[];
|
||||
destinationCalendar?: CompleteDestinationCalendar | null;
|
||||
customInputs: CompleteEventTypeCustomInput[];
|
||||
Schedule: CompleteSchedule[];
|
||||
}
|
||||
|
||||
/**
|
||||
* EventTypeModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const EventTypeModel: z.ZodSchema<CompleteEventType> = z.lazy(() =>
|
||||
_EventTypeModel.extend({
|
||||
users: UserModel.array(),
|
||||
team: TeamModel.nullish(),
|
||||
bookings: BookingModel.array(),
|
||||
availability: AvailabilityModel.array(),
|
||||
destinationCalendar: DestinationCalendarModel.nullish(),
|
||||
customInputs: EventTypeCustomInputModel.array(),
|
||||
Schedule: ScheduleModel.array(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { _EventTypeModel } from "./eventtype";
|
||||
|
||||
const createEventTypeBaseInput = _EventTypeModel
|
||||
.pick({
|
||||
title: true,
|
||||
slug: true,
|
||||
description: true,
|
||||
length: true,
|
||||
teamId: true,
|
||||
schedulingType: true,
|
||||
})
|
||||
.refine((data) => (data.teamId ? data.teamId && data.schedulingType : true), {
|
||||
path: ["schedulingType"],
|
||||
message: "You must select a scheduling type for team events",
|
||||
});
|
||||
|
||||
export const createEventTypeInput = createEventTypeBaseInput;
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { EventTypeCustomInputType } from "@prisma/client";
|
||||
import { CompleteEventType, EventTypeModel } from "./index";
|
||||
|
||||
export const _EventTypeCustomInputModel = z.object({
|
||||
id: z.number().int(),
|
||||
eventTypeId: z.number().int(),
|
||||
label: z.string(),
|
||||
type: z.nativeEnum(EventTypeCustomInputType),
|
||||
required: z.boolean(),
|
||||
placeholder: z.string(),
|
||||
});
|
||||
|
||||
export interface CompleteEventTypeCustomInput extends z.infer<typeof _EventTypeCustomInputModel> {
|
||||
eventType: CompleteEventType;
|
||||
}
|
||||
|
||||
/**
|
||||
* EventTypeCustomInputModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const EventTypeCustomInputModel: z.ZodSchema<CompleteEventTypeCustomInput> = z.lazy(() =>
|
||||
_EventTypeCustomInputModel.extend({
|
||||
eventType: EventTypeModel,
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
export * from "./eventtype";
|
||||
export * from "./credential";
|
||||
export * from "./destinationcalendar";
|
||||
export * from "./user";
|
||||
export * from "./team";
|
||||
export * from "./membership";
|
||||
export * from "./verificationrequest";
|
||||
export * from "./bookingreference";
|
||||
export * from "./attendee";
|
||||
export * from "./dailyeventreference";
|
||||
export * from "./booking";
|
||||
export * from "./schedule";
|
||||
export * from "./availability";
|
||||
export * from "./selectedcalendar";
|
||||
export * from "./eventtypecustominput";
|
||||
export * from "./resetpasswordrequest";
|
||||
export * from "./remindermail";
|
||||
export * from "./payment";
|
||||
export * from "./webhook";
|
||||
@@ -0,0 +1,28 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { MembershipRole } from "@prisma/client";
|
||||
import { CompleteTeam, TeamModel, CompleteUser, UserModel } from "./index";
|
||||
|
||||
export const _MembershipModel = z.object({
|
||||
teamId: z.number().int(),
|
||||
userId: z.number().int(),
|
||||
accepted: z.boolean(),
|
||||
role: z.nativeEnum(MembershipRole),
|
||||
});
|
||||
|
||||
export interface CompleteMembership extends z.infer<typeof _MembershipModel> {
|
||||
team: CompleteTeam;
|
||||
user: CompleteUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* MembershipModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const MembershipModel: z.ZodSchema<CompleteMembership> = z.lazy(() =>
|
||||
_MembershipModel.extend({
|
||||
team: TeamModel,
|
||||
user: UserModel,
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,41 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { PaymentType } from "@prisma/client";
|
||||
import { CompleteBooking, BookingModel } from "./index";
|
||||
|
||||
// Helper schema for JSON fields
|
||||
type Literal = boolean | number | string;
|
||||
type Json = Literal | { [key: string]: Json } | Json[];
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
|
||||
const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
|
||||
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
|
||||
);
|
||||
|
||||
export const _PaymentModel = z.object({
|
||||
id: z.number().int(),
|
||||
uid: z.string(),
|
||||
type: z.nativeEnum(PaymentType),
|
||||
bookingId: z.number().int(),
|
||||
amount: z.number().int(),
|
||||
fee: z.number().int(),
|
||||
currency: z.string(),
|
||||
success: z.boolean(),
|
||||
refunded: z.boolean(),
|
||||
data: jsonSchema,
|
||||
externalId: z.string(),
|
||||
});
|
||||
|
||||
export interface CompletePayment extends z.infer<typeof _PaymentModel> {
|
||||
booking?: CompleteBooking | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* PaymentModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const PaymentModel: z.ZodSchema<CompletePayment> = z.lazy(() =>
|
||||
_PaymentModel.extend({
|
||||
booking: BookingModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { ReminderType } from "@prisma/client";
|
||||
|
||||
export const _ReminderMailModel = z.object({
|
||||
id: z.number().int(),
|
||||
referenceId: z.number().int(),
|
||||
reminderType: z.nativeEnum(ReminderType),
|
||||
elapsedMinutes: z.number().int(),
|
||||
createdAt: z.date(),
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
|
||||
export const _ResetPasswordRequestModel = z.object({
|
||||
id: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date(),
|
||||
email: z.string(),
|
||||
expires: z.date(),
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteUser, UserModel, CompleteEventType, EventTypeModel } from "./index";
|
||||
|
||||
// Helper schema for JSON fields
|
||||
type Literal = boolean | number | string;
|
||||
type Json = Literal | { [key: string]: Json } | Json[];
|
||||
const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
|
||||
const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
|
||||
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
|
||||
);
|
||||
|
||||
export const _ScheduleModel = z.object({
|
||||
id: z.number().int(),
|
||||
userId: z.number().int().nullish(),
|
||||
eventTypeId: z.number().int().nullish(),
|
||||
title: z.string().nullish(),
|
||||
freeBusyTimes: jsonSchema,
|
||||
});
|
||||
|
||||
export interface CompleteSchedule extends z.infer<typeof _ScheduleModel> {
|
||||
user?: CompleteUser | null;
|
||||
eventType?: CompleteEventType | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ScheduleModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const ScheduleModel: z.ZodSchema<CompleteSchedule> = z.lazy(() =>
|
||||
_ScheduleModel.extend({
|
||||
user: UserModel.nullish(),
|
||||
eventType: EventTypeModel.nullish(),
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteUser, UserModel } from "./index";
|
||||
|
||||
export const _SelectedCalendarModel = z.object({
|
||||
userId: z.number().int(),
|
||||
integration: z.string(),
|
||||
externalId: z.string(),
|
||||
});
|
||||
|
||||
export interface CompleteSelectedCalendar extends z.infer<typeof _SelectedCalendarModel> {
|
||||
user: CompleteUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* SelectedCalendarModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const SelectedCalendarModel: z.ZodSchema<CompleteSelectedCalendar> = z.lazy(() =>
|
||||
_SelectedCalendarModel.extend({
|
||||
user: UserModel,
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,29 @@
|
||||
import * as z from "zod";
|
||||
import * as imports from "../zod-utils";
|
||||
import { CompleteMembership, MembershipModel, CompleteEventType, EventTypeModel } from "./index";
|
||||
|
||||
export const _TeamModel = z.object({
|
||||
id: z.number().int(),
|
||||
name: z.string().nullish(),
|
||||
slug: z.string().nullish(),
|
||||
logo: z.string().nullish(),
|
||||
bio: z.string().nullish(),
|
||||
hideBranding: z.boolean(),
|
||||
});
|
||||
|
||||
export interface CompleteTeam extends z.infer<typeof _TeamModel> {
|
||||
members: CompleteMembership[];
|
||||
eventTypes: CompleteEventType[];
|
||||
}
|
||||
|
||||
/**
|
||||
* TeamModel contains all relations on your model in addition to the scalars
|
||||
*
|
||||
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||
*/
|
||||
export const TeamModel: z.ZodSchema<CompleteTeam> = z.lazy(() =>
|
||||
_TeamModel.extend({
|
||||
members: MembershipModel.array(),
|
||||
eventTypes: EventTypeModel.array(),
|
||||
})
|
||||
);
|
||||
Loaded 100 of 128 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user