feat: add emailcount of user

This commit is contained in:
prafull-opensignlabs
2024-03-31 12:42:08 +05:30
parent d588caf6d4
commit 5adaffc684
14 changed files with 126 additions and 102 deletions
@@ -1,4 +1,4 @@
import axios from 'axios'
import { updateMailCount } from '../../Utils.js';
async function sendMailOTPv1(request) {
try {
@@ -11,37 +11,40 @@ async function sendMailOTPv1(request) {
// console.log(JSON.stringify(request));
if (email) {
axios({
method: 'POST',
url: process.env.SERVER_URL + '/functions/sendmail',
headers: {
'Content-Type': 'application/json',
'X-Parse-Application-Id': process.env.APP_ID,
},
params: {
otp: code,
email: email,
TenantId: TenantId,
},
}).then(
function (httpResponse) {},
function (httpResponse) {
console.error('sms Request failed with response code ' + httpResponse.status);
return Promise.reject('sms Request failed with response code ' + httpResponse.status);
const recipient = request.params.email;
const otp = request.params.otp;
const mailsender = process.env.SMTP_ENABLE
? process.env.SMTP_USER_EMAIL
: process.env.MAILGUN_SENDER;
try {
await Parse.Cloud.sendEmail({
from: 'Opensign™' + ' <' + mailsender + '>',
recipient: recipient,
subject: 'Your OpenSign™ OTP',
text: 'This email is a test.',
html:
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /></head><body><div style='background-color:#f5f5f5;padding:20px'><div style='box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;background-color:white;'><div style='background-color:red;padding:2px;font-family:system-ui; background-color:#47a3ad;'> <p style='font-size:20px;font-weight:400;color:white;padding-left:20px',>OTP Verification</p></div><div style='padding:20px'><p style='font-family:system-ui;font-size:14px'>Your OTP for OpenSign™ verification is:</p><p style=' text-decoration: none; font-weight: bolder; color:blue;font-size:45px;margin:20px'>" +
otp +
'</p></div> </div> </div></body></html>',
});
console.log('OTP sent');
if (request.params?.extUserId) {
await updateMailCount(request.params.extUserId);
}
);
} catch (err) {
console.log('error in send OTP mail', err);
}
const tempOtp = new Parse.Query('defaultdata_Otp');
tempOtp.equalTo('Email', email);
const resultOTP = await tempOtp.first({ useMasterKey: true });
console.log('resultOTP', resultOTP);
// console.log('resultOTP', resultOTP);
if (resultOTP !== undefined) {
const updateOtpQuery = new Parse.Query('defaultdata_Otp');
const updateOtp = await updateOtpQuery.get(resultOTP.id, {
useMasterKey: true,
});
updateOtp.set('OTP', code);
const updateRes = updateOtp.save(null, { useMasterKey: true });
updateOtp.save(null, { useMasterKey: true });
// console.log("update otp Res in tempSendOtp ", updateRes);
} else {
const otpClass = Parse.Object.extend('defaultdata_Otp');
@@ -49,17 +52,17 @@ async function sendMailOTPv1(request) {
newOtpQuery.set('OTP', code);
newOtpQuery.set('Email', email);
newOtpQuery.set('TenantId', TenantId);
const newRes = await newOtpQuery.save(null, { useMasterKey: true });
await newOtpQuery.save(null, { useMasterKey: true });
// console.log("new otp Res in tempSendOtp ", newRes);
}
return 'Otp send';
} else {
return Promise.reject('Please Enter valid email');
return 'Please Enter valid email';
}
} catch (err) {
console.log('err in sendMailOTPv1');
console.log(err);
return Promise.reject(err);
return err;
}
}
export default sendMailOTPv1;