fix(email) checkpoint email service
parent
a1f7108bc5
commit
b08325a53c
|
@ -24,8 +24,11 @@ CRON_EVERY_HOUR="0 * * * *"
|
||||||
|
|
||||||
EMAIL_HOST=smtp.gmail.com
|
EMAIL_HOST=smtp.gmail.com
|
||||||
EMAIL_POST=465
|
EMAIL_POST=465
|
||||||
EMAIL_USER=developer@eigen.co.id
|
EMAIL_USER=weplayground.app@gmail.com
|
||||||
EMAIL_TOKEN=bitqkbkzjzfywxqx
|
EMAIL_TOKEN=sonvvwiukhsevtmv
|
||||||
|
|
||||||
|
// nama email yang akan muncul ke user sebagai pengirim
|
||||||
|
EMAIL_SENDER=no-reply@eigen.co.id
|
||||||
|
|
||||||
MIDTRANS_URL=https://app.sandbox.midtrans.com
|
MIDTRANS_URL=https://app.sandbox.midtrans.com
|
||||||
MIDTRANS_PRODUCTION=false
|
MIDTRANS_PRODUCTION=false
|
||||||
|
|
|
@ -20,9 +20,9 @@ export async function sendEmail(receivers, subject) {
|
||||||
if (receiver.payment_type == TransactionPaymentType.MIDTRANS)
|
if (receiver.payment_type == TransactionPaymentType.MIDTRANS)
|
||||||
templateName = 'payment-confirmation-midtrans';
|
templateName = 'payment-confirmation-midtrans';
|
||||||
|
|
||||||
let templatePath = path.resolve(
|
let templatePath = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
`../email-template/${ templateName }.html`,
|
`../email-template/${templateName}.html`,
|
||||||
);
|
);
|
||||||
templatePath = templatePath.replace(/dist/g, 'src');
|
templatePath = templatePath.replace(/dist/g, 'src');
|
||||||
const templateSource = fs.readFileSync(templatePath, 'utf8');
|
const templateSource = fs.readFileSync(templatePath, 'utf8');
|
||||||
|
@ -31,7 +31,7 @@ export async function sendEmail(receivers, subject) {
|
||||||
const htmlToSend = template(receiver);
|
const htmlToSend = template(receiver);
|
||||||
|
|
||||||
const emailContext = {
|
const emailContext = {
|
||||||
from: 'no-reply@eigen.co.id',
|
from: process.env.EMAIL_SENDER ?? 'no-reply@weplayground.app',
|
||||||
to: receiver.email,
|
to: receiver.email,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
html: htmlToSend,
|
html: htmlToSend,
|
||||||
|
@ -42,13 +42,13 @@ export async function sendEmail(receivers, subject) {
|
||||||
|
|
||||||
smtpTransport.sendMail(emailContext, function (err, data) {
|
smtpTransport.sendMail(emailContext, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err, `Error occurs on send to ${ receiver.email }`);
|
console.log(err, `Error occurs on send to ${receiver.email}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Email sent to ${ receiver.email }`);
|
console.log(`Email sent to ${receiver.email}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error, `Error occurs on send to ${ receiver.email }`)
|
console.log(error, `Error occurs on send to ${receiver.email}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { Controller, Get, Injectable } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
@ApiTags(`email templates`)
|
||||||
|
@Controller('v1/email-templates')
|
||||||
|
@Public()
|
||||||
|
@Injectable()
|
||||||
|
export class MailTemplateController {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
getTemplate(templateName) {
|
||||||
|
const templatePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'../../../../../',
|
||||||
|
`src/modules/configuration/mail/domain/email-template/${templateName}.html`,
|
||||||
|
);
|
||||||
|
return fs.readFileSync(templatePath, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('date-change')
|
||||||
|
async getDateChange() {
|
||||||
|
return this.getTemplate('change-date');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('invoice')
|
||||||
|
async getBookingInvoice() {
|
||||||
|
return this.getTemplate('invoice');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('payment-confirmation-bank')
|
||||||
|
async getPaymentConfirmation() {
|
||||||
|
return this.getTemplate('payment-confirmation-bank');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('payment-confirmation-midtrans')
|
||||||
|
async getPaymentConfirmationMidtrans() {
|
||||||
|
return this.getTemplate('payment-confirmation-midtrans');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('invoice-expired')
|
||||||
|
async getInvoiceExpired() {
|
||||||
|
return this.getTemplate('invoice-expired');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('refund-confirmation')
|
||||||
|
async getRefundConfirmation() {
|
||||||
|
return this.getTemplate('refund-confirmation');
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('refund-request')
|
||||||
|
async getRefundRequest() {
|
||||||
|
return this.getTemplate('refunr-request');
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||||
import { PaymentTransactionHandler } from './domain/handlers/payment-transaction.handler';
|
import { PaymentTransactionHandler } from './domain/handlers/payment-transaction.handler';
|
||||||
|
import { MailTemplateController } from './infrastructure/mail.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -18,7 +19,7 @@ import { PaymentTransactionHandler } from './domain/handlers/payment-transaction
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [MailTemplateController],
|
||||||
providers: [
|
providers: [
|
||||||
PaymentTransactionHandler,
|
PaymentTransactionHandler,
|
||||||
PaymentMethodDataService,
|
PaymentMethodDataService,
|
||||||
|
|
Loading…
Reference in New Issue