Files
starr-philproperties/database/migrations/20260703000003-create-email-templates.js
T
kennethobsequio 1d12f04967 new commits
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-07-03 16:20:58 +08:00

115 lines
5.9 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('email_templates', {
email_template_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
type: { type: Sequelize.STRING(100), allowNull: false, unique: true },
label: { type: Sequelize.STRING(150), allowNull: false },
subject: { type: Sequelize.STRING(255), allowNull: false },
html_body: { type: Sequelize.TEXT, allowNull: false },
is_system: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
});
const FONT = 'font-family: Arial, sans-serif; font-size: 14px; color: #000;';
const now = new Date();
// Seed the 8 built-in types that services/email.service.js's sendEmail()
// looks up by name — these are marked is_system so they can't be
// deleted/renamed from the admin CRUD. Body content only (no <html>/<body>
// wrapper) — the header/footer layout stays fixed in code, not admin-editable.
await queryInterface.bulkInsert('email_templates', [
{
type: 'OTP', label: 'OTP Verification', is_system: true,
subject: 'Email OTP Verification - STARR System',
html_body: `<p>Dear User,</p>
<p>Please use the One-Time Password (OTP) below to verify your email address. This code is valid for <strong>{{expiryMinutes}} minutes</strong>.</p>
<p style="font-size: 28px; font-weight: bold; letter-spacing: 6px;">{{otp}}</p>
<p>For security reasons, please do not share this code with anyone. If you did not request this, please contact the administrator.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'WELCOME', label: 'Welcome Email', is_system: true,
subject: 'Welcome to STARR System',
html_body: `<p>Dear {{name}},</p>
<p>We are pleased to welcome you to the STARR System. Your account has been successfully created and is now ready for use.</p>
<p>You may now access your dashboard and begin using the available services.</p>
<p>We look forward to supporting you.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'PASSWORD_CHANGED', label: 'Password Changed', is_system: true,
subject: 'Password Update Confirmation - STARR System',
html_body: `<p>Dear User,</p>
<p>This is to confirm that your account password has been successfully changed.</p>
<p>If you did not perform this action, please reset your password immediately or contact support.</p>
<p>For your security, we recommend using a strong and unique password.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'ADDED_TO_GROUP', label: 'Added to Group', is_system: true,
subject: 'Group Assignment Notification - STARR System',
html_body: `<p>Dear User,</p>
<p>You have been assigned to the group <strong>{{groupName}}</strong> in the STARR System.</p>
<p>This assignment grants you access to shared resources and collaboration tools within the group.</p>
<p>Please log in to your account to view group details.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'TASK_ASSIGNED', label: 'Task Assigned', is_system: true,
subject: 'New Task Assignment - STARR System',
html_body: `<p>Dear User,</p>
<p>You have been assigned a new task in the STARR System.</p>
<table style="${FONT}">
<tr><td><strong>Task</strong></td><td>{{taskTitle}}</td></tr>
<tr><td><strong>Due Date</strong></td><td>{{dueDate}}</td></tr>
</table>
<p>Kindly ensure completion within the specified timeframe.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'BAN_LIFTED', label: 'Ban Lifted', is_system: true,
subject: 'Account Suspension Lifted - STARR System',
html_body: `<p>Dear {{name}},</p>
<p>We are writing to inform you that the suspension on your account (<strong>{{email}}</strong>) has been lifted effective <strong>{{date}}</strong>.</p>
<p>You may now log in and resume access to all services within the STARR System.</p>
<p>If you have any concerns, please do not hesitate to contact your administrator.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'BANNED', label: 'Account Banned', is_system: true,
subject: 'Account Suspension Notice - STARR System',
html_body: `<p>Dear {{name}},</p>
<p>Your account (<strong>{{email}}</strong>) has been {{duration_word}} suspended from the STARR System effective <strong>{{date}}</strong>.</p>
<table style="${FONT}">
<tr><td><strong>Reason</strong></td><td>{{reason}}</td></tr>
<tr><td><strong>Duration</strong></td><td>{{duration_label}}</td></tr>
</table>
<p>During this period, access to all system services has been revoked.{{suspension_note}}</p>
<p>If you believe this was made in error, please contact your administrator.</p>`,
createdAt: now, updatedAt: now,
},
{
type: 'ADD_STAFF', label: 'Staff Account Created', is_system: true,
subject: 'Your Staff Account Has Been Created - STARR System',
html_body: `<p>Dear {{name}},</p>
<p>Your staff account has been successfully created in the STARR System. Below are your login credentials:</p>
<table style="${FONT}">
<tr><td><strong>Email</strong></td><td>{{email}}</td></tr>
<tr><td><strong>Password</strong></td><td>{{password}}</td></tr>
</table>
<p>This temporary password is valid for <strong>{{expiryHours}} hours</strong>. You will be required to change it upon first login.</p>
<p>If you did not request this account or believe this was created in error, please contact your administrator immediately to have it deactivated.</p>
<p>For security, please do not share your credentials with anyone. If you need a new password, contact your administrator.</p>`,
createdAt: now, updatedAt: now,
},
]);
},
async down(queryInterface) {
await queryInterface.dropTable('email_templates');
},
};