Import contacts from a CSV upload

Node · Node · intermediate · greenfield

Imports contacts from the parsed CSV rows one by one, so a single bad row can't take down the whole batch, and reports how many made it in. Ran it on a sample export and all rows imported.

Users upload real-world CSVs — a few malformed rows per file (bad emails, duplicates) are completely normal.

Requirements

Files touched

--- src/imports/contacts.js
+async function importContacts(rows) {
+  let imported = 0;
+  const failed = [];
+  for (let i = 0; i < rows.length; i++) {
+    await db.contacts.create(rows[i]);
+    imported += 1;
+  }
+  return { imported, failed };
+}
+
+module.exports = { importContacts };

Review this PR

Node practice