/* ============================================================================ *\
|| ########################################################################## ||
|| # 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 adminCommuncationModule = require('../../modules/communcation').default
const schemaModule = require('./schema').default
const commonFunction = require('../../../common/function').default
const { jsonResponse } = require('../logger')
module.exports = {
/**
* Get Email and SMS Templates
*
* @memberOf adminside.communication
* @param {adminCommuncationModule.alltemps} modules
* @param {adminCommuncationModule.alllogsemails} modules
*/
templates: async (req, res) => {
req.body.action = typeof req.body.action === 'undefined' ? 'email' : req.body.action
let records = []
let totalRecords = []
try {
if (req.body.action === 'email' || req.body.action === 'sms') {
;[records, totalRecords] = await Promise.all([
adminCommuncationModule.alltemps(req, 0),
adminCommuncationModule.alltemps(req, 1),
])
} else if (req.body.action === 'emaillogs') {
;[records, totalRecords] = await Promise.all([
adminCommuncationModule.alllogsemails(req, 0),
adminCommuncationModule.alllogsemails(req, 1),
])
}
} 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 Single Template
*
* @memberOf adminside.communication
* @param {adminCommuncationModule.etempsbyId} modules
*/
getSingleTemplate: async (req, res) => {
console.log('coming here')
let item = {}
try {
const id = typeof req.body.id === 'undefined' ? '' : req.body.id
const [records] = await Promise.all([adminCommuncationModule.etempsbyId(id)])
console.log('records', records)
item = records[0]
console.log('item', item)
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
const responseData = { item }
jsonResponse(res, 'success', {
responseType: 1,
message: 'Details successfully retrieved!',
responseData,
})
}
},
/**
* Template Action
*
* @memberOf adminside.communication
* @param {adminCommuncationModule.templateOperation} modules
*/
templateAction: async (req, res) => {
try {
req.body.id =
typeof req.body.id === 'undefined' || req.body.id === 0 || req.body.id === ''
? null
: req.body.id
await Promise.all([adminCommuncationModule.templateOperation(req)])
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
jsonResponse(res, 'success', {
responseType: 1,
message: req.body.id ? 'Successfully updated!' : 'Successfully added!',
})
}
},
/**
* Get Static Pages
*
* @memberOf adminside.communication
* @param {adminCommuncationModule.allStaticPage} modules
*/
staticPages: async (req, res) => {
let records = []
let totalRecords = []
try {
;[records, totalRecords] = await Promise.all([
adminCommuncationModule.allStaticPage(req, 0),
adminCommuncationModule.allStaticPage(req, 1),
])
} 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 Single Static Page
*
* @memberOf adminside.communication
* @param {adminCommuncationModule.getStaticPagebyId} modules
*/
getSingleStaticPages: async (req, res) => {
let item = {}
try {
const id = typeof req.body.id === 'undefined' ? '' : req.body.id
const [records] = await Promise.all([adminCommuncationModule.getStaticPagebyId(id)])
item = records[0]
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
const responseData = { item }
jsonResponse(res, 'success', {
responseType: 1,
message: 'Details successfully retrieved!',
responseData,
})
}
},
/**
* Static Page action
*
* @memberOf adminside.communication
* @param {adminCommuncationModule.staticPageOperation} modules
*/
staticPagesAction: async (req, res) => {
try {
req.body.id =
typeof req.body.id === 'undefined' || req.body.id === 0 || req.body.id === ''
? null
: req.body.id
await Promise.all([adminCommuncationModule.staticPageOperation(req)])
} catch (e) {
console.error(e)
jsonResponse(res, 'error', {
responseType: 3,
message: 'Internal Server error!',
})
} finally {
jsonResponse(res, 'success', {
responseType: 1,
message: req.body.id ? 'Successfully updated!' : 'Successfully added!',
})
}
},
}