accountSchema.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const moduleManager = require("../../../index");
  2. const mongoModule = moduleManager.modules["mongo"];
  3. const accountSchemaModule = moduleManager.modules["accountSchema"];
  4. module.exports = {
  5. "getLatest": cb => {
  6. accountSchemaModule.getLatest().then(schema => {
  7. cb({
  8. status: "success",
  9. schema
  10. });
  11. }).catch(err => {
  12. cb({
  13. status: "failure"
  14. });
  15. });
  16. },
  17. "getByVersion": (cb, version) => {
  18. accountSchemaModule.getByVersion(version).then(schema => {
  19. cb({
  20. status: "success",
  21. schema
  22. });
  23. }).catch(err => {
  24. cb({
  25. status: "failure"
  26. });
  27. });
  28. },
  29. "getAllVersions": (cb) => {
  30. accountSchemaModule.getAllVersions().then(versions => {
  31. cb({
  32. status: "success",
  33. versions
  34. });
  35. }).catch(err => {
  36. cb({
  37. status: "failure"
  38. });
  39. });
  40. },
  41. "getAll": cb => {
  42. accountSchemaModule.getAll().then(schemas => {
  43. cb({
  44. status: "success",
  45. schemas
  46. });
  47. }).catch(err => {
  48. cb({
  49. status: "failure"
  50. });
  51. });
  52. },
  53. "getById": (cb, schemaId) => {
  54. accountSchemaModule.getById(schemaId).then(schema => {
  55. cb({
  56. status: "success",
  57. schema
  58. });
  59. }).catch(err => {
  60. cb({
  61. status: "failure"
  62. });
  63. });
  64. },
  65. "removeById": (cb, schemaId) => {
  66. accountSchemaModule.removeById(schemaId).then(() => {
  67. cb({
  68. status: "success"
  69. });
  70. }).catch(err => {
  71. cb({
  72. status: "failure"
  73. });
  74. });
  75. },
  76. "listSchemasInDirectory": (cb) => {
  77. accountSchemaModule.listSchemasInDirectory().then((schemasInDirectory) => {
  78. cb({
  79. status: "success",
  80. schemasInDirectory
  81. });
  82. }).catch(err => {
  83. cb({
  84. status: "failure",
  85. error: err.message
  86. });
  87. });
  88. },
  89. "import": (cb, name) => {
  90. accountSchemaModule.import(name).then(() => {
  91. cb({
  92. status: "success"
  93. });
  94. }).catch(err => {
  95. cb({
  96. status: "failure",
  97. error: err.message
  98. });
  99. });
  100. }
  101. }