index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const express = require('express');
  2. const path = require('path');
  3. const CrudModule = require('../../base/CrudModule');
  4. const RepositorySystem = require('../../systems/RepositorySystem');
  5. const RoutingSystem = require('../../systems/RoutingSystem');
  6. let Global = {
  7. fields: [
  8. {
  9. key: "name",
  10. type: "text"
  11. },
  12. {
  13. key:"value",
  14. type: "text"
  15. }
  16. ]
  17. };
  18. class CustomModule extends CrudModule {
  19. constructor(){
  20. super('/globals', [3,0,3,4,0], 'Globals');
  21. this.repository = RepositorySystem.create('Globals', Global);
  22. this.setRepo(this.repository);
  23. // this.users = RepositorySystem.create('Users'); // You can get any repo you want!!
  24. this.router = express.Router();
  25. this.init();
  26. }
  27. init() {
  28. let routes = [
  29. {
  30. type: 'custom',
  31. method: 'get',
  32. endpoint: '/select/:name',
  33. customFn: this.selectGlobal.bind(this)
  34. }
  35. ];
  36. RoutingSystem.loadRoutes(routes, this.router, '/globals');
  37. }
  38. selectGlobal(req, res) {
  39. let name = req.params.name;
  40. this.repository.get('name', name)
  41. .then((item) => res.send(item));
  42. }
  43. }
  44. module.exports = {};//new CustomModule();