From 0c65dee04506567ee50537ff2fbb83998b8fef0f Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Wed, 10 Apr 2024 03:41:05 +0300 Subject: add methods in kb-util module; intoduce match-util module --- paths.js | 71 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 30 deletions(-) (limited to 'paths.js') diff --git a/paths.js b/paths.js index f772478..2653ff3 100644 --- a/paths.js +++ b/paths.js @@ -1,41 +1,45 @@ const Router = require('koa-router'); -const kbu = require('./pieces/kbutils.js'); +const kb = require('./pieces/kb-util.js'); // Prefix all routes with: /items const router = new Router({ //// prefix: '/items' }); -// let items = [ -// { id: 100, iname: 'Quartz Analog Wrist Watch', price: 'US $4.99'}, -// { id: 101, iname: 'Leather Peep Pump Heels', price: 'US $33.56'}, -// { id: 102, iname: 'Apple iPod', price: 'US $219.99'}, -// { id: 103, iname: 'Prince Phantom 97P Tennnis Racket', price: 'US $50.00'}, -// ]; +/* simple route example + let items = [ + { id: 100, iname: 'Quartz Analog Wrist Watch', price: 'US $4.99'}, + { id: 101, iname: 'Leather Peep Pump Heels', price: 'US $33.56'}, + { id: 102, iname: 'Apple iPod', price: 'US $219.99'}, + { id: 103, iname: 'Prince Phantom 97P Tennnis Racket', price: 'US $50.00'}, + ]; + + // Routes + + router.get('/items', (ctx, next) => { + ctx.body = items; + next(); + }); + + router.get('/items/:id', (ctx, next) => { + let getCurrentItem = items.filter(function(item) { + if (item.id == ctx.params.id) { + return true; + } + }); + if (getCurrentItem.length) { + ctx.body = getCurrentItem[0]; + } else { + ctx.response.status = 404; + ctx.body = 'Item Not Found'; + } + next(); + }); +*/ -// Routes -/// router.get('/items', (ctx, next) => { -/// ctx.body = items; -/// next(); -/// }); -/// -/// router.get('/items/:id', (ctx, next) => { -/// let getCurrentItem = items.filter(function(item) { -/// if (item.id == ctx.params.id) { -/// return true; -/// } -/// }); -/// -/// if (getCurrentItem.length) { -/// ctx.body = getCurrentItem[0]; -/// } else { -/// ctx.response.status = 404; -/// ctx.body = 'Item Not Found'; -/// } -/// next(); -/// }); +// Routes router.get('/search', (ctx, next) => { ctx.body = []; @@ -43,7 +47,7 @@ router.get('/search', (ctx, next) => { }); router.get('/search/:title', (ctx, next) => { - let words = kbu.keybutil.keyboardize(ctx.params.title).split(' '); + let words = kb.keyboardize(kb.clean(ctx.params.title)).split(' '); ctx.body = { params: ctx.params, results: words @@ -53,8 +57,15 @@ router.get('/search/:title', (ctx, next) => { /** other routes * + /suggest/ - * + /create + * + /prepare (products, keywords, linked-terms etc) * + /stats */ +router.get('/test', (ctx, next) => { // easy test route + // test anything ... + let result = { success: true, data: [1, 2, 3] }; + ctx.body = result; + next(); +}); + module.exports = router; \ No newline at end of file -- cgit v1.2.3