diff --git a/src/db/migrations/20210314175439_fromName_null.ts b/src/db/migrations/20210314175439_fromName_null.ts new file mode 100644 index 0000000..24019e4 --- /dev/null +++ b/src/db/migrations/20210314175439_fromName_null.ts @@ -0,0 +1,17 @@ +import { Knex } from "knex"; + +export async function up(knex: Knex) { + return knex.transaction((trx) => + trx.schema.alterTable("voicemails", (table) => { + table.string("fromName", 64).alter(); + }) + ); +} + +export async function down(knex: Knex) { + return knex.transaction((trx) => + trx.schema.alterTable("voicemails", (table) => { + table.string("fromName", 64).notNullable().alter(); + }) + ); +} diff --git a/src/template.tsx b/src/template.tsx index 3fd6e46..18df9b3 100644 --- a/src/template.tsx +++ b/src/template.tsx @@ -5,19 +5,21 @@ import { DateTime } from "luxon"; import type { Contact } from "./types"; import type { StoredVoicemail, StoredRecording } from "knex/types/tables"; -export function getTicketSubject( - voicemail: StoredVoicemail, - contact?: Contact -) { - return `New Voicemail from ${getNationalNumber(voicemail.fromNumber)} (${ - contact ? contact.name : voicemail.fromName - })`; +function fromName(vm: StoredVoicemail, contact?: Contact) { + return contact?.name ?? vm.fromName ?? "unknown"; +} + +export function getTicketSubject(vm: StoredVoicemail, contact?: Contact) { + const name = fromName(vm, contact); + return `New Voicemail from ${getNationalNumber(vm.fromNumber)} (${name})`; } export function getTicketBody( vm: StoredVoicemail & StoredRecording, contact?: Contact ) { + const name = fromName(vm, contact); + return ReactDOMServer.renderToStaticMarkup(
@@ -25,8 +27,7 @@ export function getTicketBody( {DateTime.fromISO(vm.received).toLocaleString(DateTime.DATETIME_MED)}
- From: {getNationalNumber(vm.fromNumber)} ( - {contact?.name ?? vm.fromName}) + From: {getNationalNumber(vm.fromNumber)} ({name})
To: {getNationalNumber(vm.toNumber)}x{vm.extensionNumber} (