feat: pg-boss job queue, notifications, client interactions, bulk email
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { Elysia, t } from 'elysia';
|
||||
import { db } from '../db';
|
||||
import { clients, events, communications } from '../db/schema';
|
||||
import { clients, events, communications, interactions } from '../db/schema';
|
||||
import { eq, and, desc } from 'drizzle-orm';
|
||||
import type { User } from '../lib/auth';
|
||||
|
||||
export interface ActivityItem {
|
||||
id: string;
|
||||
type: 'email_sent' | 'email_drafted' | 'event_created' | 'client_contacted' | 'client_created' | 'client_updated';
|
||||
type: 'email_sent' | 'email_drafted' | 'event_created' | 'client_contacted' | 'client_created' | 'client_updated' | 'interaction';
|
||||
title: string;
|
||||
description?: string;
|
||||
date: string;
|
||||
@@ -110,6 +110,37 @@ export const activityRoutes = new Elysia({ prefix: '/clients' })
|
||||
});
|
||||
}
|
||||
|
||||
// Interactions
|
||||
const clientInteractions = await db.select()
|
||||
.from(interactions)
|
||||
.where(and(
|
||||
eq(interactions.clientId, params.id),
|
||||
eq(interactions.userId, user.id),
|
||||
))
|
||||
.orderBy(desc(interactions.contactedAt));
|
||||
|
||||
for (const interaction of clientInteractions) {
|
||||
const typeLabels: Record<string, string> = {
|
||||
call: '📞 Phone Call',
|
||||
meeting: '🤝 Meeting',
|
||||
email: '✉️ Email',
|
||||
note: '📝 Note',
|
||||
other: '📌 Interaction',
|
||||
};
|
||||
activities.push({
|
||||
id: `interaction-${interaction.id}`,
|
||||
type: 'interaction',
|
||||
title: `${typeLabels[interaction.type] || typeLabels.other}: ${interaction.title}`,
|
||||
description: interaction.description || undefined,
|
||||
date: interaction.contactedAt.toISOString(),
|
||||
metadata: {
|
||||
interactionId: interaction.id,
|
||||
interactionType: interaction.type,
|
||||
duration: interaction.duration,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by date descending
|
||||
activities.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user