Skip to content

Commit

Permalink
Merge pull request #3087 from hollaex/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
abeikverdi authored Nov 8, 2024
2 parents 6dceda9 + ce262e0 commit 8be5f8e
Show file tree
Hide file tree
Showing 221 changed files with 35,356 additions and 6,192 deletions.
83 changes: 72 additions & 11 deletions server/api/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ const createInitialAdmin = (req, res) => {
if (user) {
throw new Error('Admin already exists');
}

if (!email || !isEmail(email)) {
throw new Error(PROVIDE_VALID_EMAIL);
}
if (!toolsLib.security.isValidPassword(password)) {
throw new Error(INVALID_PASSWORD);
}

return toolsLib.user.createUser(email, password, {
role: 'admin',
id: 1,
Expand Down Expand Up @@ -2096,7 +2104,7 @@ const setUserBank = (req, res) => {
if (!foundBank) {
deletedBankInfoLog.push(existingBank);
}
})
});

const newBankAccounts = bank_account.map((bank) => {
let existingBank = existingBankAccounts.filter((b) => b.id === bank.id);
Expand Down Expand Up @@ -2126,8 +2134,8 @@ const setUserBank = (req, res) => {
}
}

newBankInfoLog.map(bank => toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, req?.swagger?.operationPath?.[2], bank))
deletedBankInfoLog.map(bank => toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, 'delete', bank))
newBankInfoLog.map(bank => toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, req?.swagger?.operationPath?.[2], bank));
deletedBankInfoLog.map(bank => toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, 'delete', bank));
return res.json(updatedUser.bank_account);
})
.catch((err) => {
Expand Down Expand Up @@ -2300,7 +2308,7 @@ const getUserReferer = (req, res) => {
};

const createUserByAdmin = (req, res) => {
const { email, password } = req.swagger.params.data.value;
const { email, password, referral } = req.swagger.params.data.value;

loggerAdmin.info(req.uuid, 'controllers/admin/createUserByAdmin email', email);

Expand All @@ -2325,6 +2333,7 @@ const createUserByAdmin = (req, res) => {
role: 'user',
id: null,
email_verified: true,
referral,
additionalHeaders: {
'x-forwarded-for': req.headers['x-forwarded-for']
}
Expand Down Expand Up @@ -2858,7 +2867,7 @@ const disableUserWithdrawal = (req, res) => {
expiry_date
);

toolsLib.user.disableUserWithdrawal(user_id, { expiry_date })
toolsLib.user.disableUserWithdrawal(user_id, { expiry_date })
.then((data) => {
toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, req?.swagger?.operationPath?.[2], req?.swagger?.params?.data?.value);
loggerAdmin.info(
Expand Down Expand Up @@ -2908,10 +2917,10 @@ const createTradeByAdmin = (req, res) => {
taker_fee
);

toolsLib.order.createTrade({symbol, side, price, size, maker_id, taker_id, maker_fee, taker_fee },
{
'x-forwarded-for': req.headers['x-forwarded-for']
})
toolsLib.order.createTrade({symbol, side, price, size, maker_id, taker_id, maker_fee, taker_fee },
{
'x-forwarded-for': req.headers['x-forwarded-for']
})
.then((data) => {
toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, req?.swagger?.operationPath?.[2], req?.swagger?.params?.data?.value);
loggerAdmin.info(
Expand Down Expand Up @@ -3001,6 +3010,35 @@ const createUserReferralCodeByAdmin = (req, res) => {
});
};

const fetchUserTradingVolumeByAdmin = (req, res) => {
const { user_id, to, from } = req.swagger.params;

loggerAdmin.info(
user_id.value,
'controllers/user/fetchUserTradingVolumeByAdmin',
to.value,
from.value
);

toolsLib.user.fetchUserTradingVolume(
user_id.value,
{
to: to.value,
from: from.value
}
)
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerAdmin.error(
req.uuid,
'controllers/user/fetchUserTradingVolumeByAdmin err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const getPaymentDetailsByAdmin = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/getPaymentDetailsByAdmin/auth', req.auth);
Expand Down Expand Up @@ -3082,7 +3120,7 @@ const deletePaymentDetailByAdmin = (req, res) => {
toolsLib.user.deletePaymentDetail(id, user_id)
.then(() => {
return res.json({
message: "Success"
message: 'Success'
});
})
.catch((err) => {
Expand All @@ -3091,6 +3129,27 @@ const deletePaymentDetailByAdmin = (req, res) => {
});
};

const deleteUserByAdmin = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/deleteUserByAdmin/auth', req.auth);

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

loggerAdmin.verbose(
req.uuid,
'controllers/admin/deleteUserByAdmin',
'user_id',
user_id,
);
toolsLib.user.deleteKitUser(user_id, false)
.then(() => {
return res.json({ message: 'Success' });
})
.catch((err) => {
loggerAdmin.error(req.uuid, 'controllers/admin/deleteUserByAdmin', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err, req?.auth?.sub?.lang) });
});
};

module.exports = {
createInitialAdmin,
getAdminKit,
Expand Down Expand Up @@ -3165,8 +3224,10 @@ module.exports = {
performDirectWithdrawalByAdmin,
getUserReferralCodesByAdmin,
createUserReferralCodeByAdmin,
fetchUserTradingVolumeByAdmin,
getPaymentDetailsByAdmin,
createPaymentDetailByAdmin,
updatePaymentDetailByAdmin,
deletePaymentDetailByAdmin
deletePaymentDetailByAdmin,
deleteUserByAdmin
};
1 change: 1 addition & 0 deletions server/api/controllers/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ const adminCancelOrder = (req, res) => {
});
};


module.exports = {
createOrder,
createOrderByAdmin,
Expand Down
3 changes: 2 additions & 1 deletion server/api/controllers/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ const createP2PFeedback = (req, res) => {
const fetchP2PFeedbacks = (req, res) => {
loggerP2P.verbose(req.uuid, 'controllers/p2p/fetchP2PFeedbacks/auth', req.auth);

const { transaction_id, merchant_id, limit, page, order_by, order, start_date, end_date, format } = req.swagger.params;
const { transaction_id, merchant_id, user_id, limit, page, order_by, order, start_date, end_date, format } = req.swagger.params;

if (format.value && req.auth.scopes.indexOf(ROLES.ADMIN) === -1) {
return res.status(403).json({ message: API_KEY_NOT_PERMITTED });
Expand All @@ -527,6 +527,7 @@ const fetchP2PFeedbacks = (req, res) => {
toolsLib.p2p.fetchP2PFeedbacks({
transaction_id: transaction_id.value,
merchant_id: merchant_id.value,
user_id: user_id.value,
limit: limit.value,
page: page.value,
order_by: order_by.value,
Expand Down
145 changes: 144 additions & 1 deletion server/api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const { all } = require('bluebird');
const { each, isInteger } = require('lodash');
const { publisher } = require('../../db/pubsub');
const { isDate } = require('moment');
const moment = require('moment');
const DeviceDetector = require('node-device-detector');
const uuid = require('uuid/v4');

Expand Down Expand Up @@ -1476,6 +1477,36 @@ const fetchUserReferrals = (req, res) => {
});
};

const fetchUserTradingVolume = (req, res) => {
const { to, from } = req.swagger.params;

loggerUser.info(
req.uuid,
'controllers/user/fetchUserTradingVolume',
to.value,
from.value
);

toolsLib.user.fetchUserTradingVolume(
req.auth.sub.id,
{
to: to.value,
from: from.value
}
)
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerUser.error(
req.uuid,
'controllers/user/fetchUserTradingVolume err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const fetchUserAddressBook = (req, res) => {
loggerUser.verbose(req.uuid, 'controllers/user/fetchUserAddressBook/auth', req.auth);

Expand Down Expand Up @@ -1600,6 +1631,113 @@ const deletePaymentDetail = (req, res) => {
};


const fetchUserAutoTrades = (req, res) => {
loggerUser.verbose(req.uuid, 'controllers/user/fetchUserAutoTrades/auth', req.auth);

const { limit, page, order_by, order, start_date, end_date, active } = req.swagger.params;

if (order_by.value && typeof order_by.value !== 'string') {
loggerUser.error(
req.uuid,
'controllers/user/fetchUserAutoTrades invalid order_by',
order_by.value
);
return res.status(400).json({ message: 'Invalid order by' });
}

toolsLib.user.fetchUserAutoTrades(req.auth.sub.id, {
limit: limit.value,
page: page.value,
order_by: order_by.value,
order: order.value,
start_date: start_date.value,
end_date: end_date.value,
active: active.value
})
.then((data) => res.json(data))
.catch((err) => {
loggerUser.error(req.uuid, 'controllers/user/fetchUserAutoTrades', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const createUserAutoTrade = (req, res) => {
loggerUser.verbose(req.uuid, 'controllers/user/createUserAutoTrade/auth', req.auth);

const { spend_coin, buy_coin, spend_amount, frequency, week_days, day_of_month, trade_hour, active, description } = req.swagger.params.data.value;

loggerUser.verbose(
req.uuid,
'controllers/user/createUserAutoTrade data',
spend_coin, buy_coin, spend_amount, frequency, week_days, day_of_month, trade_hour, active, description
);

toolsLib.user.createUserAutoTrade(req.auth.sub.id, {
spend_coin,
buy_coin,
spend_amount,
frequency,
week_days,
day_of_month,
trade_hour,
active,
description
})
.then((data) => res.json(data))
.catch((err) => {
loggerUser.error(req.uuid, 'controllers/user/createUserAutoTrade', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const updateUserAutoTrade = (req, res) => {
loggerUser.verbose(req.uuid, 'controllers/user/updateUserAutoTrade/auth', req.auth);

const { id, spend_coin, buy_coin, spend_amount, frequency, week_days, day_of_month, trade_hour, active, description } = req.swagger.params.data.value;

loggerUser.verbose(
req.uuid,
'controllers/user/updateUserAutoTrade data',
id, spend_coin, buy_coin, spend_amount, frequency, week_days, day_of_month, trade_hour, active, description
);

toolsLib.user.updateUserAutoTrade(req.auth.sub.id, {
id,
spend_coin,
buy_coin,
spend_amount,
frequency,
week_days,
day_of_month,
trade_hour,
active,
description
})
.then((data) => res.json(data))
.catch((err) => {
loggerUser.error(req.uuid, 'controllers/user/updateUserAutoTrade', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const deleteUserAutoTrade = (req, res) => {
loggerUser.verbose(req.uuid, 'controllers/user/deleteUserAutoTrade/auth', req.auth);

const { removed_ids } = req.swagger.params.data.value;

loggerUser.verbose(req.uuid, 'controllers/user/deleteUserAutoTrade data', removed_ids);

toolsLib.user.deleteUserAutoTrade({
user_id: req.auth.sub.id,
removed_ids
})
.then((data) => res.json(data))
.catch((err) => {
loggerUser.error(req.uuid, 'controllers/user/deleteUserAutoTrade', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

module.exports = {
signUpUser,
getVerifyUser,
Expand Down Expand Up @@ -1638,10 +1776,15 @@ module.exports = {
fetchUserReferrals,
createUserReferralCode,
getUserReferralCodes,
fetchUserTradingVolume,
updateUserAddresses,
fetchUserAddressBook,
getPaymentDetails,
createPaymentDetail,
updatePaymentDetail,
deletePaymentDetail
deletePaymentDetail,
fetchUserAutoTrades,
createUserAutoTrade,
updateUserAutoTrade,
deleteUserAutoTrade
};
Loading

0 comments on commit 8be5f8e

Please sign in to comment.