Files
calendar/packages/features/noShow/handleSendingAttendeeNoShowDataToApps.ts
T
Keith WilliamsGitHubkeith@cal.com <keithwillcode@gmail.com>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>hbjORbj
79a09362c9 refactor: remove circular dependency between prisma and app-store packages (#23475)
* refactor: remove circular dependency between prisma and app-store packages

- Replace EventTypeAppMetadataSchema with z.record(z.any()).optional() pattern
- Remove appDataSchemas import from packages/prisma/zod-utils.ts
- Add null checks in consuming packages for flexible validation
- Fix test file that no longer needs @ts-expect-error directive

This breaks the circular dependency while maintaining all functionality
by moving strict validation to the business logic layer where operations
actually happen, following existing patterns in the codebase.

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* refactor: remove EventTypeAppMetadataSchema exports from prisma package

- Remove EventTypeAppMetadataSchema and eventTypeAppMetadataOptionalSchema exports from prisma/zod-utils.ts
- Update all importing files to use local z.record(z.any()).optional() schemas
- Replace type annotations with Record<string, any> where appropriate
- Maintain validation functionality while breaking circular dependency
- All TypeScript compilation now passes without errors

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* refactor: complete removal of EventTypeAppMetadataSchema from remaining files

- Update handleSeats/createNewSeat.ts to use local schema
- Update payment handlers to use local schemas
- Update eventTypes update handler to use local schema
- All files now define their own validation instead of importing from prisma
- Circular dependency completely eliminated

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: resolve TypeScript compilation errors

- Remove duplicate z import from handleConfirmation.ts
- Remove duplicate appDataSchemas import from update.handler.ts
- Fix index signature errors in handlePayment.ts by using appData variable consistently
- All type checks now pass successfully

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix: add type casting for appSlug in eventTypeService

- Cast appSlug as keyof typeof apps to resolve index signature error
- Maintains type safety while allowing dynamic property access

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>

* fix

* remove

* make zod-utils.ts in app-store

* update imports

* fix

* fix

* fix

* revert unrelated change

* update imports

* fix

* fix

* revert

* fix

* fix

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: hbjORbj <sldisek783@gmail.com>
2025-09-12 05:57:09 -03:00

87 lines
2.4 KiB
TypeScript

import type { z } from "zod";
import type { eventTypeAppCardZod } from "@calcom/app-store/eventTypeAppCardZod";
import { eventTypeAppMetadataOptionalSchema } from "@calcom/app-store/zod-utils";
import CrmManager from "@calcom/lib/crmManager/crmManager";
import logger from "@calcom/lib/logger";
import prisma from "@calcom/prisma";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import type { NoShowAttendees } from "../handleMarkNoShow";
import { noShowEnabledApps } from "./noShowEnabledApps";
const log = logger.getSubLogger({ prefix: ["handleSendingNoShowDataToApps"] });
export default async function handleSendingAttendeeNoShowDataToApps(
bookingUid: string,
attendees: NoShowAttendees
) {
// Get event type metadata
const eventTypeQuery = await prisma.booking.findUnique({
where: {
uid: bookingUid,
},
select: {
eventType: {
select: {
metadata: true,
},
},
},
});
if (!eventTypeQuery || !eventTypeQuery?.eventType?.metadata) {
log.warn(`For no show, could not find eventType for bookingUid ${bookingUid}`);
return;
}
const eventTypeMetadataParse = EventTypeMetaDataSchema.safeParse(eventTypeQuery?.eventType?.metadata);
if (!eventTypeMetadataParse.success) {
log.error(`Malformed event type metadata for bookingUid ${bookingUid}`);
return;
}
const eventTypeAppMetadata = eventTypeAppMetadataOptionalSchema.parse(eventTypeMetadataParse.data?.apps);
for (const slug in eventTypeAppMetadata) {
if (noShowEnabledApps.includes(slug)) {
const app = eventTypeAppMetadata[slug as keyof typeof eventTypeAppMetadata];
const appCategory = app.appCategories[0];
if (appCategory === "crm") {
await handleCRMNoShow(bookingUid, app, attendees);
}
}
}
return;
}
async function handleCRMNoShow(
bookingUid: string,
appData: z.infer<typeof eventTypeAppCardZod>,
attendees: NoShowAttendees
) {
// Handle checking if no she in CrmService
const credential = await prisma.credential.findUnique({
where: {
id: appData.credentialId,
},
include: {
user: {
select: {
email: true,
},
},
},
});
if (!credential) {
log.warn(`CRM credential not found for bookingUid ${bookingUid}`);
return;
}
const crm = new CrmManager(credential, appData);
await crm.handleAttendeeNoShow(bookingUid, attendees);
}