AI Newsletter Digest improvements: fixed QP soft line break decoding, URL extraction, and content cleaning

This commit is contained in:
Krilly
2026-03-04 13:29:22 +00:00
parent 29a98137a7
commit 57dd294675
13706 changed files with 2114953 additions and 237629 deletions

View File

@@ -0,0 +1,54 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/db/prisma'
import { getCurrentUser } from '@/lib/auth'
import { canAccessWorkspace } from '@/lib/db/workspace-access'
// POST /api/workspaces/[id]/care-tasks/[taskId]/complete
export async function POST(
request: NextRequest,
{ params }: { params: { id: string; taskId: string } }
) {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { id: workspaceId, taskId } = params
const access = await canAccessWorkspace(user.id, workspaceId)
if (!access || access.role === 'VIEWER') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
const task = await prisma.careTask.update({
where: { id: taskId },
data: {
completedAt: new Date(),
completedById: user.id
},
include: {
completedBy: { select: { id: true, name: true } }
}
})
// Log audit
await prisma.auditLog.create({
data: {
workspaceId,
userId: user.id,
action: 'COMPLETE_TASK',
entityType: 'CARE_TASK',
entityId: task.id,
details: { title: task.title }
}
})
return NextResponse.json({ task })
} catch (error) {
console.error('Failed to complete task:', error)
return NextResponse.json(
{ error: 'Failed to complete task' },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,104 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/db/prisma'
import { getCurrentUser } from '@/lib/auth'
import { canAccessWorkspace } from '@/lib/db/workspace-access'
// GET /api/workspaces/[id]/care-tasks
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const workspaceId = params.id
const access = await canAccessWorkspace(user.id, workspaceId)
if (!access) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
const tasks = await prisma.careTask.findMany({
where: { workspaceId },
orderBy: [
{ completedAt: 'asc' },
{ priority: 'desc' },
{ createdAt: 'desc' }
],
include: {
assignedTo: { select: { id: true, name: true } },
completedBy: { select: { id: true, name: true } },
createdBy: { select: { id: true, name: true } }
}
})
return NextResponse.json({ tasks })
} catch (error) {
console.error('Failed to fetch care tasks:', error)
return NextResponse.json(
{ error: 'Failed to fetch care tasks' },
{ status: 500 }
)
}
}
// POST /api/workspaces/[id]/care-tasks
export async function POST(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const workspaceId = params.id
const access = await canAccessWorkspace(user.id, workspaceId)
if (!access || access.role === 'VIEWER') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
const body = await request.json()
const { title, description, priority, category, dueAt, assignedToId } = body
const task = await prisma.careTask.create({
data: {
workspaceId,
title,
description,
priority: priority || 'MEDIUM',
category: category || 'GENERAL',
dueAt: dueAt ? new Date(dueAt) : null,
assignedToId: assignedToId || null,
createdById: user.id,
},
include: {
assignedTo: { select: { id: true, name: true } },
createdBy: { select: { id: true, name: true } }
}
})
// Log audit
await prisma.auditLog.create({
data: {
workspaceId,
userId: user.id,
action: 'CREATE',
entityType: 'CARE_TASK',
entityId: task.id,
details: { title, priority, category }
}
})
return NextResponse.json({ task })
} catch (error) {
console.error('Failed to create care task:', error)
return NextResponse.json(
{ error: 'Failed to create care task' },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,51 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/db/prisma'
import { getCurrentUser } from '@/lib/auth'
import { canAccessWorkspace } from '@/lib/db/workspace-access'
// POST /api/workspaces/[id]/handoff-notes/[noteId]/acknowledge
export async function POST(
request: NextRequest,
{ params }: { params: { id: string; noteId: string } }
) {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { id: workspaceId, noteId } = params
const access = await canAccessWorkspace(user.id, workspaceId)
if (!access) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
// Get current note
const note = await prisma.handoffNote.findUnique({
where: { id: noteId }
})
if (!note) {
return NextResponse.json({ error: 'Note not found' }, { status: 404 })
}
// Add user to acknowledged list if not already there
const acknowledgedBy = note.acknowledgedBy || []
if (!acknowledgedBy.includes(user.id)) {
acknowledgedBy.push(user.id)
await prisma.handoffNote.update({
where: { id: noteId },
data: { acknowledgedBy }
})
}
return NextResponse.json({ success: true })
} catch (error) {
console.error('Failed to acknowledge note:', error)
return NextResponse.json(
{ error: 'Failed to acknowledge note' },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,100 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/db/prisma'
import { getCurrentUser } from '@/lib/auth'
import { canAccessWorkspace } from '@/lib/db/workspace-access'
// GET /api/workspaces/[id]/handoff-notes
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const workspaceId = params.id
const access = await canAccessWorkspace(user.id, workspaceId)
if (!access) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
// Get notes that haven't expired
const notes = await prisma.handoffNote.findMany({
where: {
workspaceId,
expiresAt: { gte: new Date() }
},
orderBy: { createdAt: 'desc' },
include: {
createdBy: { select: { id: true, name: true } }
}
})
return NextResponse.json({ notes })
} catch (error) {
console.error('Failed to fetch handoff notes:', error)
return NextResponse.json(
{ error: 'Failed to fetch handoff notes' },
{ status: 500 }
)
}
}
// POST /api/workspaces/[id]/handoff-notes
export async function POST(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const workspaceId = params.id
const access = await canAccessWorkspace(user.id, workspaceId)
if (!access || access.role === 'VIEWER') {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
const body = await request.json()
const { content, category, priority, expiresAt } = body
const note = await prisma.handoffNote.create({
data: {
workspaceId,
content,
category: category || 'GENERAL',
priority: priority || 'NORMAL',
expiresAt: new Date(expiresAt),
createdById: user.id,
acknowledgedBy: []
},
include: {
createdBy: { select: { id: true, name: true } }
}
})
// Log audit
await prisma.auditLog.create({
data: {
workspaceId,
userId: user.id,
action: 'CREATE',
entityType: 'HANDOFF_NOTE',
entityId: note.id,
details: { category, priority }
}
})
return NextResponse.json({ note })
} catch (error) {
console.error('Failed to create handoff note:', error)
return NextResponse.json(
{ error: 'Failed to create handoff note' },
{ status: 500 }
)
}
}