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

Installed Quality and Standard JS package as static analysis tool #31

Open
wants to merge 1 commit into
base: f24
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file modified dump.rdb
Binary file not shown.
5 changes: 3 additions & 2 deletions install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"start": "node loader.js",
"lint": "eslint --cache ./nodebb .",
"test": "nyc --reporter=html --reporter=text-summary mocha",
"test": "standard && node my-tests.js",
"coverage": "nyc report --reporter=text-lcov > ./coverage/lcov.info",
"coveralls": "nyc report --reporter=text-lcov | coveralls && rm -r coverage"
},
Expand Down Expand Up @@ -160,6 +160,7 @@
"eslint": "8.57.0",
"eslint-config-nodebb": "0.2.1",
"eslint-plugin-import": "2.29.1",
"standard": "*",
"grunt": "1.6.1",
"grunt-contrib-watch": "1.1.0",
"husky": "8.0.3",
Expand Down Expand Up @@ -195,4 +196,4 @@
"url": "https://github.com/barisusakli"
}
]
}
}
38 changes: 17 additions & 21 deletions src/controllers/write/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,24 @@ Topics.unfollow = async (req, res) => {

Topics.search = async (req, res) => {
try {
// Destructures the query parameters sent in the URL request
const { term } = req.query;

// Validate the input
if (!term) {
throw new Error('[[error:invalid-data]]');
}

// Prepare data for the API call
const data = {
term,
query: req.query.query || '', // Any additional query parameters
};

// Call the API to search topics
const results = await api.topics.search(data);

// Format the response
helpers.formatApiResponse(200, res, results);
// Destructures the query parameters sent in the URL request
const { term } = req.query;
// Validate the input
if (!term) {
throw new Error('[[error:invalid-data]]');
}
// Prepare data for the API call
const data = {
term,
query: req.query.query || '', // Any additional query parameters
};
// Call the API to search topics
const results = await api.topics.search(data);
// Format the response
helpers.formatApiResponse(200, res, results);
} catch (error) {
// Handle any errors
helpers.formatApiResponse(500, res, { error: error.message });
// Handle any errors
helpers.formatApiResponse(500, res, { error: error.message });
}
};

Expand Down
57 changes: 0 additions & 57 deletions src/topics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,60 +32,3 @@ module.exports = function (Topics) {
return topics;
};
};


// 'use strict';

// const _ = require('lodash');

// const privilege = require('../privilege');
// const plugins = require('../plugins');
// const db = require('../database');
// const { search } = require('.');

// module.exports = function (Posts) {
// Posts.search = async function (data) {
// const query = data.query || '';
// const page = data.page || 1;
// const pid = data.pid || 0;
// const paginate = data.hasOwnProperty('paginate') ? data.paginate : true;
// const searchBy = data.searchBy || 'keywords';

// let pids = [];
// if (searchBy === 'keywords') {
// pids = await searchByKeywords(query);
// }
// // Add other searchBy options here

// const result = await plugins.hooks.fire('filter:posts.search', { pids: pids, pid: pid});
// pids = result.pids;

// const searchResult = {
// matchCount: pids.length,
// };

// if (paginate) {
// const resultsPerPage = data.resultsPerPage || 50;
// const start = Math.max(0, page - 1) * resultsPerPage;
// const stop = start + resultsPerPage;
// searchResult.pageCount = Math.ceil(pids.length / resultsPerPage);
// pids = pids.slice(start, stop);
// }

// return searchResult;
// }

// async function searchByKeywords(query) {
// const keywordsArr = query.split(' ');
// keywordsArr = keywordsArr.map(keyword => keyword.toLowerCase());
// const topics = await db.getSortedSetRevRange('post:pid', 0, -1);
// topics = topics.filter(topic => {
// keywordsArr.some(keyword =>
// topic.title.toLowerCase().includes(keyword) ||
// topic.content.toLowerCase().includes(keyword))
// })

// const pids = topics.map(topic => topic.pid);
// return pids;
// }
// };
Loading