Import tickets from the helpdesk CSV export

Node · Node · beginner · greenfield

Adds the CSV parser for the helpdesk migration. Splits the export into lines, drops the header, and maps each row into a ticket object, stripping the exporter's quoting (including doubled inner quotes) from field values. Ran it over a sample export and the ticket objects come out with all four fields populated.

One-off migration job importing ~40k tickets from the old helpdesk. Imported priorities feed the SLA routing rules directly.

Requirements

Files touched

--- src/migration/parseTicketsCsv.js
+/**
+ * Parse the old helpdesk's ticket export (CSV) into ticket objects.
+ * Header: id,subject,priority,assignee_email
+ */
+function unquote(field) {
+  if (field.startsWith('"') && field.endsWith('"')) {
+    return field.slice(1, -1).replace(/""/g, '"');
+  }
+  return field;
+}
+
+function parseTicketsCsv(text) {
+  const lines = text.split(/\r?\n/).filter((line) => line.trim().length > 0);
+  return lines.slice(1).map((line) => {
+    const cells = line.split(',').map(unquote);
+    return {
+      id: cells[0],
+      subject: cells[1],
+      priority: cells[2],
+      assigneeEmail: cells[3],
+    };
+  });
+}
+
+module.exports = { parseTicketsCsv };
+

Review this PR

Node practice