nfp_sites/old/page/routes.mjs

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-09-13 13:33:10 +00:00
import Page from './model.mjs'
import * as security from './security.mjs'
export default class PageRoutes {
constructor(opts = {}) {
Object.assign(this, {
Page: opts.Page || Page,
security: opts.security || security,
})
}
2021-02-05 11:50:01 +00:00
/** GET: /api/pagetree */
async getPageTree(ctx) {
ctx.body = await this.Page.getTree()
}
2019-09-13 13:33:10 +00:00
/** GET: /api/pages */
async getAllPages(ctx) {
await this.security.ensureIncludes(ctx)
2021-02-05 11:50:01 +00:00
ctx.body = await this.Page.getAll(ctx, null, ctx.state.filter.includes, 'name')
2019-09-13 13:33:10 +00:00
}
/** GET: /api/pages/:id */
async getSinglePage(ctx) {
await this.security.ensureIncludes(ctx)
2022-04-05 16:47:24 +00:00
ctx.body = await this.Page.getSingle(ctx.params.pageId, ctx.state.filter.includes, true, ctx)
2019-09-13 13:33:10 +00:00
}
/** POST: /api/pages */
async createPage(ctx) {
await this.security.validUpdate(ctx)
ctx.body = await this.Page.create(ctx.request.body)
}
/** PUT: /api/pages/:id */
async updatePage(ctx) {
await this.security.validUpdate(ctx)
2021-02-05 11:50:01 +00:00
let page = await this.Page.updateSingle(ctx, ctx.params.id, ctx.request.body)
2019-09-13 13:33:10 +00:00
ctx.body = page
}
/** DELETE: /api/pages/:id */
async removePage(ctx) {
2021-02-05 11:50:01 +00:00
await this.Page.updateSingle(ctx, ctx.params.id, { is_deleted: true })
2019-09-13 13:33:10 +00:00
ctx.status = 204
}
}