index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const FilterService = require('./FilterService')
  2. const express = require('express');
  3. const RepositorySystem = require('../../systems/RepositorySystem');
  4. const RoutingSystem = require('../../systems/RoutingSystem');
  5. const knex = require('../../database/db');
  6. //1 Dont know if it will be Crud Extension
  7. //2
  8. class SearchModule {
  9. constructor(){
  10. //Missing Roles Options
  11. //Dont know it will extends Crud
  12. this.router = express.Router();
  13. this.table = 'products';
  14. this.init();
  15. }
  16. init() {
  17. let routes = [
  18. {
  19. type: 'custom',
  20. method: 'get',
  21. endpoint: '/',
  22. customFn: (req,res) => {
  23. this.searchFn(req,res)
  24. }
  25. }
  26. ];
  27. RoutingSystem.loadRoutes(routes, this.router, '/search');
  28. }
  29. searchFn(req,res) {
  30. console.log("here")
  31. var query = knex.table(this.table).select('*');
  32. if(req.body.length){
  33. query = FilterService.parseFilters(query, req.body);
  34. }
  35. // Missing lots of functionality
  36. res.send(200)
  37. }
  38. }
  39. module.exports = SearchModule;