chore: Upgrade prisma to 6.7.0 (#21264)
* chore: Upgrade prisma to 6.7.0 * Build fixes * type fixes Signed-off-by: Omar López <[email protected]> * Update schema.prisma * Patching * Revert "Update schema.prisma" This reverts commit 47d8618bf89ef4d007b30084df766f17281e21a1. * Revert "Patching" This reverts commit a1d2e3040e71690a44d4324db95d73b4d68c6adb. * Revert schema changes Signed-off-by: Omar López <[email protected]> * WIP Signed-off-by: Omar López <[email protected]> * Update getPublicEvent.ts * Update imports Signed-off-by: Omar López <[email protected]> * Update gitignore Signed-off-by: Omar López <[email protected]> * update remaining imports Signed-off-by: Omar López <[email protected]> * Delete .cursor/config.json * Discard changes to packages/features/eventtypes/lib/getPublicEvent.ts * Update _get.ts * Update user.ts * Update .gitignore * update * Update WorkflowStepContainer.tsx * Update next-auth-custom-adapter.ts * Update getPublicEvent.ts * Update workflow.ts * Update next-auth-custom-adapter.ts * Update next-auth-options.ts * Update bookingScenario.ts * fix missing imports * upgrades prismock Signed-off-by: Omar López <[email protected]> * patches prismock Signed-off-by: Omar López <[email protected]> * Update reschedule.test.ts * Update prisma.ts * patch prismock Signed-off-by: Omar López <[email protected]> * fix enums imports Signed-off-by: Omar López <[email protected]> * Revert "Update prisma.ts" This reverts commit 64edcf8db54171ff4456c209d563b5d431d99619. * Revert "patch prismock" This reverts commit e95819113dc9d88e7130947aa120cd42710977c8. * fix patch * Fix test that overrun the boundary, it shouldn't test too much * Move prisma import to changeSMSLockState * Bring back broken test without illegal imports * Merge with main and fix filter hosts by same round robin host * Fixed buildDryRunBooking fn tests * Fix and move ooo create or update handler test * Fix packages/features/eventtypes/lib/isCurrentlyAvailable.test.ts * Fix packages/trpc/server/routers/viewer/organizations/listMembers.handler.test.ts * Mock @calcom/prisma * Fix: verify-email.test.ts * fix: Moved WebhookService test and fixed default import mock * Fix: Added missing prisma mock, handleNewBooking uses that of course * We're not testing createContext here * fix: Prisma mock fix for listMembers.test.ts * More fixes to broken testcases * Forgot to remove borked test * Prevent the need to mock a lot of dependencies by moving out buildBaseWhereCondition to its own file * Temporarily skip getCalendarEvents, needs a rewrite * Fix: turns out you can access protected in testcases * fix further mocks * Added packages/features/insights/server/buildBaseWhereCondition.ts, types * Always great to have a mock and then not use it * And one less again. * fix: confirm.handler.test, didn't mock prisma * fix: Address minor nit by @eunjae & fix ImpersonationProvider test * Updated isPrismaAvailableCheck that doesn't crash on import * fix: Get Prisma directly from the client, it usually involves the Validator and does not need 'local' inclusion * Add zod-prisma-types without the generator enabled (commented out) * Uncomment and see what happens * Change method of import as imports did not work in Input Schemas * Remove custom 'zod' booking model, it does not belong with Prisma * Fix all other global Model imports * Rewrite most schema includes AND remove barrel file * Add bookingCreateBodySchema to features/bookings * Flurry of type fixes for compatibility with new zod gen * Refactor out the custom prisma type createEventTypeInput * Work around nullable eventTypeLocations * HandlePayment type fix * More fixes, final fix remaining is CompleteEventType * Should fix a bunch more booking related type errors * Missed one * Some props missing from BookingCreateBodySchema * Fix location type in handleChildrenEventTypes * Little bit hacky imo but it works * Final type error \o/ * Forgot to include Prisma * Do not include zod-utils in booker/types * Oops, was already including Booker/types * Fix membership type, also disallow updating createdAt/updatedAt, make part of patch/post * Fix api v1 type errors * Fix EventTypeDescription typings * Remove getParserWithGeneric, use userBodySchema with UserSchema * use centralized timeZoneSchema * Implement feedback by @zomars * Couple of WIP pushes * Fix tests * Type fixes in `handleChildrenEventTypes` test * Try and parse metadata before use * Change zod-prisma-types configuration for optimal performance * Fix prisma validator error in `prisma/selects/credential` * Disable seperate relations model, hits a bug * Import absolute - this makes rollup work in @platform/libraries * Attempt at removing resolutions override * Refactor using `Prisma.validator` to `satisfies` * Build atoms using @calcom/prisma/client * Build atoms using @calcom/prisma/client * fixes * Update eventTypeSelect.ts * Adjust `eventTypeMetaDataSchemaWithUntypedApps` from `unknown` to `record(any)` * `EventTypeDescription` rely on `descriptionAsSafeHTML` instead of `description` * Add `seatsPerTimeSlot` to event type public select * Fix typing in `users-public-view` getServerSide props * Add missing `schedulingType` to prop * chore: bump platform libraries * Function return type is illegal, not sure how this passed eslint (#21567) * Merged with main * Update updateTokenObject.ts * Update handleResponse.ts * Update index.ts * Update handleChildrenEventTypes.ts * Update booking-idempotency-key.ts * Update WebhookService.test.ts * Update events.test.ts * Update queued-response.test.ts * Update events.test.ts * Update getRoutedUrl.test.ts * fix: type checks Signed-off-by: Omar López <[email protected]> * fixes Signed-off-by: Omar López <[email protected]> * chore: bump platform libraries * Update yarn.lock * more fixes Signed-off-by: Omar López <[email protected]> * fixes Signed-off-by: Omar López <[email protected]> * biuld fixes * chore: bump platform libraries * Update conferencing.repository.ts * Update conferencing.repository.ts * Update getCalendarsEvents.test.ts * Update vite.config.js * chore: bump platform libraries * Update users.ts * Discard changes to docs/api-reference/v2/openapi.json * Update vite.config.ts * updated platform libraries * Update get.handler.test.ts * Update get.handler.test.ts * Update schema.prisma * Discard changes to docs/api-reference/v2/openapi.json * Update next-auth-custom-adapter.ts * Update team.ts * Flurry of type fixes * Fix majority of insight related type errors * Type fixes for unlink of account * Make user nullable again * Fixed a bunch of unit tests and one type error * Attempted mock fix * Attempted fix for Attribute type * Ensure default import becomes prisma, but not direct usage * Import default as prisma in prisma.module * Add attributeOption to attribute type * Fix calcom/prisma mock * Refactor Prisma client imports to @calcom/prisma/client Updated all imports from '@prisma/client' to '@calcom/prisma/client' across tests and repository files for consistency and to use the correct Prisma client package. This change improves maintainability and ensures the correct client is referenced throughout the codebase. * Undo removal of max-warnings=0 to get main to merge * Remove unit tests for e2e fixtures, provide new prisma mock * Mock @calcom/prisma in event manager * Mock @calcom/prisma in event manager * Add correct format even with --no-verify * Mock prisma in CalendarManager * Add mock for permission-check.service * Better injection in PrismaApiKeyRepository imports * More mock fixes :) * Fix listMembers.handler.test * Fix User import * Appropriately adjust all types to be imported as types, there were a lot of types imported as normal deps * Why was this a thing? * Strictly speaking; Not using prismock anymore * Ditched patch file for prismock * Fix output.service.ts platform type imports, need concrete for plainToClass * Better typing and tests for unlinkConnectedAccount.handler * Small type fix * Disable calendar cache tests as they are dependent on prismock * chore: bump platform lib * getRoutedUrl test remove of unused import * Extract select to external const on getEventTypesFromDB * Direct select of userSelect from selects/user * fix type error from merging 23653 * Fixed integration tests by removing hardcoded values that were possible due to mocking, but as its now directly hitting the db no longer * fix: vite config atoms prisma client type location * revert: example app prisma client * revert: example app prisma client * bump platform libs * fix: use class instead of type for DI of PlatformBookingsService * update platform libs * remove unused variable * chore: generate prisma client for api v2 * fix: api v2 e2e * fix: atoms e2e * fix: atoms e2e * fix: atoms e2e * fix: api v2 e2e * fix: tsconfig apiv2 enums * publish libraries * Simplify check for existence teamId --------- Signed-off-by: Omar López <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: supalarry <[email protected]> Co-authored-by: cal.com <[email protected]> Co-authored-by: Morgan <[email protected]> Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
623 files changed
+4363
-12559
No files matched your search
@@ -1,7 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { getCalendarCredentials, deduplicateCredentialsBasedOnSelectedCalendars } from "./CalendarManager";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
prisma,
|
||||
}));
|
||||
|
||||
function buildCredential(data: {
|
||||
type: string;
|
||||
appId: string;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/triple-slash-reference */
|
||||
/// <reference path="../types/ical.d.ts"/>
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import ICAL from "ical.js";
|
||||
import type { Attendee, DateArray, DurationObject } from "ics";
|
||||
import { createEvent } from "ics";
|
||||
@@ -18,6 +17,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import sanitizeCalendarObject from "@calcom/lib/sanitizeCalendarObject";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { Person as AttendeeInCalendarEvent } from "@calcom/types/Calendar";
|
||||
import type {
|
||||
Calendar,
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import type { DestinationCalendar } from "@prisma/client";
|
||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
|
||||
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
||||
import type { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
|
||||
import EventManager from "./EventManager";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
prisma,
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/crypto", () => ({
|
||||
symmetricDecrypt: vi.fn(),
|
||||
}));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { DestinationCalendar, BookingReference } from "@prisma/client";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { cloneDeep, merge } from "lodash";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
@@ -22,7 +21,8 @@ import {
|
||||
} from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { CredentialRepository } from "@calcom/lib/server/repository/credential";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { DestinationCalendar, BookingReference } from "@calcom/prisma/client";
|
||||
import { createdEventSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeAppMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { AdditionalInformation, CalendarEvent, NewCalendarEventType } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import type { CredentialDataWithTeamName } from "@calcom/app-store/utils";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { isDelegationCredential } from "../delegationCredential/clientAndServer";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Availability } from "@prisma/client";
|
||||
|
||||
import type { ConfigType } from "@calcom/dayjs";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { Availability } from "@calcom/prisma/client";
|
||||
import type { Schedule, TimeRange, WorkingHours } from "@calcom/types/schedule";
|
||||
|
||||
import { nameOfDay } from "./weekday";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { EventType } from "@prisma/client";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -7,6 +6,7 @@ import { useIsEmbed } from "@calcom/embed-core/embed-iframe";
|
||||
import type { BookingResponse } from "@calcom/features/bookings/types";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { navigateInTopWindow } from "@calcom/lib/navigateInTopWindow";
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
|
||||
import { getSafe } from "./getSafe";
|
||||
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||
|
||||
import type { Mock } from "vitest";
|
||||
import { describe, expect, it, vi, afterEach, beforeEach } from "vitest";
|
||||
|
||||
import { getLuckyUserService } from "@calcom/lib/di/containers/LuckyUser";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { RRResetInterval } from "@calcom/prisma/enums";
|
||||
import { RRResetInterval, RRTimestampBasis } from "@calcom/prisma/enums";
|
||||
|
||||
import { filterHostsByLeadThreshold, errorCodes } from "./filterHostsByLeadThreshold";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
prisma,
|
||||
}));
|
||||
|
||||
const luckyUserService = getLuckyUserService();
|
||||
|
||||
// Mocking setup
|
||||
@@ -17,7 +22,7 @@ const prismaMock = {
|
||||
};
|
||||
|
||||
// Use `vi.spyOn` to make `prisma.booking.groupBy` call the mock instead
|
||||
vi.spyOn(prisma.booking, "groupBy").mockImplementation(prismaMock.booking.groupBy);
|
||||
vi.spyOn(prismaMock.booking, "groupBy").mockImplementation(prismaMock.booking.groupBy);
|
||||
|
||||
// This variable will hold our mock function
|
||||
let getOrderedListOfLuckyUsersMock: Mock;
|
||||
@@ -58,7 +63,9 @@ describe("filterHostByLeadThreshold", () => {
|
||||
team: {
|
||||
parentId: null,
|
||||
rrResetInterval: RRResetInterval.MONTH,
|
||||
rrTimestampBasis: RRTimestampBasis.CREATED_AT,
|
||||
},
|
||||
includeNoShowInRRCalculation: false,
|
||||
},
|
||||
routingFormResponse: null,
|
||||
})
|
||||
@@ -76,7 +83,9 @@ describe("filterHostByLeadThreshold", () => {
|
||||
team: {
|
||||
parentId: null,
|
||||
rrResetInterval: RRResetInterval.MONTH,
|
||||
rrTimestampBasis: RRTimestampBasis.CREATED_AT,
|
||||
},
|
||||
includeNoShowInRRCalculation: false,
|
||||
},
|
||||
routingFormResponse: null,
|
||||
})
|
||||
@@ -123,7 +132,9 @@ describe("filterHostByLeadThreshold", () => {
|
||||
team: {
|
||||
parentId: null,
|
||||
rrResetInterval: RRResetInterval.MONTH,
|
||||
rrTimestampBasis: RRTimestampBasis.CREATED_AT,
|
||||
},
|
||||
includeNoShowInRRCalculation: false,
|
||||
},
|
||||
routingFormResponse: null,
|
||||
})
|
||||
@@ -173,20 +184,6 @@ describe("filterHostByLeadThreshold", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const test = filterHostsByLeadThreshold({
|
||||
hosts,
|
||||
maxLeadThreshold: 3,
|
||||
eventType: {
|
||||
id: 1,
|
||||
isRRWeightsEnabled: true,
|
||||
team: {
|
||||
parentId: null,
|
||||
rrResetInterval: RRResetInterval.MONTH,
|
||||
},
|
||||
},
|
||||
routingFormResponse: null,
|
||||
});
|
||||
|
||||
expect(
|
||||
filterHostsByLeadThreshold({
|
||||
hosts,
|
||||
@@ -197,7 +194,9 @@ describe("filterHostByLeadThreshold", () => {
|
||||
team: {
|
||||
parentId: null,
|
||||
rrResetInterval: RRResetInterval.MONTH,
|
||||
rrTimestampBasis: RRTimestampBasis.CREATED_AT,
|
||||
},
|
||||
includeNoShowInRRCalculation: false,
|
||||
},
|
||||
routingFormResponse: null,
|
||||
})
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
import { getRoutedUsersWithContactOwnerAndFixedUsers } from "./getRoutedUsers";
|
||||
|
||||
vi.mock("@calcom/prisma", () => {
|
||||
return {
|
||||
default: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe("getRoutedUsersWithContactOwnerAndFixedUsers", () => {
|
||||
const users = [
|
||||
{ id: 1, email: "[email protected]", isFixed: false },
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { parseRecurringEvent } from "./isRecurringEvent";
|
||||
import { getTranslation } from "./server/i18n";
|
||||
|
||||
@@ -1,41 +1,60 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getRescheduleLink } from "@calcom/lib/CalEventParser";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { CalendarEventClass } from "./class";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["builders", "CalendarEvent", "builder"] });
|
||||
const translator = short();
|
||||
const userSelect = {
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
username: true,
|
||||
timeZone: true,
|
||||
credentials: true,
|
||||
bufferTime: true,
|
||||
destinationCalendar: true,
|
||||
locale: true,
|
||||
},
|
||||
} satisfies Prisma.UserArgs;
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
username: true,
|
||||
timeZone: true,
|
||||
credentials: true,
|
||||
bufferTime: true,
|
||||
destinationCalendar: true,
|
||||
locale: true,
|
||||
} satisfies Prisma.UserSelect;
|
||||
|
||||
// Single source of truth for user type
|
||||
type User = Prisma.UserGetPayload<{ select: typeof userSelect }>;
|
||||
|
||||
// Base fields that are common between attendees and team members
|
||||
interface PersonAttendeeCommonFields {
|
||||
id: number;
|
||||
email: string;
|
||||
name: string | null;
|
||||
locale: string | null;
|
||||
timeZone: string;
|
||||
username: string | null;
|
||||
}
|
||||
|
||||
// Team members extend the common fields with language
|
||||
interface TeamMember extends PersonAttendeeCommonFields {
|
||||
language: {
|
||||
translate: any;
|
||||
locale: string;
|
||||
};
|
||||
}
|
||||
|
||||
// Add type for event type users that matches Prisma schema
|
||||
type EventTypeUser = Prisma.UserGetPayload<{
|
||||
select: typeof userSelect;
|
||||
}>;
|
||||
|
||||
type User = Omit<Prisma.UserGetPayload<typeof userSelect>, "selectedCalendars">;
|
||||
type PersonAttendeeCommonFields = Pick<User, "id" | "email" | "name" | "locale" | "timeZone" | "username">;
|
||||
interface ICalendarEventBuilder {
|
||||
calendarEvent: CalendarEventClass;
|
||||
eventType: Awaited<ReturnType<CalendarEventBuilder["getEventFromEventId"]>>;
|
||||
users: Awaited<ReturnType<CalendarEventBuilder["getUserById"]>>[];
|
||||
users: User[];
|
||||
attendeesList: PersonAttendeeCommonFields[];
|
||||
teamMembers: Awaited<ReturnType<CalendarEventBuilder["getTeamMembers"]>>;
|
||||
teamMembers: TeamMember[];
|
||||
rescheduleLink: string;
|
||||
}
|
||||
|
||||
@@ -80,7 +99,7 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
|
||||
if (!users.length && this.eventType.userId) {
|
||||
const eventTypeUser = await this.getUserById(this.eventType.userId);
|
||||
if (!eventTypeUser) {
|
||||
throw new Error("buildUsersFromINnerClass.eventTypeUser.notFound");
|
||||
throw new Error("buildUsersFromInnerClass.eventTypeUser.notFound");
|
||||
}
|
||||
users.push(eventTypeUser);
|
||||
}
|
||||
@@ -95,31 +114,24 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
|
||||
];
|
||||
}
|
||||
|
||||
private async getUserById(userId: number) {
|
||||
let resultUser: User | null;
|
||||
private async getUserById(userId: number): Promise<User> {
|
||||
try {
|
||||
resultUser = await prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
...userSelect,
|
||||
return await prisma.user.findUniqueOrThrow({
|
||||
where: { id: userId },
|
||||
select: userSelect,
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error("getUsersById.users.notFound");
|
||||
}
|
||||
return resultUser;
|
||||
}
|
||||
|
||||
private async getEventFromEventId(eventTypeId: number) {
|
||||
let resultEventType;
|
||||
try {
|
||||
resultEventType = await prisma.eventType.findUniqueOrThrow({
|
||||
where: {
|
||||
id: eventTypeId,
|
||||
},
|
||||
return await prisma.eventType.findUniqueOrThrow({
|
||||
where: { id: eventTypeId },
|
||||
select: {
|
||||
id: true,
|
||||
users: userSelect,
|
||||
users: { select: userSelect },
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -154,38 +166,45 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
|
||||
} catch (error) {
|
||||
throw new Error("Error while getting eventType");
|
||||
}
|
||||
log.debug("getEventFromEventId.resultEventType", safeStringify(resultEventType));
|
||||
return resultEventType;
|
||||
}
|
||||
|
||||
public async buildTeamMembers() {
|
||||
this.teamMembers = await this.getTeamMembers();
|
||||
}
|
||||
|
||||
private async getTeamMembers() {
|
||||
private async getTeamMembers(): Promise<TeamMember[]> {
|
||||
if (!this.users.length) {
|
||||
return [];
|
||||
}
|
||||
// Users[0] its organizer so we are omitting with slice(1)
|
||||
const teamMemberPromises = this.users.slice(1).map(async function (user) {
|
||||
return {
|
||||
const teamMemberPromises = this.users.slice(1).map(async (user) => {
|
||||
if (!user) return null;
|
||||
const member: TeamMember = {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email || "", // @NOTE: Should we change this "" to teamMemberId?
|
||||
name: user.name || "",
|
||||
username: user.username ?? null,
|
||||
email: user.email ?? "",
|
||||
name: user.name ?? "",
|
||||
timeZone: user.timeZone,
|
||||
locale: user.locale ?? "en",
|
||||
language: {
|
||||
translate: await getTranslation(user.locale ?? "en", "common"),
|
||||
locale: user.locale ?? "en",
|
||||
},
|
||||
locale: user.locale,
|
||||
} as PersonAttendeeCommonFields;
|
||||
};
|
||||
return member;
|
||||
});
|
||||
return await Promise.all(teamMemberPromises);
|
||||
const members = await Promise.all(teamMemberPromises);
|
||||
return members.filter((member): member is TeamMember => member !== null);
|
||||
}
|
||||
|
||||
public buildUIDCalendarEvent() {
|
||||
if (this.users && this.users.length > 0) {
|
||||
if (!this.users?.length) {
|
||||
throw new Error("call buildUsers before calling this function");
|
||||
}
|
||||
const [mainOrganizer] = this.users;
|
||||
if (!mainOrganizer?.username) {
|
||||
throw new Error("Organizer username is required");
|
||||
}
|
||||
const seed = `${mainOrganizer.username}:${dayjs(this.calendarEvent.startTime)
|
||||
.utc()
|
||||
.format()}:${new Date().getTime()}`;
|
||||
@@ -232,14 +251,8 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
|
||||
}
|
||||
|
||||
public async setUsersFromId(userId: User["id"]) {
|
||||
let resultUser: User | null;
|
||||
try {
|
||||
resultUser = await prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
...userSelect,
|
||||
});
|
||||
const resultUser = await this.getUserById(userId);
|
||||
this.setUsers([resultUser]);
|
||||
} catch (error) {
|
||||
throw new Error("getUsersById.users.notFound");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { DestinationCalendar } from "@prisma/client";
|
||||
|
||||
import type { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type {
|
||||
AdditionalInformation,
|
||||
CalendarEvent,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Booking } from "@prisma/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type { Booking } from "@calcom/prisma/client";
|
||||
|
||||
import type { CalendarEventBuilder } from "./builder";
|
||||
|
||||
|
||||
@@ -4,6 +4,12 @@ import { checkRateLimitAndThrowError } from "./checkRateLimitAndThrowError";
|
||||
import { rateLimiter } from "./rateLimit";
|
||||
import type { RatelimitResponse } from "./rateLimit";
|
||||
|
||||
vi.mock("@calcom/prisma", () => {
|
||||
return {
|
||||
prisma: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./rateLimit", () => {
|
||||
return {
|
||||
rateLimiter: vi.fn(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { SMSLockState } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Prisma, SelectedCalendar } from "@prisma/client";
|
||||
|
||||
import { DailyLocationType } from "@calcom/app-store/constants";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import type { Prisma, SelectedCalendar } from "@calcom/prisma/client";
|
||||
import { PeriodType, SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { userSelect } from "@calcom/prisma/selects";
|
||||
import type { CustomInputSchema } from "@calcom/prisma/zod-utils";
|
||||
@@ -9,7 +8,7 @@ import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/prisma/zod-utils";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
type User = Omit<Prisma.UserGetPayload<typeof userSelect>, "selectedCalendars"> & {
|
||||
type User = Omit<Prisma.UserGetPayload<{ select: typeof userSelect }>, "selectedCalendars"> & {
|
||||
allSelectedCalendars: SelectedCalendar[];
|
||||
userLevelSelectedCalendars: SelectedCalendar[];
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function getEntityPermissionLevel(
|
||||
userId: number
|
||||
) {
|
||||
if (entity.teamId) {
|
||||
const { prisma } = await import("@calcom/prisma");
|
||||
const { default: prisma } = await import("@calcom/prisma");
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
teamId: entity.teamId,
|
||||
@@ -73,7 +73,7 @@ export async function getEntityPermissionLevel(
|
||||
}
|
||||
|
||||
async function getMembership(teamId: number | null, userId: number) {
|
||||
const { prisma } = await import("@calcom/prisma");
|
||||
const { default: prisma } = await import("@calcom/prisma");
|
||||
|
||||
const team = teamId
|
||||
? await prisma.team.findFirst({
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
//import "server-only";
|
||||
import { getLocationGroupedOptions } from "@calcom/app-store/server";
|
||||
import { getEventTypeAppData } from "@calcom/app-store/utils";
|
||||
@@ -14,6 +12,7 @@ import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { EventTypeRepository } from "@calcom/lib/server/repository/eventTypeRepository";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { SchedulingType, MembershipRole } from "@calcom/prisma/enums";
|
||||
import { customInputSchema, eventTypeMetaDataSchemaWithTypedApps } from "@calcom/prisma/zod-utils";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { baseEventTypeSelect } from "@calcom/prisma/selects";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
@@ -44,7 +43,7 @@ const getEventTypesWithHiddenFromDB = async (userId: number) => {
|
||||
"EventType"."price", "EventType"."currency",
|
||||
"EventType"."lockTimeZoneToggleOnBookingPage", "EventType"."lockedTimeZone", "EventType"."requiresConfirmation",
|
||||
"EventType"."requiresBookerEmailVerification", "EventType"."metadata",
|
||||
"EventType"."canSendCalVideoTranscriptionEmails"
|
||||
"EventType"."canSendCalVideoTranscriptionEmails", "EventType"."seatsPerTimeSlot"
|
||||
FROM "EventType"
|
||||
WHERE "EventType"."teamId" IS NULL AND "EventType"."userId" = ${userId}
|
||||
UNION
|
||||
@@ -54,7 +53,7 @@ const getEventTypesWithHiddenFromDB = async (userId: number) => {
|
||||
"EventType"."price", "EventType"."currency",
|
||||
"EventType"."lockTimeZoneToggleOnBookingPage", "EventType"."lockedTimeZone", "EventType"."requiresConfirmation",
|
||||
"EventType"."requiresBookerEmailVerification", "EventType"."metadata",
|
||||
"EventType"."canSendCalVideoTranscriptionEmails"
|
||||
"EventType"."canSendCalVideoTranscriptionEmails", "EventType"."seatsPerTimeSlot"
|
||||
FROM "EventType"
|
||||
WHERE "EventType"."teamId" IS NULL
|
||||
AND "EventType"."userId" IS NOT NULL
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import type { Mock } from "vitest";
|
||||
import { describe, expect, test, vi, afterEach } from "vitest";
|
||||
|
||||
import { WatchlistRepository } from "@calcom/features/watchlist/watchlist.repository";
|
||||
|
||||
import { checkIfFreeEmailDomain } from "./checkIfFreeEmailDomain";
|
||||
|
||||
vi.mock("@calcom/features/watchlist/watchlist.repository", () => {
|
||||
return {
|
||||
WatchlistRepository: vi.fn().mockImplementation(() => ({
|
||||
getFreeEmailDomainInWatchlist: vi.fn().mockResolvedValue(undefined),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
describe("checkIfFreeEmailDomain", () => {
|
||||
test("If gmail should return true", async () => {
|
||||
expect(await checkIfFreeEmailDomain("[email protected]")).toBe(true);
|
||||
@@ -11,18 +20,22 @@ describe("checkIfFreeEmailDomain", () => {
|
||||
test("If outlook should return true", async () => {
|
||||
expect(await checkIfFreeEmailDomain("[email protected]")).toBe(true);
|
||||
});
|
||||
test("If work email, should return false", async () => {
|
||||
const spy = vi.spyOn(WatchlistRepository.prototype, "getFreeEmailDomainInWatchlist");
|
||||
spy.mockImplementation(() => {
|
||||
return null;
|
||||
});
|
||||
expect(await checkIfFreeEmailDomain("[email protected]")).toBe(false);
|
||||
test("If there's no email domain return as if it was a free email domain", async () => {
|
||||
expect(await checkIfFreeEmailDomain("test@")).toBe(true);
|
||||
});
|
||||
test("If free email domain in watchlist, should return true", async () => {
|
||||
const spy = vi.spyOn(WatchlistRepository.prototype, "getFreeEmailDomainInWatchlist");
|
||||
spy.mockImplementation(() => {
|
||||
return { value: "freedomain.com" };
|
||||
});
|
||||
expect(await checkIfFreeEmailDomain("[email protected]")).toBe(true);
|
||||
const WatchlistRepoMock = WatchlistRepository as Mock;
|
||||
|
||||
await checkIfFreeEmailDomain("test@freedomain.com");
|
||||
|
||||
expect(WatchlistRepoMock).toHaveBeenCalled();
|
||||
|
||||
const mockInstance = WatchlistRepoMock.mock.results.at(-1)?.value;
|
||||
|
||||
expect(mockInstance.getFreeEmailDomainInWatchlist).toHaveBeenCalledWith("freedomain.com");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { bookingResponsesDbSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
type BookingSelect = {
|
||||
description: true;
|
||||
@@ -88,7 +88,7 @@ async function getBooking(prisma: PrismaClient, uid: string) {
|
||||
return booking;
|
||||
}
|
||||
|
||||
export type GetBookingType = Prisma.PromiseReturnType<typeof getBooking>;
|
||||
export type GetBookingType = Awaited<ReturnType<typeof getBooking>>;
|
||||
|
||||
export const getBookingWithResponses = <
|
||||
T extends Prisma.BookingGetPayload<{
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
|
||||
import { getBusyTimesService } from "./di/containers/BusyTimes";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
prisma,
|
||||
}));
|
||||
|
||||
const startOfTomorrow = dayjs().add(1, "day").startOf("day");
|
||||
const tomorrowDate = startOfTomorrow.format("YYYY-MM-DD");
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import type { Booking, EventType } from "@prisma/client";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getBusyCalendarTimes } from "@calcom/lib/CalendarManager";
|
||||
import { subtract } from "@calcom/lib/date-ranges";
|
||||
@@ -13,6 +10,8 @@ import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import { performance } from "@calcom/lib/server/perfObserver";
|
||||
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Booking, EventType } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { EventBusyDetails } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import type { SelectedCalendar } from "@prisma/client";
|
||||
import "../../tests/libs/__mocks__/prisma";
|
||||
|
||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
import GoogleCalendarService from "@calcom/app-store/googlecalendar/lib/CalendarService";
|
||||
import OfficeCalendarService from "@calcom/app-store/office365calendar/lib/CalendarService";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { EventBusyDate } from "@calcom/types/Calendar";
|
||||
import type { CredentialForCalendarService, CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
import type {
|
||||
Booking,
|
||||
Prisma,
|
||||
OutOfOfficeEntry,
|
||||
OutOfOfficeReason,
|
||||
User,
|
||||
EventType as PrismaEventType,
|
||||
} from "@prisma/client";
|
||||
import * as Sentry from "@sentry/nextjs";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -31,6 +23,14 @@ import { findUsersForAvailabilityCheck } from "@calcom/lib/server/findUsersForAv
|
||||
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import { EventTypeRepository } from "@calcom/lib/server/repository/eventTypeRepository";
|
||||
import type { PrismaOOORepository } from "@calcom/lib/server/repository/ooo";
|
||||
import type {
|
||||
Booking,
|
||||
Prisma,
|
||||
OutOfOfficeEntry,
|
||||
OutOfOfficeReason,
|
||||
User,
|
||||
EventType as PrismaEventType,
|
||||
} from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import type { EventType } from "@prisma/client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { createEventTypeInput } from "@calcom/features/eventtypes/lib/types";
|
||||
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { unlockedManagedEventTypeProps } from "@calcom/prisma/zod-utils";
|
||||
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
export type CreateEventTypeFormValues = z.infer<typeof createEventTypeInput>;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { EventType } from "@prisma/client";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
import { PeriodType } from "@calcom/prisma/enums";
|
||||
|
||||
import { ROLLING_WINDOW_PERIOD_MAX_DAYS_TO_CHECK } from "./constants";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
function isPrismaObj(obj: unknown): obj is Prisma.JsonObject {
|
||||
return typeof obj === "object" && !Array.isArray(obj);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { Payment, Prisma } from "@prisma/client";
|
||||
|
||||
import { PaymentServiceMap } from "@calcom/app-store/payment.services.generated";
|
||||
import type { AppCategories } from "@calcom/prisma/enums";
|
||||
import type { Payment, Prisma, AppCategories } from "@calcom/prisma/client";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
|
||||
const deletePayment = async (
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
// eslint-disable-next-line
|
||||
import { PaymentServiceMap } from "@calcom/app-store/payment.services.generated";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -12,6 +10,7 @@ import { CredentialRepository } from "@calcom/lib/server/repository/credential";
|
||||
import { MembershipRepository } from "@calcom/lib/server/repository/membership";
|
||||
import { TeamRepository } from "@calcom/lib/server/repository/team";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { Payment, Prisma } from "@prisma/client";
|
||||
|
||||
import { PaymentServiceMap } from "@calcom/app-store/payment.services.generated";
|
||||
import type { AppCategories } from "@calcom/prisma/enums";
|
||||
import type { Payment, Prisma, AppCategories } from "@calcom/prisma/client";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
|
||||
const handlePaymentRefund = async (
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Payment, Prisma } from "@prisma/client";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Payment, Prisma } from "@calcom/prisma/client";
|
||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { getPaymentAppData } from "../getPaymentAppData";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Credential, SelectedCalendar, DestinationCalendar } from "@prisma/client";
|
||||
|
||||
import type { Credential, SelectedCalendar, DestinationCalendar } from "@calcom/prisma/client";
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
|
||||
@@ -12,7 +12,12 @@ import type { AttributeType } from "@calcom/prisma/enums";
|
||||
import { RoutingFormFieldType } from "@calcom/routing-forms/lib/FieldTypes";
|
||||
import type { AttributesQueryValue, FormFieldsQueryValue } from "@calcom/routing-forms/types/types";
|
||||
|
||||
vi.mock("@calcom/lib/service/attribute/server/getAttributes");
|
||||
vi.mock("@calcom/lib/service/attribute/server/getAttributes", () => {
|
||||
return {
|
||||
getAttributesAssignmentData: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../components/react-awesome-query-builder/widgets", () => ({
|
||||
default: {},
|
||||
}));
|
||||
|
||||
@@ -5,6 +5,8 @@ import logger from "./logger";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["RateLimit"] });
|
||||
|
||||
export { type RatelimitResponse };
|
||||
|
||||
export type RateLimitHelper = {
|
||||
rateLimitingType?: "core" | "forcedSlowMode" | "common" | "api" | "ai" | "sms" | "smsMonth";
|
||||
identifier: string;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { Availability } from "@prisma/client";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getWorkingHours } from "@calcom/lib/availability";
|
||||
import { yyyymmdd } from "@calcom/lib/dayjs";
|
||||
import type { Availability } from "@calcom/prisma/client";
|
||||
import type { Schedule, TimeRange } from "@calcom/types/schedule";
|
||||
|
||||
type ScheduleAvailability = Pick<Availability, "days" | "startTime" | "endTime">[];
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
|
||||
import { availabilityUserSelect } from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
import { withSelectedCalendars } from "./withSelectedCalendars";
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { Prisma, User } from "@prisma/client";
|
||||
|
||||
import type { FormResponse, Fields } from "@calcom/app-store/routing-forms/types/types";
|
||||
import { zodRoutes } from "@calcom/app-store/routing-forms/zod";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -13,8 +11,8 @@ import type { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import type { HostRepository } from "@calcom/lib/server/repository/host";
|
||||
import type { PrismaOOORepository } from "@calcom/lib/server/repository/ooo";
|
||||
import type { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import type { Booking } from "@calcom/prisma/client";
|
||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { User, Booking, SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { AttributeType } from "@calcom/prisma/enums";
|
||||
import { RRTimestampBasis, RRResetInterval } from "@calcom/prisma/enums";
|
||||
import type { EventBusyDate } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { ZodIssue } from "zod";
|
||||
import { ZodError } from "zod";
|
||||
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { ErrorWithCode } from "@calcom/lib/errors";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { getHTTPStatusCodeFromError } from "@trpc/server/http";
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import { z } from "zod";
|
||||
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import { DATABASE_CHUNK_SIZE } from "@calcom/lib/constants";
|
||||
import { parseBookingLimit } from "@calcom/lib/intervalLimits/isBookingLimits";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import prisma, { baseEventTypeSelect } from "@calcom/prisma";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { Team } from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { _EventTypeModel } from "@calcom/prisma/zod";
|
||||
import { baseEventTypeSelect } from "@calcom/prisma/selects";
|
||||
import { EventTypeSchema } from "@calcom/prisma/zod/modelSchema/EventTypeSchema";
|
||||
import {
|
||||
EventTypeMetaDataSchema,
|
||||
allManagedEventTypeProps,
|
||||
unlockedManagedEventTypeProps,
|
||||
eventTypeLocations,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
|
||||
import { getBookerBaseUrlSync } from "../../../getBookerUrl/client";
|
||||
@@ -433,13 +436,19 @@ export function generateNewChildEventTypeDataForDB({
|
||||
includeWorkflow = true,
|
||||
includeUserConnect = true,
|
||||
}: {
|
||||
eventType: Prisma.EventTypeGetPayload<{ select: typeof allManagedEventTypeProps & { id: true } }>;
|
||||
eventType: Omit<
|
||||
Prisma.EventTypeGetPayload<{ select: typeof allManagedEventTypeProps & { id: true } }>,
|
||||
"locations"
|
||||
> & { locations: Prisma.JsonValue | null };
|
||||
userId: number;
|
||||
includeWorkflow?: boolean;
|
||||
includeUserConnect?: boolean;
|
||||
}) {
|
||||
const allManagedEventTypePropsZod = _EventTypeModel.pick(allManagedEventTypeProps).extend({
|
||||
bookingFields: _EventTypeModel.shape.bookingFields.nullish(),
|
||||
const allManagedEventTypePropsZod = EventTypeSchema.pick(allManagedEventTypeProps).extend({
|
||||
bookingFields: EventTypeSchema.shape.bookingFields.nullish(),
|
||||
locations: z
|
||||
.preprocess((val: unknown) => (val === null ? undefined : val), eventTypeLocations)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const managedEventTypeValues = allManagedEventTypePropsZod
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
interface _AgentRawResult {
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { generateUniqueAPIKey as generateHashedApiKey } from "@calcom/ee/api-keys/lib/apiKeys";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
export class PrismaApiKeyRepository {
|
||||
static async findApiKeysFromUserId({ userId }: { userId: number }) {
|
||||
const apiKeys = await prisma.apiKey.findMany({
|
||||
constructor(private prismaClient: PrismaClient) {}
|
||||
|
||||
static async withGlobalPrisma() {
|
||||
return new PrismaApiKeyRepository((await import("@calcom/prisma")).prisma);
|
||||
}
|
||||
|
||||
async findApiKeysFromUserId({ userId }: { userId: number }) {
|
||||
const apiKeys = await this.prismaClient.apiKey.findMany({
|
||||
where: {
|
||||
userId,
|
||||
OR: [
|
||||
@@ -29,7 +35,7 @@ export class PrismaApiKeyRepository {
|
||||
});
|
||||
}
|
||||
|
||||
static async createApiKey({
|
||||
async createApiKey({
|
||||
userId,
|
||||
teamId,
|
||||
note,
|
||||
@@ -41,7 +47,7 @@ export class PrismaApiKeyRepository {
|
||||
expiresAt?: Date | null;
|
||||
}) {
|
||||
const [hashedApiKey, apiKey] = generateHashedApiKey();
|
||||
await prisma.apiKey.create({
|
||||
await this.prismaClient.apiKey.create({
|
||||
data: {
|
||||
id: uuidv4(),
|
||||
userId,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
export class PrismaAttributeOptionRepository {
|
||||
static async findMany({ orgId }: { orgId: number }) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
export class PrismaAttributeToUserRepository {
|
||||
static async createManySkipDuplicates(data: Prisma.AttributeToUserCreateManyInput[]) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import { PhoneNumberSubscriptionStatus } from "@calcom/prisma/enums";
|
||||
|
||||
interface _PhoneNumberRawResult {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { App_RoutingForms_Form, App_RoutingForms_FormResponse } from "@prisma/client";
|
||||
import type { App_RoutingForms_Form, App_RoutingForms_FormResponse } from "@calcom/prisma/client";
|
||||
|
||||
export interface RoutingFormResponseRepositoryInterface {
|
||||
findByIdIncludeForm(
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import prismaMock from "../../../../tests/libs/__mocks__/prismaMock";
|
||||
|
||||
import type { Team } from "@prisma/client";
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
import type { Team } from "@calcom/prisma/client";
|
||||
|
||||
import { TeamRepository } from "./team";
|
||||
|
||||
describe("TeamRepository", () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { Booking } from "@calcom/prisma/client";
|
||||
import { RRTimestampBasis, BookingStatus } from "@calcom/prisma/enums";
|
||||
import { bookingMinimalSelect } from "@calcom/prisma/selects/booking";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { PartialReference } from "@calcom/types/EventManager";
|
||||
|
||||
const bookingReferenceSelect = {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { safeCredentialSelect } from "@calcom/prisma/selects/credential";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import {
|
||||
serviceAccountKeySchema,
|
||||
@@ -9,6 +7,7 @@ import {
|
||||
decryptServiceAccountKey,
|
||||
} from "@calcom/lib/server/serviceAccountKey";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { OrganizationRepository } from "./organization";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { PrismaClient as PrismaClientWithoutExtensions } from "@prisma/client";
|
||||
|
||||
import type { PrismaClient as PrismaClientWithExtensions } from "@calcom/prisma";
|
||||
import type { PrismaClient as PrismaClientWithoutExtensions } from "@calcom/prisma/client";
|
||||
|
||||
import type { IDeploymentRepository } from "./deployment.interface";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { buildCredentialPayloadForPrisma } from "../buildCredentialPayloadForCalendar";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { SelectedSlots } from "@prisma/client";
|
||||
import type { SelectedSlots } from "@calcom/prisma/client";
|
||||
|
||||
export type SelectedSlot = Pick<
|
||||
SelectedSlots,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
type EnforceTrueOrNested<T> = {
|
||||
[K in keyof T]: T[K] extends object ? EnforceTrueOrNested<T[K]> : true; // only allow `true` at leaves
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { EventType as PrismaEventType } from "@prisma/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { prisma, availabilityUserSelect } from "@calcom/prisma";
|
||||
import type { EventType as PrismaEventType } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
import { availabilityUserSelect, prisma, type PrismaTransaction } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { Prisma, Membership, PrismaClient } from "@calcom/prisma/client";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { User as PrismaUser } from "@prisma/client";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { whereClauseForOrgWithSlugOrRequestedSlug } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
@@ -6,6 +5,7 @@ import { getOrgUsernameFromEmail } from "@calcom/features/auth/signup/utils/getO
|
||||
import { DATABASE_CHUNK_SIZE } from "@calcom/lib/constants";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { User as PrismaUser } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { Team } from "@calcom/prisma/client";
|
||||
import { userMetadata } from "@calcom/prisma/zod-utils";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import type { SelectedCalendarEventTypeIds } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -257,7 +256,12 @@ export class SelectedCalendarRepository {
|
||||
}
|
||||
|
||||
static async findMany({ where, select, orderBy }: FindManyArgs) {
|
||||
return await prisma.selectedCalendar.findMany({ where, select, orderBy });
|
||||
const args = {
|
||||
where,
|
||||
select,
|
||||
orderBy,
|
||||
} satisfies Prisma.SelectedCalendarFindManyArgs;
|
||||
return await prisma.selectedCalendar.findMany(args);
|
||||
}
|
||||
|
||||
static async findUniqueOrThrow({ where }: { where: Prisma.SelectedCalendarWhereInput }) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { whereClauseForOrgWithSlugOrRequestedSlug } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@ import { whereClauseForOrgWithSlugOrRequestedSlug } from "@calcom/ee/organizatio
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { availabilityUserSelect } from "@calcom/prisma";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { Prisma, User as UserType } from "@calcom/prisma/client";
|
||||
import { availabilityUserSelect } from "@calcom/prisma";
|
||||
import type { User as UserType } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { CreationSource } from "@calcom/prisma/enums";
|
||||
import { MembershipRole, BookingStatus } from "@calcom/prisma/enums";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Workflow } from "@prisma/client";
|
||||
|
||||
import type { Workflow } from "@calcom/prisma/client";
|
||||
import { isAuthorized } from "@calcom/trpc/server/routers/viewer/workflows/util";
|
||||
|
||||
export interface WorkflowPermissions {
|
||||
|
||||
@@ -8,8 +8,8 @@ import type { WorkflowStep } from "@calcom/ee/workflows/lib/types";
|
||||
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { WorkflowMethods } from "@calcom/prisma/enums";
|
||||
import type { TFilteredListInputSchema } from "@calcom/trpc/server/routers/viewer/workflows/filteredList.schema";
|
||||
import type { TGetVerifiedEmailsInputSchema } from "@calcom/trpc/server/routers/viewer/workflows/getVerifiedEmails.schema";
|
||||
@@ -25,47 +25,45 @@ export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;
|
||||
|
||||
const deleteScheduledWhatsappReminder = deleteScheduledSMSReminder;
|
||||
|
||||
const { include: includedFields } = {
|
||||
include: {
|
||||
activeOn: {
|
||||
select: {
|
||||
eventType: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
parentId: true,
|
||||
_count: {
|
||||
select: {
|
||||
children: true,
|
||||
},
|
||||
const includedFields = {
|
||||
activeOn: {
|
||||
select: {
|
||||
eventType: {
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
parentId: true,
|
||||
_count: {
|
||||
select: {
|
||||
children: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
activeOnTeams: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
activeOnTeams: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
steps: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
name: true,
|
||||
members: true,
|
||||
logoUrl: true,
|
||||
isOrganization: true,
|
||||
},
|
||||
},
|
||||
steps: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
name: true,
|
||||
members: true,
|
||||
logoUrl: true,
|
||||
isOrganization: true,
|
||||
},
|
||||
},
|
||||
} satisfies Prisma.WorkflowDefaultArgs;
|
||||
} satisfies Prisma.WorkflowInclude;
|
||||
|
||||
export class WorkflowRepository {
|
||||
private static log = logger.getSubLogger({ prefix: ["workflow"] });
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import md5 from "md5";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -13,6 +12,7 @@ import {
|
||||
isNumberFilterValue,
|
||||
} from "@calcom/features/data-table/lib/utils";
|
||||
import type { DateRange } from "@calcom/features/insights/server/insightsDateUtils";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { z } from "zod";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
@@ -13,6 +12,7 @@ import {
|
||||
} from "@calcom/features/data-table/lib/utils";
|
||||
import type { DateRange } from "@calcom/features/insights/server/insightsDateUtils";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import type { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Team, User, Membership } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ColumnFilterType } from "@calcom/features/data-table/lib/types";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Team, User, Membership } from "@calcom/prisma/client";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import { BookingStatus, MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { InsightsBookingBaseService as InsightsBookingService } from "../InsightsBookingBaseService";
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { Team, User, Membership } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { randomUUID } from "crypto";
|
||||
import { v4 as uuid } from "uuid";
|
||||
import { describe, expect, it, vi, beforeAll, afterAll } from "vitest";
|
||||
|
||||
import { ColumnFilterType } from "@calcom/features/data-table/lib/types";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Team, User, Membership } from "@calcom/prisma/client";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import { BookingStatus, MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { InsightsRoutingBaseService as InsightsRoutingService } from "../../service/InsightsRoutingBaseService";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Team, User } from "@prisma/client";
|
||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Team, User } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { TeamService } from "../teamService";
|
||||
@@ -209,15 +209,15 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
// Create organization structure
|
||||
const orgTeam = await createTestTeam({ isOrganization: true });
|
||||
const subTeam = await createTestTeam({ parentId: orgTeam.id });
|
||||
|
||||
|
||||
// Create users
|
||||
const orgUser1 = await createTestUser({ organizationId: orgTeam.id });
|
||||
const orgUser2 = await createTestUser({ organizationId: orgTeam.id });
|
||||
const nonOrgUser = await createTestUser();
|
||||
|
||||
|
||||
// Create regular team
|
||||
const regularTeamEntity = await createTestTeam();
|
||||
|
||||
|
||||
// Set up memberships
|
||||
await createTestMembership(orgUser1.id, orgTeam.id);
|
||||
await createTestMembership(orgUser2.id, orgTeam.id);
|
||||
@@ -227,36 +227,35 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
await createTestMembership(orgUser2.id, subTeam.id);
|
||||
await createTestMembership(nonOrgUser.id, regularTeamEntity.id);
|
||||
await createTestMembership(nonOrgUser.id, subTeam.id);
|
||||
|
||||
|
||||
// Structure the test data
|
||||
orgTestData = {
|
||||
team: orgTeam,
|
||||
teams: [{
|
||||
team: subTeam,
|
||||
members: [orgUser1, orgUser2]
|
||||
}],
|
||||
members: [orgUser1, orgUser2]
|
||||
teams: [
|
||||
{
|
||||
team: subTeam,
|
||||
members: [orgUser1, orgUser2],
|
||||
},
|
||||
],
|
||||
members: [orgUser1, orgUser2],
|
||||
};
|
||||
|
||||
|
||||
regularTeamTestData = {
|
||||
team: regularTeamEntity,
|
||||
members: [orgUser1, orgUser2, nonOrgUser]
|
||||
members: [orgUser1, orgUser2, nonOrgUser],
|
||||
};
|
||||
|
||||
|
||||
userWithoutOrg = nonOrgUser;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const teamIds = [
|
||||
orgTestData.team.id,
|
||||
...orgTestData.teams.map(t => t.team.id),
|
||||
regularTeamTestData.team.id
|
||||
...orgTestData.teams.map((t) => t.team.id),
|
||||
regularTeamTestData.team.id,
|
||||
];
|
||||
const userIds = [
|
||||
...orgTestData.members.map(u => u.id),
|
||||
userWithoutOrg.id
|
||||
];
|
||||
|
||||
const userIds = [...orgTestData.members.map((u) => u.id), userWithoutOrg.id];
|
||||
|
||||
await cleanupTestData(teamIds, userIds);
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
@@ -264,10 +263,10 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
describe("Team Removal - Sub-Team/Regular Team", () => {
|
||||
it("should remove members from a single team", async () => {
|
||||
const [orgUser1, orgUser2] = orgTestData.members;
|
||||
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgUser1.id, orgUser2.id]
|
||||
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgUser1.id, orgUser2.id],
|
||||
});
|
||||
|
||||
await expectMembershipNotExists(orgUser1.id, regularTeamTestData.team.id);
|
||||
@@ -283,10 +282,10 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
it("should remove members from multiple teams", async () => {
|
||||
const [orgUser1] = orgTestData.members;
|
||||
const subTeam = orgTestData.teams[0].team;
|
||||
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id, subTeam.id],
|
||||
userIds: [orgUser1.id]
|
||||
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id, subTeam.id],
|
||||
userIds: [orgUser1.id],
|
||||
});
|
||||
|
||||
await expectMembershipNotExists(orgUser1.id, regularTeamTestData.team.id);
|
||||
@@ -337,7 +336,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
expect(hostsBefore).toHaveLength(3);
|
||||
|
||||
// Remove member from team (not org)
|
||||
await TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [teamMember.id], isOrg: false });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [teamMember.id],
|
||||
isOrg: false,
|
||||
});
|
||||
|
||||
// Verify hosts for team events were removed
|
||||
const hostsAfterForTeamEvents = await prisma.host.findMany({
|
||||
@@ -410,7 +413,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
});
|
||||
|
||||
// Remove orgTestData.members[0] from team
|
||||
await TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [orgTestData.members[0].id], isOrg: false });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
isOrg: false,
|
||||
});
|
||||
|
||||
// Verify orgTestData.members[0]'s managed event types were deleted
|
||||
const deletedEventType1 = await prisma.eventType.findUnique({
|
||||
@@ -447,7 +454,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
});
|
||||
|
||||
it("should not modify user organization data when removing from sub-team", async () => {
|
||||
await TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [orgTestData.members[0].id], isOrg: false });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
isOrg: false,
|
||||
});
|
||||
|
||||
await expectMembershipNotExists(orgTestData.members[0].id, regularTeamTestData.team.id);
|
||||
|
||||
@@ -464,7 +475,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
it("should remove members from organization and all sub-teams", async () => {
|
||||
const originalUsername = orgTestData.members[0].username || "";
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [orgTestData.members[0].id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
await expectMembershipNotExists(orgTestData.members[0].id, orgTestData.team.id);
|
||||
await expectMembershipExists(orgTestData.members[0].id, regularTeamTestData.team.id);
|
||||
@@ -493,7 +508,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
const eventType = await createTestEventType(orgTestData.teams[0].team.id);
|
||||
await createTestHost(orgTestData.members[0].id, eventType.id);
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [orgTestData.members[0].id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
const hosts = await prisma.host.findMany({
|
||||
where: {
|
||||
@@ -522,7 +541,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
organizationId: null,
|
||||
});
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [userInOrg.id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [userInOrg.id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
const updatedUser = await prisma.user.findUnique({
|
||||
where: { id: userInOrg.id },
|
||||
@@ -573,7 +596,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [profileUser.id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [profileUser.id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
const deletedProfile = await prisma.profile.findUnique({
|
||||
where: { id: profile.id },
|
||||
@@ -588,7 +615,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
await createTestMembership(userWithoutProfile.id, orgTestData.team.id);
|
||||
|
||||
await expect(
|
||||
TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [userWithoutProfile.id], isOrg: true })
|
||||
TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [userWithoutProfile.id],
|
||||
isOrg: true,
|
||||
})
|
||||
).resolves.not.toThrow();
|
||||
|
||||
await expectMembershipNotExists(userWithoutProfile.id, orgTestData.team.id);
|
||||
@@ -623,7 +654,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [userWithProfile.id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [userWithProfile.id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
const redirects = await prisma.tempOrgRedirect.findMany({
|
||||
where: { from: userWithProfile.username || "" },
|
||||
@@ -653,7 +688,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [userWithUsername.id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [userWithUsername.id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
const updatedUser = await prisma.user.findUnique({
|
||||
where: { id: userWithUsername.id },
|
||||
@@ -863,7 +902,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
expect(eventsBeforeRemoval).toHaveLength(3);
|
||||
|
||||
// Remove orgTestData.members[0] from organization
|
||||
await TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [orgTestData.members[0].id], isOrg: true });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
isOrg: true,
|
||||
});
|
||||
|
||||
// Verify orgTestData.members[0]'s managed events in all sub-teams were deleted
|
||||
const deletedEvent1 = await prisma.eventType.findUnique({
|
||||
@@ -912,7 +955,10 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
it("should call TeamBilling.updateQuantity for each team", async () => {
|
||||
const { TeamBilling } = await import("@calcom/features/ee/billing/teams");
|
||||
|
||||
await TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [orgTestData.members[0].id, orgTestData.members[1].id] });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id, orgTestData.members[1].id],
|
||||
});
|
||||
|
||||
expect(TeamBilling.findAndInitMany).toHaveBeenCalledWith([regularTeamTestData.team.id]);
|
||||
const mockInstances = await TeamBilling.findAndInitMany([regularTeamTestData.team.id]);
|
||||
@@ -928,16 +974,26 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
});
|
||||
|
||||
it("should gracefully skip when given empty arrays", async () => {
|
||||
await expect(TeamService.removeMembers({ teamIds: [], userIds: [orgTestData.members[0].id] })).resolves.not.toThrow();
|
||||
await expect(TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [] })).resolves.not.toThrow();
|
||||
await expect(
|
||||
TeamService.removeMembers({ teamIds: [], userIds: [orgTestData.members[0].id] })
|
||||
).resolves.not.toThrow();
|
||||
await expect(
|
||||
TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [] })
|
||||
).resolves.not.toThrow();
|
||||
await expect(TeamService.removeMembers({ teamIds: [], userIds: [] })).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
it("should throw error on second removal attempt of same member", async () => {
|
||||
await TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [orgTestData.members[0].id] });
|
||||
await TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
});
|
||||
|
||||
await expect(
|
||||
TeamService.removeMembers({ teamIds: [regularTeamTestData.team.id], userIds: [orgTestData.members[0].id] })
|
||||
TeamService.removeMembers({
|
||||
teamIds: [regularTeamTestData.team.id],
|
||||
userIds: [orgTestData.members[0].id],
|
||||
})
|
||||
).rejects.toThrow("Membership not found");
|
||||
});
|
||||
|
||||
@@ -978,7 +1034,11 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
|
||||
// This should fail because of username unique constraint violation
|
||||
await expect(
|
||||
TeamService.removeMembers({ teamIds: [orgTestData.team.id], userIds: [rollbackTestUser.id], isOrg: true })
|
||||
TeamService.removeMembers({
|
||||
teamIds: [orgTestData.team.id],
|
||||
userIds: [rollbackTestUser.id],
|
||||
isOrg: true,
|
||||
})
|
||||
).rejects.toThrow();
|
||||
|
||||
// Verify nothing was changed - all data should still exist due to transaction rollback
|
||||
@@ -1014,4 +1074,4 @@ describe("TeamService.removeMembers Integration Tests", () => {
|
||||
await cleanupTestData([subTeamForRollback.id], [rollbackTestUser.id, conflictingUser.id]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import type { appDataSchemas } from "@calcom/app-store/apps.schemas.generated";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { EventTypeMetaDataSchema, EventTypeAppMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export class EventTypeService {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
import { TeamBilling } from "@calcom/features/ee/billing/teams";
|
||||
@@ -7,6 +9,10 @@ import { WorkflowService } from "@calcom/lib/server/service/workflows";
|
||||
|
||||
import { TeamService } from "./teamService";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
prisma,
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/billing/teams");
|
||||
vi.mock("@calcom/lib/server/repository/team");
|
||||
vi.mock("@calcom/lib/server/service/workflows");
|
||||
@@ -45,6 +51,7 @@ const mockTeamRepo = {
|
||||
throw new Error(`Team with id ${id} not found`);
|
||||
}),
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as any);
|
||||
|
||||
vi.mocked(deleteDomain).mockImplementation(async (slug) => {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import { TeamBilling } from "@calcom/features/ee/billing/teams";
|
||||
import { deleteWorkfowRemindersOfRemovedMember } from "@calcom/features/ee/teams/lib/deleteWorkflowRemindersOfRemovedMember";
|
||||
import { deleteDomain } from "@calcom/lib/domainManager/organization";
|
||||
@@ -7,7 +5,8 @@ import logger from "@calcom/lib/logger";
|
||||
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import { TeamRepository } from "@calcom/lib/server/repository/team";
|
||||
import { WorkflowService } from "@calcom/lib/server/service/workflows";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
import type { Membership } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import { z } from "zod";
|
||||
|
||||
import { SERVICE_ACCOUNT_ENCRYPTION_KEY } from "@calcom/lib/constants";
|
||||
import { symmetricEncrypt, symmetricDecrypt } from "@calcom/lib/crypto";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { serviceAccountKeySchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
export type ServiceAccountKey = z.infer<typeof serviceAccountKeySchema>;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import type { Booking, EventType, Prisma, Webhook, BookingReference } from "@prisma/client";
|
||||
import type { TFunction } from "i18next";
|
||||
|
||||
import getICalUID from "@calcom/emails/lib/getICalUID";
|
||||
import type { Booking, EventType, Prisma, Webhook, BookingReference } from "@calcom/prisma/client";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent, Person, VideoCallData } from "@calcom/types/Calendar";
|
||||
|
||||
Reference in new issue
Block a user