Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): decode the search query before searching #138

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};
};