Init
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
const mongoose = require("mongoose");
|
||||
const db = async () => {
|
||||
try {
|
||||
const connect = await mongoose.connect(process.env.CONNECTION_STRING);
|
||||
console.log(
|
||||
"Database connected: ",
|
||||
connect.connection.host,
|
||||
connect.connection.name
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
setTimeout(() => {
|
||||
console.log("Retry for DB");
|
||||
db();
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = db;
|
||||
@@ -0,0 +1,26 @@
|
||||
const nodemailer = require("nodemailer");
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.EMAIL_HOST,
|
||||
port: process.env.EMAIL_PORT,
|
||||
secure: true,
|
||||
auth: {
|
||||
user: process.env.EMAIL_USER,
|
||||
pass: process.env.EMAIL_PASS,
|
||||
},
|
||||
});
|
||||
|
||||
const email = async (to, subject, text, html) => {
|
||||
|
||||
const info = await transporter.sendMail({
|
||||
from: `"Asan Market" ${process.env.EMAIL_ADDRESS}`, // sender address
|
||||
to: to, // list of receivers
|
||||
subject: subject, // Subject line
|
||||
text: text, // plain text body
|
||||
html: html, // html body
|
||||
});
|
||||
|
||||
|
||||
|
||||
};
|
||||
module.exports = email;
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
const axios = require('axios')
|
||||
|
||||
const accountInfo = {
|
||||
Username: '000',
|
||||
Password: '000',
|
||||
Number: '000',
|
||||
url: 'http://www.afe.ir/WebService/V4/BoxService.asmx'
|
||||
}
|
||||
|
||||
/////// http post soap method
|
||||
module.exports.sms = (mobileNumbersArray, message) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
function renderMobileNumbers(array) {
|
||||
if (Array.isArray(array)) {
|
||||
return array.map(item => `<string>${item}</string>`).join('')
|
||||
} else {
|
||||
return `<string>${array}</string>`
|
||||
}
|
||||
}
|
||||
|
||||
const xml = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<SendMessage xmlns="http://www.afe.ir/">
|
||||
<Username>${accountInfo.Username}</Username>
|
||||
<Password>${accountInfo.Password}</Password>
|
||||
<Number>${accountInfo.Number}</Number>
|
||||
<Mobile>
|
||||
${renderMobileNumbers(mobileNumbersArray)}
|
||||
</Mobile>
|
||||
<Message>${message}</Message>
|
||||
<Type>1</Type>
|
||||
</SendMessage>
|
||||
</soap:Body>
|
||||
</soap:Envelope>`
|
||||
|
||||
axios
|
||||
.post(accountInfo.url, xml, {
|
||||
headers: {
|
||||
'Content-Type': 'text/xml; charset=utf-8',
|
||||
SOAPAction: 'http://www.afe.ir/SendMessage'
|
||||
}
|
||||
})
|
||||
.then(res => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(
|
||||
'this is sms module error ------------------ status code: %s error message: %s ',
|
||||
err.response.status,
|
||||
err.response.data
|
||||
)
|
||||
resolve(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user