| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 'use server';
- import { createImport } from './imports';
- import { getLayoutConfigurations } from './layout-configurations';
- /**
- * Creates an import record for Cintas Install Calendar workflow
- * @param fileId - The uploaded file ID from blob storage
- * @param fileName - The original file name
- * @returns The created import record
- */
- export async function createCintasImportRecord(fileId: string, fileName: string) {
- try {
- // Step 1: Find the "Cintas Install Calendar" layout configuration
- const layoutsResult = await getLayoutConfigurations();
-
- if (!layoutsResult.success || !layoutsResult.data) {
- throw new Error('Failed to fetch layout configurations');
- }
- const cintasLayout = layoutsResult.data.find(
- layout => layout.name === 'Cintas Install Calendar'
- );
- if (!cintasLayout) {
- throw new Error('Layout configuration "Cintas Install Calendar" not found');
- }
- // Step 2: Create import record with the layout configuration
- const importName = `Cintas Install Calendar - ${fileName}`;
-
- const importResult = await createImport({
- name: importName,
- layoutId: cintasLayout.id,
- fileId: fileId,
- });
- if (!importResult.success) {
- throw new Error(importResult.error || 'Failed to create import record');
- }
- return {
- success: true,
- data: importResult.data,
- layout: cintasLayout
- };
- } catch (error) {
- console.error('Error creating Cintas import record:', error);
- return {
- success: false,
- error: error instanceof Error ? error.message : 'Failed to create Cintas import record'
- };
- }
- }
- /**
- * Gets the Cintas Install Calendar layout configuration
- * @returns The layout configuration or null if not found
- */
- export async function getCintasInstallCalendarLayout() {
- try {
- const layoutsResult = await getLayoutConfigurations();
-
- if (!layoutsResult.success) {
- return null;
- }
- return layoutsResult.data?.find(
- layout => layout.name === 'Cintas Install Calendar'
- ) || null;
- } catch (error) {
- console.error('Error fetching Cintas layout:', error);
- return null;
- }
- }
|