admin/controllers/return/index.js

  1. /* ============================================================================ *\
  2. || ########################################################################## ||
  3. || # Auction Software Marketplace Release: 0.6 Build 0.7 # ||
  4. || # ---------------------------------------------------------------------- # ||
  5. || # License # 35YAHCNR9344X6O666C123AB # ||
  6. || # ---------------------------------------------------------------------- # ||
  7. || # Copyright ©2014–2021 Develop Scripts LLC. All Rights Reserved # ||
  8. || # This file may not be redistributed in whole or significant part. # ||
  9. || # ------------- AUCTION SOFTWARE IS NOT FREE SOFTWARE ------------------ # ||
  10. || # http://www.auctionsoftwaremarketplace.com|support@auctionsoftware.com # ||
  11. || # ---------------------------------------------------------------------- # ||
  12. || ########################################################################## ||
  13. \* ============================================================================ */
  14. /* eslint-disable prefer-destructuring */
  15. /* eslint-disable no-param-reassign */
  16. const jwt = require('jsonwebtoken')
  17. const adminReturnModule = require('../../modules/return').default
  18. const schemaModule = require('./schema').default
  19. const commonFunction = require('../../../common/function').default
  20. const { jsonResponse } = require('../logger')
  21. const shortDescribeSCH = async (items) => {
  22. function changingdata(item) {
  23. item.avatarorg =
  24. item.file_name === '' || item.file_name === null
  25. ? `${global.s3_static_image_url}images/pics-coming.jpg`
  26. : `${global.s3_static_image_url}uploads/product/${item.file_name}`
  27. return item
  28. }
  29. const promises = items.map(changingdata)
  30. items = await Promise.all(promises)
  31. return items
  32. }
  33. module.exports = {
  34. /**
  35. * Get All Return Invoice
  36. *
  37. * @memberOf adminside.return
  38. * @param {adminReturnModule.fetchInvoicesAll} modules
  39. */
  40. invoices: async (req, res) => {
  41. req.body.action = typeof req.body.action === 'undefined' ? 'open' : req.body.action
  42. let records = []
  43. let totalRecords = []
  44. try {
  45. ;[records, totalRecords] = await Promise.all([
  46. adminReturnModule.fetchInvoicesAll(req, 0),
  47. adminReturnModule.fetchInvoicesAll(req, 1),
  48. ])
  49. totalRecords = [{ totallength: totalRecords.length }]
  50. records = await shortDescribeSCH(records)
  51. } catch (e) {
  52. console.error(e)
  53. jsonResponse(res, 'error', {
  54. responseType: 3,
  55. message: 'Internal Server error!',
  56. })
  57. } finally {
  58. let responseData = { records, totalRecords }
  59. responseData = await commonFunction.getdynamicinnercontents(req, responseData)
  60. jsonResponse(res, 'success', {
  61. responseType: 1,
  62. message: 'Details successfully retrieved!',
  63. responseData,
  64. })
  65. }
  66. },
  67. /**
  68. * Change the Status of the Projects
  69. *
  70. * @memberOf adminside.return
  71. * @param {adminReturnModule.invoiceStatusUpdate} modules
  72. * @param {adminReturnModule.invoiceBuynowStatusUpdate} modules
  73. */
  74. changeStatus: async (req, res) => {
  75. try {
  76. if (req.body.action && req.body.project_id.length > 0) {
  77. await Promise.all([
  78. adminReturnModule.invoiceStatusUpdate(req.body.action, req.body.project_id),
  79. adminReturnModule.invoiceBuynowStatusUpdate(
  80. req.body.action,
  81. req.body.project_id,
  82. ),
  83. ])
  84. }
  85. } catch (e) {
  86. console.error(e)
  87. jsonResponse(res, 'error', {
  88. responseType: 3,
  89. message: 'Internal Server error!',
  90. })
  91. } finally {
  92. const responseData = {}
  93. jsonResponse(res, 'success', {
  94. responseType: 1,
  95. message: 'Status successfully changed',
  96. responseData,
  97. })
  98. }
  99. },
  100. /**
  101. * Get a Single Refund Invoice
  102. *
  103. * @memberOf adminside.return
  104. * @param {adminReturnModule.marketStatusUpdate} modules
  105. */
  106. refundInvoice: async (req, res) => {
  107. try {
  108. if (req.body.action && req.body.project_id.length > 0) {
  109. await adminReturnModule.marketStatusUpdate(req.body.action, req.body.project_id)
  110. }
  111. } catch (e) {
  112. console.error(e)
  113. jsonResponse(res, 'error', {
  114. responseType: 3,
  115. message: 'Internal Server error!',
  116. })
  117. } finally {
  118. const responseData = {}
  119. jsonResponse(res, 'success', {
  120. responseType: 1,
  121. message: 'Status successfully changed',
  122. responseData,
  123. })
  124. }
  125. },
  126. }