Files
alla-allaos-fullstack/src/features/crm/activities/server/adapters/opportunity-followup.adapter.ts
phaichayon e96320a24d task-ep.1.2
2026-07-13 09:49:45 +07:00

43 lines
1.5 KiB
TypeScript

import { formatCrmActivityLabel } from '@/features/crm/activity/types';
import type { ActivityTimelineItem } from '../../api/types';
import type { OpportunityFollowupRecord } from '@/features/crm/opportunities/api/types';
export interface OpportunityFollowupAdapterCandidate {
source: 'opportunity_followup';
followup: OpportunityFollowupRecord;
followupTypeLabel?: string | null;
createdByName?: string | null;
}
export function adaptOpportunityFollowupCandidate(
candidate: OpportunityFollowupAdapterCandidate
): ActivityTimelineItem {
const typeLabel =
candidate.followupTypeLabel ?? formatCrmActivityLabel(candidate.followup.followupType);
return {
id: candidate.followup.id,
source: 'opportunity_followup',
sourceLabel: 'Opportunity Follow-up',
isLegacy: true,
activityId: null,
activityCode: null,
primaryEntityType: 'opportunity',
primaryEntityId: candidate.followup.opportunityId,
primaryRecordLabel: null,
activityType: 'follow_up',
activityTypeLabel: typeLabel,
subject: typeLabel,
description: candidate.followup.outcome ?? candidate.followup.notes,
status: 'completed',
statusLabel: 'Completed',
occurredAt: candidate.followup.followupDate,
scheduledAt: candidate.followup.followupDate,
dueAt: candidate.followup.nextFollowupDate,
nextAction: candidate.followup.nextAction,
ownerName: null,
assignedToName: null,
createdByName: candidate.createdByName ?? null
};
}