mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
feat: fix metadata in logging, lint prettier, typed Models (#747)
This commit is contained in:
+28
-14
@@ -4,18 +4,27 @@ import Mail from 'nodemailer/lib/mailer';
|
||||
import {config} from '../config';
|
||||
import {transporter} from './email';
|
||||
|
||||
if (config.notifications.phone.number && !config.notifications.email.username) {
|
||||
logger.warn('✖ in order to receive sms alerts, email notifications must also be configured');
|
||||
}
|
||||
|
||||
const [email, phone] = [config.notifications.email, config.notifications.phone];
|
||||
|
||||
if (phone.number.length > 0 && (!email.username || !email.password)) {
|
||||
logger.warn(
|
||||
'✖ in order to receive sms alerts, email notifications must also be configured'
|
||||
);
|
||||
}
|
||||
|
||||
if (phone.carrier.length !== phone.number.length) {
|
||||
logger.warn('✖ the number of carriers must match the number of phone numbers');
|
||||
logger.warn(
|
||||
'✖ the number of carriers must match the number of phone numbers',
|
||||
{carrier: phone.carrier, number: phone.number}
|
||||
);
|
||||
}
|
||||
|
||||
export function sendSms(link: Link, store: Store) {
|
||||
for (let i = 0; i < Math.max(phone.number.length, phone.carrier.length); i++) {
|
||||
for (
|
||||
let i = 0;
|
||||
i < Math.max(phone.number.length, phone.carrier.length);
|
||||
i++
|
||||
) {
|
||||
const currentNumber = phone.number[i];
|
||||
const currentCarrier = phone.carrier[i];
|
||||
|
||||
@@ -35,21 +44,26 @@ export function sendSms(link: Link, store: Store) {
|
||||
logger.debug('↗ sending sms');
|
||||
|
||||
const mailOptions: Mail.Options = {
|
||||
attachments: link.screenshot ? [
|
||||
{
|
||||
filename: link.screenshot,
|
||||
path: `./${link.screenshot}`
|
||||
}
|
||||
] : undefined,
|
||||
attachments: link.screenshot
|
||||
? [
|
||||
{
|
||||
filename: link.screenshot,
|
||||
path: `./${link.screenshot}`
|
||||
}
|
||||
]
|
||||
: undefined,
|
||||
from: email.username,
|
||||
subject: Print.inStock(link, store, false, true),
|
||||
text: link.cartUrl ? link.cartUrl : link.url,
|
||||
to: generateAddress(currentNumber, currentCarrier)
|
||||
};
|
||||
|
||||
transporter.sendMail(mailOptions, error => {
|
||||
transporter.sendMail(mailOptions, (error) => {
|
||||
if (error) {
|
||||
logger.error(`✖ couldn't send sms to ${currentNumber} for carrier ${currentCarrier}`, error);
|
||||
logger.error(
|
||||
`✖ couldn't send sms to ${currentNumber} for carrier ${currentCarrier}`,
|
||||
error
|
||||
);
|
||||
} else {
|
||||
logger.info('✔ sms sent');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user