* feat: add CalendarsTasker with sync and trigger.dev versions This PR implements a CalendarsTasker following the same pattern as PlatformOrganizationBillingTasker to replace the logic in apps/api/v2/src/ee/calendars/processors/calendars.processor.ts New files created: - CalendarsTasker main orchestrator extending Tasker base class - CalendarsSyncTasker for sync execution - CalendarsTriggerTasker for async execution via trigger.dev - CalendarsTaskService with business logic for ensuring default calendars - trigger.dev task with queue config and retry settings - DI modules using @evyweb/ioctopus - NestJS DI modules for API v2 Co-Authored-By: morgan@cal.com <morgan@cal.com> * fix: import and deasync * style: format trigger.config.ts dirs array Co-Authored-By: unknown <> * refactor: move prisma query to UserRepository and set onboarding to true Co-Authored-By: morgan@cal.com <morgan@cal.com> * refactor: remove credential.key from UserRepository method Co-Authored-By: morgan@cal.com <morgan@cal.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import type { ITaskerDependencies } from "@calcom/lib/tasker/types";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
|
|
import { UserRepository } from "../../../users/repositories/UserRepository";
|
|
import type { CalendarsTasks } from "./types";
|
|
|
|
export interface ICalendarsTaskServiceDependencies {
|
|
prisma: PrismaClient;
|
|
}
|
|
|
|
export class CalendarsTaskService implements CalendarsTasks {
|
|
constructor(
|
|
public readonly dependencies: {
|
|
logger: ITaskerDependencies["logger"];
|
|
} & ICalendarsTaskServiceDependencies
|
|
) {}
|
|
|
|
async ensureDefaultCalendars(
|
|
payload: Parameters<CalendarsTasks["ensureDefaultCalendars"]>[0]
|
|
): Promise<void> {
|
|
const { userId } = payload;
|
|
const { prisma, logger } = this.dependencies;
|
|
|
|
try {
|
|
const userRepository = new UserRepository(prisma);
|
|
const userWithCalendars = await userRepository.findByIdWithSelectedCalendars({ userId });
|
|
|
|
if (!userWithCalendars) {
|
|
logger.error(`User not found for ensureDefaultCalendars`, { userId });
|
|
return;
|
|
}
|
|
|
|
const { getConnectedDestinationCalendarsAndEnsureDefaultsInDb } = await import(
|
|
"@calcom/features/calendars/lib/getConnectedDestinationCalendars"
|
|
);
|
|
|
|
await getConnectedDestinationCalendarsAndEnsureDefaultsInDb({
|
|
user: {
|
|
...userWithCalendars,
|
|
allSelectedCalendars: userWithCalendars.selectedCalendars,
|
|
userLevelSelectedCalendars: userWithCalendars.selectedCalendars.filter(
|
|
(calendar) => !calendar.eventTypeId
|
|
),
|
|
},
|
|
onboarding: true,
|
|
eventTypeId: null,
|
|
prisma,
|
|
});
|
|
|
|
logger.info("Successfully ensured default calendars for user", { userId });
|
|
} catch (err) {
|
|
logger.error(`Failed to ensure default calendars for user`, {
|
|
userId,
|
|
error: err instanceof Error ? err.message : "Unknown error",
|
|
});
|
|
}
|
|
}
|
|
}
|