index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const express = require('express');
  2. const path = require('path');
  3. const CrudModule = require('klapi/base/CrudModule');
  4. const OneToOne = require('klapi/base/OneToOne');
  5. const RepositorySystem = require('klapi/systems/RepositorySystem');
  6. const RoutingSystem = require('klapi/systems/RoutingSystem');
  7. const Actions = require('klapi/systems/ActionSystem');
  8. let CategoriesScheme = {
  9. fields: [
  10. {
  11. key: "name",
  12. type: "string",
  13. unique: true,
  14. keyLength: 50
  15. },
  16. {
  17. key: "link",
  18. type: "text"
  19. },
  20. {
  21. key: "quantity",
  22. type: "integer"
  23. }
  24. ]
  25. };
  26. class CategoriesModule extends CrudModule {
  27. constructor(){
  28. super('/categories', [1,0,1,1,0], 'Categories', '', );
  29. this.repository = RepositorySystem.create('Categories', CategoriesScheme);
  30. this.setRepo(this.repository);
  31. // this.userAccountConnection = new OneToOne('Account', 'Users');
  32. // Actions.on('postUsers', (user) => {
  33. // let acc = {
  34. // };
  35. // return this.repository.insert(acc).returning('id')
  36. // .then((data) => {
  37. // if(data[0]) {
  38. // user[this.name+"_id"] = data[0];
  39. // return user;
  40. // } else {
  41. // throw new Error("Cannot create Account for inserted user");
  42. // }
  43. // })
  44. // });
  45. }
  46. }
  47. module.exports = CategoriesModule;