Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ export const editUserRole = async (req: Request, res: Response) => {

await user.update({ RoleId: roleId }, { transaction });
await transaction.commit();
const name = user.firstName + ' ' + user.lastName;
const email = user.email;

await sendEmail('role', { name, email, role: role.name });
res.status(200).json({ ok: true, message: 'Role assigned successfully.' });
} catch (error) {
await transaction.rollback();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('orders', 'expectedDeliveryDate', {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Date.now(),
});
},

async down(queryInterface, Sequelize) {
await queryInterface.removeColumn('orders', 'expectedDeliveryDate');
},
};
23 changes: 22 additions & 1 deletion src/helpers/send-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IData {
link?: string;
otp?: string;
productName?: string;
role?: string;
}
interface EmailContent {
name: string;
Expand Down Expand Up @@ -53,6 +54,26 @@ export const sendEmail = async (type: string, data: IData) => {
let email;

switch (type) {
case 'role':
email = {
body: {
name: data.name,
intro: 'Your role has been changed up on your request!',
action: {
instructions: `You have requested to change the role to ${data.role}!`,
button: {
color: '#000c24',
text: 'Revert back the Action',
link: 'https://e-commerce-mavericks-fn.netlify.app',
},
},
outro: 'Ignore this email, if you did not request that!',
},
};
mailOptions.subject = 'Account Role Changed';
mailOptions.html = mailGenerator.generate(email);
break;

case 'account_verify':
email = {
body: {
Expand Down Expand Up @@ -105,7 +126,7 @@ export const sendEmail = async (type: string, data: IData) => {
button: {
color: '#22BC66',
text: 'Access Account',
link: 'https://e-commerce-mavericks.com/login',
link: 'https://e-commerce-mavericks-fn.netlify.app/login',
},
},
outro: 'If you did not request this action, please contact support immediately.',
Expand Down