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 <noreply@anthropic.com>
This commit is contained in:
Ruslan Bakiev
2026-02-25 09:04:04 +07:00
parent 693a96cffd
commit 5c29cde13d

View File

@@ -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) { function normalizeSourceExternalId(channel: string, sourceExternalId: string | null | undefined) {
const raw = String(sourceExternalId ?? "").trim(); const raw = String(sourceExternalId ?? "").trim();
if (raw) return raw; if (raw) return raw;
@@ -1169,16 +1134,6 @@ async function createCalendarEvent(auth: AuthContext | null, input: {
include: { contact: { select: { name: true } } }, 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 { return {
id: created.id, id: created.id,
title: created.title, title: created.title,
@@ -1215,16 +1170,6 @@ async function archiveCalendarEvent(auth: AuthContext | null, input: { id: strin
include: { contact: { select: { name: true } } }, 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 { return {
id: updated.id, id: updated.id,
title: updated.title, title: updated.title,
@@ -1421,12 +1366,26 @@ async function createWorkspaceDocument(auth: AuthContext | null, input: {
}); });
if (linkedContact) { if (linkedContact) {
await upsertClientTimelineEntry({ await prisma.clientTimelineEntry.upsert({
teamId: ctx.teamId, where: {
contactId: linkedContact.id, teamId_contentType_contentId: {
contentType: "DOCUMENT", teamId: ctx.teamId,
contentId: created.id, contentType: "DOCUMENT",
datetime: new Date(), 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 },
}); });
} }
} }