/* ============================================================================ *\
|| ########################################################################## ||
|| # 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 # ||
|| # ---------------------------------------------------------------------- # ||
|| ########################################################################## ||
\* ============================================================================ */
const dateFormat = require('dateformat')
const md5 = require('md5')
const _ = require('underscore')
const commonSQL = require('../../common/sql').default
const mysqclass = require('./mysqli').default
/**
* @class class to handle settings functions
*/
class adminSettingModule {
/**
* All Configurations
* @param {object} req request data
* @param {string} count count for the pagination
* @returns {object} sql response
*/
static async allConfiguration(req, count) {
const mysql = {}
req.body.action = typeof req.body.action === 'undefined' ? 'email' : req.body.action
mysql.where = ''
const { action } = req.body
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
mysql.order = 'order by id desc'
const order = req.body.order === '' ? 'asc' : req.body.order
const orderby = req.body.orderby === '' && !req.body.orderby ? '' : req.body.orderby
if (orderby !== '') {
mysql.order = ` order by ${orderby} ${order}`
}
if (req.body.searchterm !== '' && req.body.searchterm !== undefined) {
let changed = req.body.searchterm.replace(/\\/g, '\\\\\\\\')
changed = changed.replace(/"/g, '\\"')
mysql.where += `and (name like "%${changed}%" or id like "%${changed}%")`
}
let row = ''
const pagen = (req.body.page - 1) * req.body.limit
const limitf = ` limit ${pagen},${req.body.limit}`
mysql.limit = limitf
mysql.dateNow = dateNow
const escapeData = [action]
if (count === 1) {
row = 'get_all_setting_configuration_limit'
} else {
row = 'get_all_setting_configuration'
}
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* All Single Configuration
* @param {number} id ID which the configuration has to be fetched
* @returns {object} sql response
*/
static async getConfigurationbyId(id) {
const mysql = {}
const escapeData = [id]
const strQuery = await mysqclass.mysqli(mysql, 'get_single_setting_configuration')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* All Single Configuration
* @param {object} req req object
* @returns {object} sql response
*/
static async configurationOperation(req) {
const mysql = {}
const postData = req.body
const acceptedObjects = ['value', 'variable', 'question', 'enabled', 'type']
let escapeData = []
let row = ''
if (req.body.id) {
const defaultKeys = []
const defaultValues = []
const valueInsert = commonSQL.updateSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysql.keys = valueInsert.keys
escapeData = valueInsert.escapeData
row = 'update_on_setting_configuration'
mysql.static_page_id = req.body.id
} else {
const defaultKeys = []
const defaultValues = []
const valueInsert = commonSQL.InsertSQLFunction(
postData,
acceptedObjects,
defaultKeys,
defaultValues,
)
mysql.keys = valueInsert.keys
mysql.values = valueInsert.values
escapeData = valueInsert.escapeData
row = 'insert_into_setting_configuration'
}
const strQuery = await mysqclass.mysqli(mysql, row)
const data = await global.mysql.query(strQuery, escapeData)
return data
}
}
module.exports.default = adminSettingModule