@padhariyavishal/nextpress
Version:
NextJS based CMS Framework.
72 lines (71 loc) • 3.69 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollectionModel = void 0;
const config_1 = require("../lib/config");
class CollectionModel {
/**
*
* @param args Object of the arguments to fetch the collections.
*/
get(args) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
let query = `
SELECT
np_collections.*,
np_users.username AS author_name,
np_collection_status.status AS status_name,
np_collection_types.name AS type_name,
np_categories.name AS category_name,
np_categories.uri AS category_uri
FROM
np_collections
JOIN
np_users ON np_collections.author = np_users.id
JOIN
np_collection_status ON np_collections.status = np_collection_status.id
JOIN
np_collection_types ON np_collections.type = np_collection_types.id
JOIN
np_categories ON np_collections.id = np_categories.collection_id;
WHERE
np_collection_types.name = "${args === null || args === void 0 ? void 0 : args.ctype}"
AND
np_collection_status.status = "${args === null || args === void 0 ? void 0 : args.status}"
`;
if (args === null || args === void 0 ? void 0 : args.s) {
query += ` ( np_collections.title LIKE '%${args === null || args === void 0 ? void 0 : args.s}%' OR
np_collections.content LIKE '%${args === null || args === void 0 ? void 0 : args.s}%' OR
np_collections.uri LIKE '%${args === null || args === void 0 ? void 0 : args.s}%' OR
np_users.username LIKE '%${args === null || args === void 0 ? void 0 : args.s}%' OR
np_categories.name LIKE '%${args === null || args === void 0 ? void 0 : args.s}%'
)`;
}
if (args === null || args === void 0 ? void 0 : args.by_author) {
query += `AND np_users.id= ${args === null || args === void 0 ? void 0 : args.by_author}`;
}
if (args === null || args === void 0 ? void 0 : args.parent) {
query += `AND np_collections.parent= ${args === null || args === void 0 ? void 0 : args.parent}`;
}
if (args === null || args === void 0 ? void 0 : args.by_category) {
query += `AND np_categories.${(_a = args === null || args === void 0 ? void 0 : args.by_category) === null || _a === void 0 ? void 0 : _a.key} = '${(_b = args === null || args === void 0 ? void 0 : args.by_category) === null || _b === void 0 ? void 0 : _b.value}'`;
}
if (args === null || args === void 0 ? void 0 : args.id) {
query += ` AND np_collections.id= ${args === null || args === void 0 ? void 0 : args.id}`;
}
query += `;`;
const [rows] = yield config_1.npdb.query(query);
return rows;
});
}
}
exports.CollectionModel = CollectionModel;