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
- Add `parseTicketsCsv(text)` for the helpdesk-migration job: parse the old helpdesk's CSV export and return one object per ticket with keys `id`, `subject`, `priority`, `assigneeEmail`.
- The export format: UTF-8, no BOM, `\n` or `\r\n` line endings, first line is always the header `id,subject,priority,assignee_email`. A field is wrapped in double quotes when (and only when) it contains a comma or a double quote; a double quote inside a quoted field is doubled (`""`). Field values never contain line breaks.
- Ticket subjects are free text typed by customers — subjects containing commas are routine in this export.
- `priority` is one of `low`, `normal`, `high`, `urgent` and is used downstream to route imported tickets into SLA queues.
- Blank lines (including a trailing newline at end of file) are skipped.
Files touched
- src/migration/parseTicketsCsv.js
--- 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 };
+