Allow fromName to be null
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/db/migrations/20210314175439_fromName_null.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/db/migrations/20210314175439_fromName_null.ts
									
									
									
									
									
										Normal file
									
								
							@ -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();
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -5,19 +5,21 @@ import { DateTime } from "luxon";
 | 
				
			|||||||
import type { Contact } from "./types";
 | 
					import type { Contact } from "./types";
 | 
				
			||||||
import type { StoredVoicemail, StoredRecording } from "knex/types/tables";
 | 
					import type { StoredVoicemail, StoredRecording } from "knex/types/tables";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function getTicketSubject(
 | 
					function fromName(vm: StoredVoicemail, contact?: Contact) {
 | 
				
			||||||
  voicemail: StoredVoicemail,
 | 
					  return contact?.name ?? vm.fromName ?? "unknown";
 | 
				
			||||||
  contact?: Contact
 | 
					}
 | 
				
			||||||
) {
 | 
					
 | 
				
			||||||
  return `New Voicemail from ${getNationalNumber(voicemail.fromNumber)} (${
 | 
					export function getTicketSubject(vm: StoredVoicemail, contact?: Contact) {
 | 
				
			||||||
    contact ? contact.name : voicemail.fromName
 | 
					  const name = fromName(vm, contact);
 | 
				
			||||||
  })`;
 | 
					  return `New Voicemail from ${getNationalNumber(vm.fromNumber)} (${name})`;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function getTicketBody(
 | 
					export function getTicketBody(
 | 
				
			||||||
  vm: StoredVoicemail & StoredRecording,
 | 
					  vm: StoredVoicemail & StoredRecording,
 | 
				
			||||||
  contact?: Contact
 | 
					  contact?: Contact
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
 | 
					  const name = fromName(vm, contact);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return ReactDOMServer.renderToStaticMarkup(
 | 
					  return ReactDOMServer.renderToStaticMarkup(
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
      <div>
 | 
					      <div>
 | 
				
			||||||
@ -25,8 +27,7 @@ export function getTicketBody(
 | 
				
			|||||||
        {DateTime.fromISO(vm.received).toLocaleString(DateTime.DATETIME_MED)}
 | 
					        {DateTime.fromISO(vm.received).toLocaleString(DateTime.DATETIME_MED)}
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <div>
 | 
					      <div>
 | 
				
			||||||
        <b>From:</b> {getNationalNumber(vm.fromNumber)} (
 | 
					        <b>From:</b> {getNationalNumber(vm.fromNumber)} ({name})
 | 
				
			||||||
        {contact?.name ?? vm.fromName})
 | 
					 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <div>
 | 
					      <div>
 | 
				
			||||||
        <b>To:</b> {getNationalNumber(vm.toNumber)}x{vm.extensionNumber} (
 | 
					        <b>To:</b> {getNationalNumber(vm.toNumber)}x{vm.extensionNumber} (
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user