From a666e1d351e6ffaf9379724a2facb0b26b79ce4a Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Tue, 28 Jun 2022 08:15:51 +0000 Subject: [PATCH] More development --- api/article/model.mjs | 0 api/db.mjs | 4 +++- api/page/model.mjs | 6 ++++++ api/page/routes.mjs | 10 ++++++++++ api/server.mjs | 3 ++- app/api/page.p.js | 4 ++-- app/frontpage/frontpage.js | 10 ++-------- 7 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 api/article/model.mjs diff --git a/api/article/model.mjs b/api/article/model.mjs new file mode 100644 index 0000000..e69de29 diff --git a/api/db.mjs b/api/db.mjs index e4448b8..bf4ac68 100644 --- a/api/db.mjs +++ b/api/db.mjs @@ -38,9 +38,11 @@ export function initPool(core, config) { core.log.info('Attempting to connect to MSSQL server') pool.open() + // const sp = pool.procedureMgr() + return { safeCallProc: function(name, params, options) { - return pool.promises.callProc(name, params, options) + return pool.promises.callProc(config.schema + '.' + name, params, options) .catch(function(err) { let message = err.message if (err.lineNumber && err.procName) { diff --git a/api/page/model.mjs b/api/page/model.mjs index 612fe14..b16ab5b 100644 --- a/api/page/model.mjs +++ b/api/page/model.mjs @@ -43,3 +43,9 @@ export async function getTree(ctx) { tree: out } } + +export async function getPage(ctx, path, page = 0, per_page = 10) { + let res = await ctx.db.safeCallProc('pages_getpage', [path, page, per_page]) + console.log([path, page, per_page]) + console.log(res.results) +} diff --git a/api/page/routes.mjs b/api/page/routes.mjs index 503d427..a2bc25d 100644 --- a/api/page/routes.mjs +++ b/api/page/routes.mjs @@ -13,4 +13,14 @@ export default class PageRoutes { async getPageTree(ctx) { ctx.body = await this.Page.getTree(ctx) } + + /** GET: /api/page/[path] */ + async getPage(ctx) { + ctx.body = await this.Page.getPage( + ctx, + ctx.params.path || null, + ctx.query.get('page') || 1, + ctx.query.get('per_page') || 10 + ) + } } diff --git a/api/server.mjs b/api/server.mjs index a2660b7..eb17cd6 100644 --- a/api/server.mjs +++ b/api/server.mjs @@ -57,7 +57,8 @@ export function run(http, port, core) { const page = new PageRoutes() flaska.get('/api/pagetree', page.getPageTree.bind(page)) - // flaska.get('/api/pages', page.getAllPages.bind(page)) + flaska.get('/api/frontpage', page.getPage.bind(page)) + flaska.get('/api/pages/:path', page.getPage.bind(page)) // flaska.get('/api/pages/:pageId', page.getSinglePage.bind(page)) // const article = new ArticleRoutes() diff --git a/app/api/page.p.js b/app/api/page.p.js index 386a734..80b5505 100644 --- a/app/api/page.p.js +++ b/app/api/page.p.js @@ -11,9 +11,9 @@ exports.getTree = function() { }) } -exports.getPage = function(id) { +exports.getPage = function(path, page) { return common.sendRequest({ method: 'GET', - url: '/api/pages/' + id + '?includes=media,banner,children,parent', + url: '/api/' + (path ? 'pages/' + path : 'frontpage') + '?page=' + (page || 1), }) } diff --git a/app/frontpage/frontpage.js b/app/frontpage/frontpage.js index 29a3eb1..2443922 100644 --- a/app/frontpage/frontpage.js +++ b/app/frontpage/frontpage.js @@ -55,15 +55,9 @@ const Frontpage = { document.title = 'NFP Moe - Anime/Manga translation group' } - return Pagination.fetchPage(Article.getAllArticlesPagination({ - per_page: 10, - page: this.lastpage, - includes: ['parent', 'files', 'media', 'banner', 'staff'], - })) + return Page.getPage(null, this.lastpage) .then(function(result) { - vnode.state.articles = result.data - vnode.state.links = result.links - Frontpage.processFeatured(vnode, result.data) + console.log(result) }) .catch(function(err) { vnode.state.error = err.message