Backend and frontend filtering (search and author), dashboard now displays creations
This commit is contained in:
parent
58268a94a9
commit
683f8784a7
11 changed files with 189 additions and 56 deletions
|
|
@ -5,7 +5,8 @@ const { authorizeModModification, authenticateToken } = require("../middleware/a
|
|||
async function listMods(req, res) {
|
||||
try {
|
||||
// Query
|
||||
const query_result = await mod_service.getAllMods();
|
||||
const filters = req.query;
|
||||
const query_result = await mod_service.listMods(filters);
|
||||
res.json(query_result);
|
||||
} catch (error) {
|
||||
handleError(error, res);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class SQLiteDatabase {
|
|||
// Runs with a result (ex: SELECT)
|
||||
async query(sql, params = []) {
|
||||
try {
|
||||
if (params.length > 0) {
|
||||
if ( params != []) {
|
||||
return this.db.prepare(sql).all(params);
|
||||
} else {
|
||||
return this.db.prepare(sql).all();
|
||||
|
|
|
|||
|
|
@ -5,12 +5,21 @@ const db = getDatabase();
|
|||
|
||||
// --- Get ---
|
||||
|
||||
async function getAllMods() {
|
||||
return await db.query("SELECT name, display_name, author, description FROM Mods");
|
||||
async function listMods(filters) {
|
||||
console.debug(filters);
|
||||
return await db.query(`SELECT name, display_name, author, description FROM Mods
|
||||
WHERE
|
||||
(CASE WHEN @search IS NOT NULL THEN
|
||||
name LIKE '%' || @search || '%' OR
|
||||
display_name LIKE '%' || @search || '%' OR
|
||||
description LIKE '%' || @search || '%'
|
||||
ELSE TRUE END) AND
|
||||
(CASE WHEN @author IS NOT NULL THEN author = @author ELSE TRUE END);
|
||||
`, filters);
|
||||
}
|
||||
|
||||
async function getModByName(name) {
|
||||
return await db.query("SELECT name, display_name, author FROM Mods WHERE name = ?;", [name]);
|
||||
return await db.query("SELECT name, display_name, author FROM Mods WHERE name = @name;", {name: name});
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +194,7 @@ async function containsTag(name, tag) {
|
|||
|
||||
// --- Exports ---
|
||||
|
||||
module.exports = { getAllMods, getModByName, getFullModInfos,
|
||||
module.exports = { listMods, getModByName, getFullModInfos,
|
||||
listVersions, listTags, getVersionByNumber, getVersion,
|
||||
createMod, addVersion, addTags,
|
||||
updateMod,
|
||||
|
|
|
|||
|
|
@ -7,8 +7,14 @@ const { sanitizeModData } = require("../utils/sanitize");
|
|||
|
||||
// --- Get ---
|
||||
|
||||
async function getAllMods() {
|
||||
return model.getAllMods();
|
||||
async function listMods(filters) {
|
||||
//TODO Validate filters
|
||||
console.warn("Skipping full filters validation: Not implemented");
|
||||
|
||||
filters.author = filters.author || null;
|
||||
filters.search = filters.search || null;
|
||||
|
||||
return await model.listMods({...filters});
|
||||
}
|
||||
|
||||
async function getModByName(name) {
|
||||
|
|
@ -162,7 +168,7 @@ async function deleteTags(mod, tags) {
|
|||
return { "mod": mod, "tags": res};
|
||||
}
|
||||
|
||||
module.exports = { getAllMods, getModByName, getFullModInfos,
|
||||
module.exports = { listMods, getModByName, getFullModInfos,
|
||||
createMod, addTags, addVersion,
|
||||
updateMod,
|
||||
deleteMod, deleteTags, deleteVersion };
|
||||
Loading…
Add table
Add a link
Reference in a new issue