initial commit
This commit is contained in:
56
src/lib/google-drive.ts
Normal file
56
src/lib/google-drive.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
}
|
||||
13
src/lib/prisma.ts
Normal file
13
src/lib/prisma.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined
|
||||
}
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ??
|
||||
new PrismaClient({
|
||||
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
|
||||
})
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
||||
Reference in New Issue
Block a user