admin/controllers/transaction/index.js

/* ============================================================================ *\
|| ########################################################################## ||
|| # 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 adminTransactionModule = require('../../modules/transaction').default
const schemaModule = require('./schema').default
const commonFunction = require('../../../common/function').default

const { jsonResponse } = require('../logger')

module.exports = {
    /**
     * Get all payment logs
     *
     * @memberOf adminside.transaction
     * @param {adminTransactionModule.fetchPaymentLogsAll} modules
     */
    paymentLogs: 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([
                adminTransactionModule.fetchPaymentLogsAll(req, 0),
                adminTransactionModule.fetchPaymentLogsAll(req, 1),
            ])
            totalRecords = [{ totallength: totalRecords.length }]
        } 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,
            })
        }
    },
    /**
     * Get all refund logs
     *
     * @memberOf adminside.transaction
     * @param {adminTransactionModule.fetchRefundLogsAll} modules
     */
    refundLogs: 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([
                adminTransactionModule.fetchRefundLogsAll(req, 0),
                adminTransactionModule.fetchRefundLogsAll(req, 1),
            ])
            totalRecords = [{ totallength: totalRecords.length }]
        } 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,
            })
        }
    },
}