/* ============================================================================ *\
|| ########################################################################## ||
|| # Auction Software Marketplace Release: 0.6 Build 0.7 # ||
|| # ---------------------------------------------------------------------- # ||
|| # License # 35YAHCNR9344X6O666C123AB # ||
|| # ---------------------------------------------------------------------- # ||
|| # Copyright ©2014–2021 Develop Scripts LLC. All Rights Reserved # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ------------- AUCTION SOFTWARE IS NOT FREE SOFTWARE ------------------ # ||
|| # http://www.auctionsoftwaremarketplace.com|support@auctionsoftware.com # ||
|| # ---------------------------------------------------------------------- # ||
|| ########################################################################## ||
\* ============================================================================ */
/* eslint-disable prefer-destructuring */
/* eslint-disable no-param-reassign */
const jwt = require('jsonwebtoken')
const adminReturnModule = require('../../modules/return').default
const schemaModule = require('./schema').default
const commonFunction = require('../../../common/function').default
const { jsonResponse } = require('../logger')
const shortDescribeSCH = async (items) => {
function changingdata(item) {
item.avatarorg =
item.file_name === '' || item.file_name === null
? `${global.s3_static_image_url}images/pics-coming.jpg`
: `${global.s3_static_image_url}uploads/product/${item.file_name}`
return item
}
const promises = items.map(changingdata)
items = await Promise.all(promises)
return items
}
module.exports = {
/**
* Get All Return Invoice
*
* @memberOf adminside.return
* @param {adminReturnModule.fetchInvoicesAll} modules
*/
invoices: async (req, res) => {
req.body.action = typeof req.body.action === 'undefined' ? 'open' : req.body.action
let records = []
let totalRecords = []
try {
;[records, totalRecords] = await Promise.all([
adminReturnModule.fetchInvoicesAll(req, 0),
adminReturnModule.fetchInvoicesAll(req, 1),
])
totalRecords = [{ totallength: totalRecords.length }]
records = await shortDescribeSCH(records)
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
let responseData = { records, totalRecords }
responseData = await commonFunction.getdynamicinnercontents(req, responseData)
jsonResponse(res, 'success', {
responseType: 1,
message: 'Details successfully retrieved!',
responseData,
})
}
},
/**
* Change the Status of the Projects
*
* @memberOf adminside.return
* @param {adminReturnModule.invoiceStatusUpdate} modules
* @param {adminReturnModule.invoiceBuynowStatusUpdate} modules
*/
changeStatus: async (req, res) => {
try {
if (req.body.action && req.body.project_id.length > 0) {
await Promise.all([
adminReturnModule.invoiceStatusUpdate(req.body.action, req.body.project_id),
adminReturnModule.invoiceBuynowStatusUpdate(
req.body.action,
req.body.project_id,
),
])
}
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
const responseData = {}
jsonResponse(res, 'success', {
responseType: 1,
message: 'Status successfully changed',
responseData,
})
}
},
/**
* Get a Single Refund Invoice
*
* @memberOf adminside.return
* @param {adminReturnModule.marketStatusUpdate} modules
*/
refundInvoice: async (req, res) => {
try {
if (req.body.action && req.body.project_id.length > 0) {
await adminReturnModule.marketStatusUpdate(req.body.action, req.body.project_id)
}
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
const responseData = {}
jsonResponse(res, 'success', {
responseType: 1,
message: 'Status successfully changed',
responseData,
})
}
},
}