index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const express = require('express');
  2. const path = require('path');
  3. const CrudModule = require('../../base/CrudModule');
  4. const OneToOne = require('../../base/OneToOne');
  5. const RepositorySystem = require('../../systems/RepositorySystem');
  6. const RoutingSystem = require('../../systems/RoutingSystem');
  7. const Actions = require('../../systems/ActionSystem');
  8. const MailSystem = require('../../systems/MailSystem')
  9. let AccountScheme = {
  10. fields: [
  11. {
  12. key: "name",
  13. type: "text"
  14. },
  15. {
  16. key: "surname",
  17. type: "text"
  18. },
  19. {
  20. key: "company",
  21. type: "text"
  22. },
  23. {
  24. key: "phone",
  25. type: "text"
  26. },
  27. {
  28. key: "mobile",
  29. type: "text"
  30. },
  31. {
  32. key: "afm",
  33. type: "text"
  34. }
  35. ]
  36. };
  37. class AccountModule extends CrudModule {
  38. constructor(){
  39. super('/accounts', [1,1,1,1,3], 'Account', '', );
  40. this.repository = RepositorySystem.create('Account', AccountScheme);
  41. this.setRepo(this.repository);
  42. this.userAccountConnection = new OneToOne('Account', 'Users');
  43. Actions.on('postUsers', (user) => {
  44. let acc = {
  45. };
  46. return this.repository.insert(acc).returning('id')
  47. .then((data) => {
  48. if(data[0]) {
  49. user[this.name+"_id"] = data[0];
  50. return user;
  51. } else {
  52. throw new Error("Cannot create Account for inserted user");
  53. }
  54. })
  55. });
  56. }
  57. }
  58. module.exports = AccountModule;