Fake Data Finalizer (dataGenerator/finalize.ts)

atomic-crm · src/components/atomic-crm/providers/fakerest/dataGenerator/finalize.ts · typescript · MIT
testing, crm, database, lang:typescript, tag:fakerest, tag:data-generator

Finalizes generated fake CRM data by setting each contact's status from its latest note. Reuse when seeding mock databases that need consistent derived contact state.

// Source: https://github.com/CopilotKit/atomic-crm | License: MIT | Copyright 2024-present, Francois Zaninotto, Marmelab
// Provided via justclaw.it.com; keep this notice with the code.
import type { Db } from "./types";

export const finalize = (db: Db) => {
  // set contact status according to the latest note
  const contactById = new Map(db.contacts.map((c) => [c.id, c]));
  db.contact_notes
    .sort((a, b) => new Date(a.date).valueOf() - new Date(b.date).valueOf())
    .forEach((note) => {
      const contact = contactById.get(note.contact_id as number);
      if (contact) {
        contact.status = note.status;
      }
    });
};

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key