account.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const moduleManager = require("../../../index");
  2. const accountModule = moduleManager.modules["account"];
  3. const mongoModule = moduleManager.modules["mongo"];
  4. const utilModule = moduleManager.modules["util"];
  5. module.exports = {
  6. "createEmptyAccount": async (cb, version) => {
  7. accountModule.createEmptyAccount(version).then(account => {
  8. cb({
  9. status: "success",
  10. account
  11. });
  12. }).catch(err => {
  13. cb({
  14. status: "failure"
  15. });
  16. });
  17. },
  18. "getAll": async cb => {
  19. accountModule.getAll().then(accounts => {
  20. cb({
  21. status: "success",
  22. accounts
  23. });
  24. }).catch(err => {
  25. cb({
  26. status: "failure"
  27. });
  28. });
  29. },
  30. "getById": (cb, accountId) => {
  31. accountModule.getById(accountId).then(account => {
  32. cb({
  33. status: "success",
  34. account
  35. });
  36. }).catch(err => {
  37. cb({
  38. status: "failure"
  39. });
  40. });
  41. },
  42. "getMigratedAccount": (cb, accountId) => {
  43. accountModule.getMigratedAccount(accountId).then(account => {
  44. cb({
  45. status: "success",
  46. account
  47. });
  48. }).catch(err => {
  49. cb({
  50. status: "failure",
  51. message: err.message
  52. });
  53. });
  54. },
  55. "migrateAccounts": (cb, accountIds) => {
  56. accountModule.migrateAccounts(accountIds).then(res => {
  57. cb({
  58. status: "success",
  59. failed: res.failed,
  60. successful: res.successful
  61. });
  62. }).catch(err => {
  63. cb({
  64. status: "failure",
  65. message: err.message
  66. });
  67. });
  68. },
  69. "add": (cb, account) => {
  70. accountModule.add(account).then(() => {
  71. console.log("Added account!");
  72. cb({
  73. status: "success"
  74. });
  75. }).catch(err => {
  76. cb({
  77. status: "failure"
  78. });
  79. });
  80. },
  81. "editById": (cb, accountId, account) => {
  82. accountModule.editById(accountId, account).then(() => {
  83. console.log("Edited account!");
  84. cb({
  85. status: "success"
  86. });
  87. }).catch(err => {
  88. cb({
  89. status: "failure"
  90. });
  91. });
  92. }
  93. }