import { google } from 'googleapis'; import { Readable } from 'stream'; export async function uploadToDrive(accessToken: string, fileName: string, content: string, folderId?: string) { const auth = new google.auth.OAuth2(); auth.setCredentials({ access_token: accessToken }); const drive = google.drive({ version: 'v3', auth }); const fileMetadata: any = { name: fileName, mimeType: 'application/vnd.google-apps.document', // Automatically convert to Google Doc }; if (folderId) { fileMetadata.parents = [folderId]; } const media = { mimeType: 'text/markdown', body: Readable.from([content]), }; try { const response = await drive.files.create({ requestBody: fileMetadata, media: media, fields: 'id, webViewLink' }); return response.data; } catch (error) { console.error('Error uploading to Google Drive:', error); throw error; } } export function generateReportMarkdown(report: any) { let md = `# WFH Daily Report - ${new Date(report.date).toLocaleDateString()}\n`; md += `**Employee:** ${report.user.name}\n`; md += `**Manager:** ${report.managerName}\n\n`; md += `## Planned Tasks\n`; report.tasks.filter((t: any) => t.type === 'PLANNED').forEach((t: any) => { md += `- [ ] ${t.description} (Est: ${t.timeEstimate})\n`; if (t.notes) md += ` - Notes: ${t.notes}\n`; }); md += `\n## Completed Tasks\n`; report.tasks.filter((t: any) => t.type === 'COMPLETED').forEach((t: any) => { md += `- [x] ${t.description}\n`; md += ` - Status: ${t.status}\n`; if (t.link) md += ` - Work Link: ${t.link}\n`; }); return md; }