More development

master
Jonatan Nilsson 2022-06-28 08:15:51 +00:00
parent dd02e98c91
commit a666e1d351
7 changed files with 25 additions and 12 deletions

0
api/article/model.mjs Normal file
View File

View File

@ -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) {

View File

@ -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)
}

View File

@ -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
)
}
}

View File

@ -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()

View File

@ -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),
})
}

View File

@ -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