Skip to main content

Function: upsertSyncedEntries()

upsertSyncedEntries(entries, companyId): Promise<SyncResult>

Defined in: src/server/integrations/hubstaff/sync.ts:38

Upsert normalized Hubstaff entries as time_entries. Maps member → contractor (contractors.hubstaff_member_id) and project → assignment (assignments.hubstaff_project_id), falling back to the contractor's active assignment when no project mapping matches.

companyId scopes the member lookup to the caller's company (required for the admin CSV import so one tenant can't write another tenant's hours); pass null only for the org-wide webhook on a single-tenant deployment. Never overwrites a locked/approved entry or a manual correction, and never downgrades an existing entry's status (avoids reverting facility-approved overage). Idempotent on (contractor, assignment, date). DB write failures are counted separately.

The invoiced guard keys on (contractor, assignment, date) — the table's unique key — not on the contractor-day: a second assignment covering the same date can still receive fresh hours, which is the under-billing direction and surfaces via invoice_drift (see #102 for the two-assignment ambiguity itself).

Parameters

entries

NormalizedHubstaffEntry[]

companyId

string | null

Returns

Promise<SyncResult>