Skip to content

Commit

Permalink
Merge pull request #138 from Whats-Cookin/fix/search-query-encode
Browse files Browse the repository at this point in the history
fix(query): decode the search query before searching
  • Loading branch information
AhmedAbdelmenam authored Sep 11, 2024
2 parents daa088a + ad3d856 commit efe5f35
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/controllers/node.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response, NextFunction } from "express";
import { Request, Response, NextFunction, urlencoded } from "express";
import { passToExpressErrorHandler, turnFalsyPropsToUndefined } from "../utils";
import createError from "http-errors";

Expand All @@ -10,7 +10,7 @@ const nodeDao = new NodeDao();
export const getNodeById = async (
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
) => {
try {
const { nodeId } = req.params;
Expand All @@ -31,18 +31,20 @@ export const getNodeById = async (
export const searchNodes = async (
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
) => {
try {
const { search, page = 1, limit = 10 } = req.query;
let nodes;
let count;

const _search = decodeURIComponent(search?.toString() || "");

if (search) {
const searchResult = await nodeDao.searchNodes(
search as string,
_search,
Number(page),
Number(limit)
Number(limit),
);
nodes = searchResult.nodes;
count = searchResult.count;
Expand All @@ -61,7 +63,7 @@ export const searchNodes = async (
export const getNodeForLoggedInUser = async (
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
) => {
try {
const userId = (req as ModifiedRequest).userId;
Expand All @@ -79,7 +81,7 @@ export const getNodeForLoggedInUser = async (
export const claimReport = async (
req: Request,
res: Response,
next: NextFunction
next: NextFunction,
) => {
try {
const { claimId } = req.params;
Expand All @@ -106,4 +108,5 @@ export const claimReport = async (
} catch (err) {
passToExpressErrorHandler(err, next);
}
};
};

0 comments on commit efe5f35

Please sign in to comment.