Skip to content

Commit

Permalink
Merge pull request #2147 from hollaex/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
abeikverdi committed Apr 30, 2023
2 parents 187b378 + 14b6504 commit 215ef40
Show file tree
Hide file tree
Showing 107 changed files with 5,161 additions and 669 deletions.
88 changes: 86 additions & 2 deletions server/api/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { cloneDeep, pick } = require('lodash');
const { all } = require('bluebird');
const { ROLES } = require('../../constants');
const { USER_NOT_FOUND, API_KEY_NOT_PERMITTED, PROVIDE_VALID_EMAIL, INVALID_PASSWORD, USER_EXISTS } = require('../../messages');
const { sendEmail, testSendSMTPEmail } = require('../../mail');
const { sendEmail, testSendSMTPEmail, sendRawEmail } = require('../../mail');
const { MAILTYPE } = require('../../mail/strings');
const { errorMessageConverter } = require('../../utils/conversion');
const { isDate } = require('moment');
Expand Down Expand Up @@ -2261,6 +2261,88 @@ const getWalletsByAdmin = (req, res) => {
});
};

const sendEmailByAdmin = (req, res) => {
loggerAdmin.info(
req.uuid,
'controllers/admin/sendEmailByAdmin',
req.auth.sub
);

const { user_id, mail_type, data } = req.swagger.params.data.value;

loggerAdmin.info(
req.uuid,
'controllers/admin/sendEmailByAdmin',
'mail_type',
mail_type,
'user_id',
user_id,
'data',
data
);

toolsLib.user.getUserByKitId(user_id)
.then((user) => {
if (!user) {
throw new Error(USER_NOT_FOUND);
}
return sendEmail(
mail_type,
user.email,
data,
user.settings
);
})
.then(() => {
return res.json({ message: 'Success' });
})
.catch((err) => {
loggerAdmin.error(
req.uuid,
'controllers/admin/sendEmailByAdmin',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const sendRawEmailByAdmin = (req, res) => {
loggerAdmin.info(
req.uuid,
'controllers/admin/sendRawEmailByAdmin',
req.auth.sub
);

const { receivers, title, html, text } = req.swagger.params.data.value;

loggerAdmin.info(
req.uuid,
'controllers/admin/sendRawEmailByAdmin',
'receivers',
receivers,
'title',
title,
);

sendRawEmail(
receivers,
title,
html,
text
)
.then(() => {
return res.json({ message: 'Success' });
})
.catch((err) => {
loggerAdmin.error(
req.uuid,
'controllers/admin/sendRawEmailByAdmin',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

module.exports = {
createInitialAdmin,
getAdminKit,
Expand Down Expand Up @@ -2317,5 +2399,7 @@ module.exports = {
getUserReferer,
createUserByAdmin,
createUserWalletByAdmin,
getWalletsByAdmin
getWalletsByAdmin,
sendEmailByAdmin,
sendRawEmailByAdmin
};
116 changes: 115 additions & 1 deletion server/api/swagger/admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ paths:
properties:
html:
type: string
maxLength: 256
title:
type: string
maxLength: 256
Expand Down Expand Up @@ -2849,5 +2848,120 @@ paths:
- supervisor
- kyc
- support
x-token-permissions:
- can_withdraw
/admin/send-email:
x-swagger-router-controller: admin
post:
operationId: sendEmailByAdmin
description: Send email by admin
tags:
- Admin
parameters:
- name: data
in: body
required: true
schema:
type: object
required:
- user_id
- mail_type
- data
properties:
user_id:
type: number
format: int32
data:
type: object
mail_type:
type: string
enum: [
'welcome',
'login',
'signup',
'reset_password',
'change_password',
'password_changed',
'user_verification_reject',
'account_upgrade',
'account_verify',
'withdrawal_request',
'deposit_cancel',
'deposit',
'withdrawal',
'contactForm',
'suspicious_deposit',
'user_verification',
'user_deactivated',
'invalid_address',
'invitedOperator',
'alert',
'discount_update',
'bank_verified',
'confirm_email']
responses:
200:
description: Success
schema:
$ref: "#/definitions/ObjectResponse"
default:
description: "Error"
schema:
$ref: "#/definitions/MessageResponse"
security:
- Token: []
x-security-types:
- bearer
- hmac
x-security-scopes:
- admin
x-token-permissions:
- can_withdraw
/admin/send-email/raw:
x-swagger-router-controller: admin
post:
operationId: sendRawEmailByAdmin
description: Send email by admin
tags:
- Admin
parameters:
- name: data
in: body
required: true
schema:
type: object
required:
- receivers
- html
properties:
receivers:
type: array
items:
type: string
maxLength: 256
title:
type: string
maxLength: 256
html:
type: string
text:
type: string
maxLength: 256
responses:
200:
description: Success
schema:
$ref: "#/definitions/ObjectResponse"
default:
description: "Error"
schema:
$ref: "#/definitions/MessageResponse"
security:
- Token: []
x-security-types:
- bearer
- hmac
x-security-scopes:
- admin
x-token-permissions:
- can_withdraw
4 changes: 0 additions & 4 deletions server/api/swagger/definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,8 @@ definitions:
properties:
head:
type: string
maxLength: 256
body:
type: string
maxLength: 256
injected_values:
type: array
items:
Expand All @@ -499,10 +497,8 @@ definitions:
properties:
tag:
type: string
maxLength: 256
target:
type: string
maxLength: 256
attributes:
type: object
black_list_countries:
Expand Down
2 changes: 1 addition & 1 deletion server/api/swagger/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const definition = {
swagger: '2.0',
info: {
title: 'HollaEx Kit',
version: '2.6.1'
version: '2.6.2'
},
host: 'api.hollaex.com',
basePath: '/v2',
Expand Down
22 changes: 21 additions & 1 deletion server/mail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ const sendEmail = (
return send(payload);
};

const sendRawEmail = (
receivers,
title,
html,
text
) => {
let from = SUPPORT_SOURCE();

const payload = {
from,
to: receivers,
subject: `${API_NAME()} ${title || ''}`,
html,
text: text || ''
};

return send(payload);
};

const send = (params) => {
return sendSMTPEmail(params)
.then((info) => {
Expand Down Expand Up @@ -119,5 +138,6 @@ const testSendSMTPEmail = (receiver = '', smtp = {}) => {

module.exports = {
sendEmail,
testSendSMTPEmail
testSendSMTPEmail,
sendRawEmail
};
Loading

0 comments on commit 215ef40

Please sign in to comment.