Skip to content

Commit

Permalink
Merge pull request #620 from zurichat/revert-618-search_endpoint
Browse files Browse the repository at this point in the history
Revert "feat-search_endpoint"
  • Loading branch information
omzi authored Oct 11, 2021
2 parents 0a75803 + 53c05a0 commit 2936f58
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 61 deletions.
26 changes: 0 additions & 26 deletions backend/controllers/index.html

This file was deleted.

33 changes: 1 addition & 32 deletions backend/controllers/search.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const DatabaseOps = require('../utils/database.helper');
const File = new DatabaseOps('File');
const Folder = new DatabaseOps('Folder');
const appResponse = require('../utils/appResponse');


Expand All @@ -10,6 +9,7 @@ exports.searchAndFilterFiles = async (req, res) => {

if (fileName.trim()) {
const data = await File.fetchAll();

let response;

if (fileType.trim()) {
Expand All @@ -31,35 +31,4 @@ exports.searchAndFilterFiles = async (req, res) => {
} else {
return res.status(400).send(appResponse('Invalid fileName provided!', null));
}
}

exports.searchFileAndFolder = async (req, res) => {
let { searchQuery } = req.query;
console.log(searchQuery)
const fileData = await File.fetchAll();
const folderData = await Folder.fetchAll();


if (searchQuery.trim()) {
searchFile = fileData.filter(({ fileName: name }) => {
return new RegExp(String(searchQuery), 'i').test(name);
})
searchFolder = folderData.filter(({ folderName: name }) => {
return new RegExp(String(searchQuery), 'i').test(name);
})

const response = await Promise.all([searchFile,searchFolder]);

if ((response[0].length <= 0) && (response[1].length <= 0)) {
return res.status(404).send(appResponse('No such File/Folder!', null, true));
}
return res.status(200).send(appResponse('Search results for files and folders', response, true));
} else {
return res.status(400).send(appResponse('Invalid search entry!', null));
}

}

exports.testSearch = async (req,res) => {
res.sendFile(`${__dirname}/index.html`);
}
4 changes: 1 addition & 3 deletions backend/routes/search.route.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const router = require('express').Router();
const { searchAndFilterFiles,searchFileAndFolder,testSearch } = require('../controllers/search.controller');
const { searchAndFilterFiles } = require('../controllers/search.controller');

router.get('/', searchAndFilterFiles);
router.get('/fileAndFolder/', searchFileAndFolder)
router.get('/testSearch/', testSearch)

module.exports = router;

0 comments on commit 2936f58

Please sign in to comment.