UNPKG

notion-page-tree

Version:

Recursively fetch nested Notion pages from the root page/database/block node.

31 lines (30 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.treeServerHandler = void 0; var convertNotionId_1 = require("../utils/convertNotionId"); var buildPageTreeToDepth_1 = require("../utils/buildPageTreeToDepth"); var treeServerHandler = function (router, data_set) { router.get('/tree/:id', function (req, res) { var convertedId = (0, convertNotionId_1.convertNotionId)(req.params.id, 'dashed'); var treeDepth; try { treeDepth = req.query.depth ? parseInt(req.query.depth) : undefined; } catch (e) { res .status(400) .send("Query parameter 'depth' should be an integer. Provided ".concat(req.query.depth, ".")); } // data_set.root data_set.page_collection ? req.params.id ? res.send( // JSON.stringify( // retrieveSubtree(data_set.root, convertedId, treeDepth) // ) JSON.stringify((0, buildPageTreeToDepth_1.buildPageTreeToDepth)(data_set.page_collection, convertedId, treeDepth))) : res.sendStatus(502) : res.sendStatus(503); }); }; exports.treeServerHandler = treeServerHandler;