convertSchema.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. const moduleManager = require("../../../index");
  2. const mongoModule = moduleManager.modules["mongo"];
  3. const convertSchemaModule = moduleManager.modules["convertSchema"];
  4. module.exports = {
  5. "getForVersion": (cb, version) => {
  6. convertSchemaModule.getForVersion(version).then(schema => {
  7. cb({
  8. status: "success",
  9. schema
  10. });
  11. }).catch(err => {
  12. cb({
  13. status: "failure"
  14. });
  15. });
  16. },
  17. "getById": (cb, schemaId) => {
  18. convertSchemaModule.getById(schemaId).then(schema => {
  19. cb({
  20. status: "success",
  21. schema
  22. });
  23. }).catch(err => {
  24. cb({
  25. status: "failure"
  26. });
  27. });
  28. },
  29. "removeById": (cb, schemaId) => {
  30. convertSchemaModule.removeById(schemaId).then(() => {
  31. cb({
  32. status: "success"
  33. });
  34. }).catch(err => {
  35. cb({
  36. status: "failure"
  37. });
  38. });
  39. },
  40. "getAll": (cb) => {
  41. convertSchemaModule.getAll().then(schemas => {
  42. cb({
  43. status: "success",
  44. schemas
  45. });
  46. }).catch(err => {
  47. cb({
  48. status: "failure"
  49. });
  50. });
  51. },
  52. "listSchemasInDirectory": (cb) => {
  53. convertSchemaModule.listSchemasInDirectory().then((schemasInDirectory) => {
  54. cb({
  55. status: "success",
  56. schemasInDirectory
  57. });
  58. }).catch(err => {
  59. cb({
  60. status: "failure",
  61. error: err.message
  62. });
  63. });
  64. },
  65. "import": (cb, name) => {
  66. convertSchemaModule.import(name).then(() => {
  67. cb({
  68. status: "success"
  69. });
  70. }).catch(err => {
  71. cb({
  72. status: "failure",
  73. error: err.message
  74. });
  75. });
  76. }
  77. }