/** * Add Portal Access notification template to system_email_templates */ exports.up = async function(knex) { // Check if Portal Access category exists let portalAccessCategory = await knex('notification_categories') .where({ name: 'Portal Access' }) .first(); if (!portalAccessCategory) { // Create new category if it doesn't exist [portalAccessCategory] = await knex('notification_categories') .insert({ name: 'Portal Access', description: 'Customer portal access and invitation notifications', is_enabled: true, is_default_enabled: true, created_at: new Date(), updated_at: new Date() }) .returning('*'); } else { // Update existing category [portalAccessCategory] = await knex('notification_categories') .where({ id: portalAccessCategory.id }) .update({ description: 'Customer portal access and invitation notifications', updated_at: new Date() }) .returning('*'); } // Check if portal invitation subtype exists let portalInvitationSubtype = await knex('notification_subtypes') .where({ name: 'portal-invitation' }) .first(); if (!portalInvitationSubtype) { // Create new subtype if it doesn't exist [portalInvitationSubtype] = await knex('notification_subtypes') .insert({ category_id: portalAccessCategory.id, name: 'portal-invitation', description: 'Portal access invitation emails for contacts', is_enabled: true, is_default_enabled: true, created_at: new Date(), updated_at: new Date() }) .returning('*'); } else { // Update existing subtype [portalInvitationSubtype] = await knex('notification_subtypes') .where({ id: portalInvitationSubtype.id }) .update({ category_id: portalAccessCategory.id, description: 'Portal access invitation emails for contacts', updated_at: new Date() }) .returning('*'); } // Check if email template exists let emailTemplate = await knex('system_email_templates') .where({ name: 'portal-invitation' }) .first(); const templateData = { name: 'portal-invitation', notification_subtype_id: portalInvitationSubtype.id, subject: 'Portal Access Invitation - {{companyName}}', created_at: new Date(), updated_at: new Date(), html_content: `
Hello {{contactName}},
You have been invited to access the customer portal for {{companyName}}. This portal will give you access to view your tickets, invoices, and other important information.
Click the button below to set up your portal account. You'll be able to create a secure password and access your information immediately.
If the button doesn't work, you can also copy and paste this link into your browser:
{{portalLink}}
Important: This invitation link will expire in {{expirationTime}}. Please complete your account setup before then.
If you didn't expect this invitation or have questions, please contact us.
© {{currentYear}} {{companyName}}. All rights reserved.