From 5c29cde13d85aa4ca22b0435949e7c3eb3fe5b19 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Wed, 25 Feb 2026 09:04:04 +0700 Subject: [PATCH] refactor: remove manual upsertClientTimelineEntry from GraphQL resolvers CalendarEvent and FeedCard timeline entries are now handled by Prisma middleware automatically. Document timeline entry is inlined since WorkspaceDocument stores contactId in scope field, not on the model. Co-Authored-By: Claude Opus 4.6 --- frontend/server/graphql/schema.ts | 81 ++++++++----------------------- 1 file changed, 20 insertions(+), 61 deletions(-) diff --git a/frontend/server/graphql/schema.ts b/frontend/server/graphql/schema.ts index 347633f..7aebd68 100644 --- a/frontend/server/graphql/schema.ts +++ b/frontend/server/graphql/schema.ts @@ -91,41 +91,6 @@ function parseContactDocumentScope(scopeInput: string) { }; } -async function upsertClientTimelineEntry(input: { - teamId: string; - contactId: string; - contentType: ClientTimelineContentType; - contentId: string; - datetime?: Date; -}) { - const datetime = - input.datetime && !Number.isNaN(input.datetime.getTime()) - ? input.datetime - : new Date(); - - return prisma.clientTimelineEntry.upsert({ - where: { - teamId_contentType_contentId: { - teamId: input.teamId, - contentType: input.contentType, - contentId: input.contentId, - }, - }, - create: { - teamId: input.teamId, - contactId: input.contactId, - contentType: input.contentType, - contentId: input.contentId, - datetime, - }, - update: { - contactId: input.contactId, - datetime, - }, - select: { id: true }, - }); -} - function normalizeSourceExternalId(channel: string, sourceExternalId: string | null | undefined) { const raw = String(sourceExternalId ?? "").trim(); if (raw) return raw; @@ -1169,16 +1134,6 @@ async function createCalendarEvent(auth: AuthContext | null, input: { include: { contact: { select: { name: true } } }, }); - if (created.contactId) { - await upsertClientTimelineEntry({ - teamId: ctx.teamId, - contactId: created.contactId, - contentType: "CALENDAR_EVENT", - contentId: created.id, - datetime: new Date(), - }); - } - return { id: created.id, title: created.title, @@ -1215,16 +1170,6 @@ async function archiveCalendarEvent(auth: AuthContext | null, input: { id: strin include: { contact: { select: { name: true } } }, }); - if (updated.contactId) { - await upsertClientTimelineEntry({ - teamId: ctx.teamId, - contactId: updated.contactId, - contentType: "CALENDAR_EVENT", - contentId: updated.id, - datetime: new Date(), - }); - } - return { id: updated.id, title: updated.title, @@ -1421,12 +1366,26 @@ async function createWorkspaceDocument(auth: AuthContext | null, input: { }); if (linkedContact) { - await upsertClientTimelineEntry({ - teamId: ctx.teamId, - contactId: linkedContact.id, - contentType: "DOCUMENT", - contentId: created.id, - datetime: new Date(), + await prisma.clientTimelineEntry.upsert({ + where: { + teamId_contentType_contentId: { + teamId: ctx.teamId, + contentType: "DOCUMENT", + contentId: created.id, + }, + }, + create: { + teamId: ctx.teamId, + contactId: linkedContact.id, + contentType: "DOCUMENT", + contentId: created.id, + datetime: new Date(), + }, + update: { + contactId: linkedContact.id, + datetime: new Date(), + }, + select: { id: true }, }); } }