Skip to content

Commit

Permalink
Merge pull request #365 from ArslanKibria98/develop
Browse files Browse the repository at this point in the history
getBulkCabn api for public modified
  • Loading branch information
zikriya committed Jan 30, 2024
2 parents 06557ba + 8575b33 commit 6a7623a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/controllers/api/v1/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mongoose = require("mongoose");
import { getUserForPublicApis } from "../../../helpers/authHelpers/rootAuthHelper";

module.exports = function (router: any) {
router.get("/:name", async (req: any, res: any) => {
Expand Down Expand Up @@ -391,7 +392,7 @@ module.exports = function (router: any) {
let filter: any[] = [];
const query: { [key: string]: any } = {};
const embeddedDocumentQuery: { [key: string]: any } = {};

const user = await getUserForPublicApis(req);
if (req.query.network) {
query["network"] = new mongoose.Types.ObjectId(req.query.network);
}
Expand Down Expand Up @@ -489,6 +490,9 @@ module.exports = function (router: any) {
isAllowedOnMultiSwap: 1,
decimals: 1,
isNative: 1,
isDefault: 1,
nonDefaultCurrencyInformation: 1,
createdByusers: 1,
"network._id": 1,
"network.name": 1,
"network.nameInLower": 1,
Expand All @@ -508,13 +512,23 @@ module.exports = function (router: any) {
if (req.query.chainId) {
embeddedDocumentQuery["network.chainId"] = req.query.chainId;
}
if (user && user._id) {
embeddedDocumentQuery.$or = [
{ createdByusers: new mongoose.Types.ObjectId(user._id) },
{ isDefault: true },
];
} else {
embeddedDocumentQuery["isDefault"] = true;
}
if (req.query.search) {
const reg = new RegExp(req.query.search, "i");
embeddedDocumentQuery.$or = [
{ "currency.name": reg },
{ "currency.nameInLower": reg },
{ "currency.symbol": reg },
{ tokenContractAddress: reg },
{ "nonDefaultCurrencyInformation.name": reg },
{ "nonDefaultCurrencyInformation.symbol": reg },
];
}

Expand Down
11 changes: 11 additions & 0 deletions app/helpers/authHelpers/rootAuthHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ export const getUser = async (id: string) => {
export const invalidRequest = async (res: any) => {
return res.http401(INVALID_TOKEN);
};

export const getUserForPublicApis = async (req: any): Promise<any> => {
try {
const token = req.headers.authorization.split(" ")[1];
const decoded = jwt.verify(token, (global as any).environment.jwtSecret);
const user = await getUser(decoded?._id);
return user;
} catch (e) {
return null;
}
};

0 comments on commit 6a7623a

Please sign in to comment.