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 }, }); } }